Improve phpdoc types

This commit is contained in:
Grégoire Paris
2025-10-18 10:23:36 +02:00
parent d94ac8e925
commit 0c4d609fe8
4 changed files with 75 additions and 17 deletions

View File

@@ -76,7 +76,7 @@ final readonly class Projects implements DataSource
}
/**
* @param mixed[] $projectData
* @param array{versions: list<array{name:string, branchName?: string|null}>} $projectData
*
* @return mixed[]
*/
@@ -96,7 +96,7 @@ final readonly class Projects implements DataSource
return $projectVersions;
}
/** @return mixed[] */
/** @return list<array{name: string, slug: string, branchName: string|null, tags: non-empty-list<Tag>}> */
private function readProjectVersionsFromGit(string $repositoryName): array
{
$repositoryPath = $this->projectsDir . '/' . $repositoryName;
@@ -104,16 +104,27 @@ final readonly class Projects implements DataSource
$projectVersions = $this->projectVersionsReader->readProjectVersions($repositoryPath);
// fix this, we shouldn't have null branch names at this point. Fix it further upstream
/** @phpstan-ignore return.type */
return array_filter($projectVersions, static function (array $projectVersion): bool {
return count($projectVersion['tags']) > 0;
});
}
/**
* @param mixed[] $projectVersions
* @param mixed[] $projectData
* @param list<array{name: string, slug: string, branchName: string|null, tags: list<Tag>}> $projectVersions
* @param array{versions: list<array{name:string, branchName?: string|null}>} $projectData
*
* @return mixed[]
* @return list<array{
* name: string,
* branchName?: string|null
* }|array{
* name: string,
* slug: string,
* branchName: string|null,
* tags: non-empty-list<Tag>,
* maintained?: false
* }>
*/
private function applyConfiguredProjectVersions(
array $projectVersions,
@@ -153,8 +164,8 @@ final readonly class Projects implements DataSource
}
/**
* @param mixed[] $a
* @param mixed[] $b
* @param array{name: string, slug: string, branchName: string|null, tags: list<Tag>} $a
* @param array{name: string, branchName?: string|null} $b
*/
private function containsSameProjectVersion(array $a, array $b): bool
{
@@ -170,8 +181,8 @@ final readonly class Projects implements DataSource
}
/**
* @param mixed[] $projectVersions
* @param mixed[] $projectData
* @param list<array{name: string, branchName?: string|null}|array{name: string, slug: string, branchName: string|null, tags: non-empty-list<Tag>, maintained?: false}> $projectVersions
* @param mixed[] $projectData
*
* @return mixed[]
*/

View File

@@ -31,8 +31,8 @@ class ProjectDataReader
private readonly Inflector $inflector;
/**
* @param mixed[] $projectsData
* @param mixed[] $projectIntegrationTypes
* @param list<array{repositoryName: string, versionsGreaterThan?: string, sortOrder?: int, integration?: bool, integrationFor?: string, integrationType?: string}> $projectsData
* @param mixed[] $projectIntegrationTypes
*/
public function __construct(
private readonly string $projectsDir,
@@ -42,7 +42,30 @@ class ProjectDataReader
$this->inflector = InflectorFactory::create()->build();
}
/** @return mixed[] */
/**
* @return array{
* name: string,
* repositoryName: string,
* docsPath: string|null,
* slug: string,
* versions: list<array{
* name: string,
* branchName: string,
* slug: string,
* aliases: list<string>
* }>,
* composerPackageName: string,
* description?: string,
* keywords?: list<string>,
* shortName?: string,
* docsSlug: string,
* versionsGreaterThan?: string,
* sortOrder?: int,
* integration?: bool,
* integrationFor?: string,
* integrationType?: array{name: string, url: string, icon: string}
* }
*/
public function read(string $repositoryName): array
{
$projectData = array_replace(
@@ -75,10 +98,27 @@ class ProjectDataReader
$projectData['docsSlug'] = $projectData['slug'];
}
/** @phpstan-ignore return.type (PHPStan loses type information with the call to array_replace) */
return $projectData;
}
/** @return mixed[] */
/**
* @return array{
* name: string,
* repositoryName: string,
* docsPath: string|null,
* slug: string,
* versions: array{array{
* name: 'master',
* branchName: 'master',
* slug: 'latest',
* aliases: array{'current', 'stable'}
* }},
* composerPackageName?: string,
* description?: string,
* keywords?: list<string>
* }
*/
private function createDefaultProjectData(string $repositoryName): array
{
$slug = str_replace('_', '-', $this->inflector->tableize($repositoryName));
@@ -133,7 +173,7 @@ class ProjectDataReader
return $default;
}
/** @return mixed[] */
/** @return array{composerPackageName?: string, description?: string, keywords?:list<string>} */
private function readComposerData(string $repositoryName): array
{
$data = $this->readJsonFile($repositoryName, self::COMPOSER_JSON_FILE_NAME);

View File

@@ -20,7 +20,7 @@ class ProjectVersionsReader
) {
}
/** @return mixed[] */
/** @return list<array{name: string, slug: string, branchName: string|null, tags: list<Tag>}> */
public function readProjectVersions(string $repositoryPath): array
{
$tags = $this->getProjectTags($repositoryPath);
@@ -60,7 +60,7 @@ class ProjectVersionsReader
return array_values($versions);
}
/** @return mixed[] */
/** @return Tag[] */
private function getProjectTags(string $repositoryPath): array
{
$tags = $this->tagReader->getRepositoryTags($repositoryPath);

View File

@@ -10,7 +10,13 @@ use InvalidArgumentException;
class ProjectDataReaderTest extends TestCase
{
/** @var string[][] */
/**
* @var array<string, array{
* name: string,
* url: string,
* icon: string
* }>
*/
private array $projectIntegrationTypes;
private ProjectDataReader $projectDataReader;
@@ -74,6 +80,7 @@ class ProjectDataReaderTest extends TestCase
{
$projectData = $this->projectDataReader->read('test-integration-project');
self::assertArrayHasKey('integrationType', $projectData);
self::assertSame($this->projectIntegrationTypes['symfony'], $projectData['integrationType']);
}