Skip to content

Commit

Permalink
array to list types
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangut committed Mar 5, 2024
1 parent 044c5d5 commit cac3cc7
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 27 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"ext-simplexml": "*",
"doctrine/annotations": "^2.0",
"infection/infection": "~0.25|~0.27",
"juliangut/easy-coding-standard-config": "^1.14",
"juliangut/phpstan-config": "^1.1",
"juliangut/easy-coding-standard-config": "^1.15",
"juliangut/phpstan-config": "^1.2",
"overtrue/phplint": "^9.0",
"phpcompatibility/php-compatibility": "^9.3",
"phpmd/phpmd": "^2.14",
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/AbstractAnnotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct($parameters)
*
* @throws AnnotationException
*
* @return array<string>
* @return list<string>
*/
private function getAnnotationProperties(array $parameters, ?string $defaultProperty): array
{
Expand Down
6 changes: 3 additions & 3 deletions src/Driver/AbstractClassDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ protected function loadClassFromFile(string $mappingFile): ?string
/**
* Traverse token stack in search of next token.
*
* @param array<mixed|array{0: int, 1: string, 2: int}> $tokens
* @param array<int> $types
* @param list<mixed|array{0: int, 1: string, 2: int}> $tokens
* @param list<int> $types
*/
private function findNextToken(array $tokens, array $types, int $start = 0, ?int $escapePreviousType = null): ?int
{
Expand Down Expand Up @@ -122,7 +122,7 @@ private function findNextToken(array $tokens, array $types, int $start = 0, ?int
}

/**
* @return array<int>
* @return list<int>
*/
private function getValidTokenTypes(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/AbstractDriverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getDriver(array $mappingSource): DriverInterface
}

if (\array_key_exists('type', $mappingSource) && \array_key_exists('path', $mappingSource)) {
return $this->getDriverImplementation($mappingSource['type'], array_values((array) $mappingSource['path']));
return $this->getDriverImplementation($mappingSource['type'], (array) $mappingSource['path']);
}

throw new DriverException(
Expand Down
15 changes: 9 additions & 6 deletions src/Driver/AbstractMappingDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract class AbstractMappingDriver extends AbstractDriver
/**
* @throws DriverException
*
* @return array<mixed>
* @return array<int|string, mixed>
*/
protected function getMappingData(): array
{
Expand All @@ -39,15 +39,15 @@ protected function getMappingData(): array
/**
* @throws DriverException
*
* @return array<mixed>
* @return array<int|string, mixed>
*/
abstract protected function loadMappingFile(string $mappingFile): array;

/**
* @param array<mixed> $mappingsA
* @param array<mixed> $mappingsB
* @param array<int|string, mixed|array<int|string, mixed>> $mappingsA
* @param array<int|string, mixed|array<int|string, mixed>> $mappingsB
*
* @return array<mixed>
* @return array<int|string, mixed>
*/
final protected function mergeMappings(array $mappingsA, array $mappingsB): array
{
Expand All @@ -56,7 +56,10 @@ final protected function mergeMappings(array $mappingsA, array $mappingsB): arra
if (\is_int($key)) {
$mappingsA[] = $value;
} elseif (\is_array($value) && \is_array($mappingsA[$key])) {
$mappingsA[$key] = $this->mergeMappings($mappingsA[$key], $value);
/** @var array<int|string, mixed> $valueA */
$valueA = $mappingsA[$key];
/** @var array<int|string, mixed> $value */
$mappingsA[$key] = $this->mergeMappings($valueA, $value);
} else {
$mappingsA[$key] = $value;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Driver/Locator/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(
) {}

/**
* @return array<string>
* @return list<string>
*/
public function getPaths(): array
{
Expand All @@ -41,7 +41,7 @@ public function getPaths(): array
/**
* Get supported file extensions.
*
* @return array<string>
* @return list<string>
*/
public function getExtensions(): array
{
Expand All @@ -51,7 +51,7 @@ public function getExtensions(): array
/**
* @throws DriverException
*
* @return array<string>
* @return list<string>
*/
public function getMappingFiles(): array
{
Expand All @@ -71,7 +71,7 @@ public function getMappingFiles(): array
}

/**
* @return array<string>
* @return list<string>
*/
protected function getFilesFromDirectory(string $mappingDirectory): array
{
Expand All @@ -81,7 +81,7 @@ protected function getFilesFromDirectory(string $mappingDirectory): array
$recursiveIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($mappingDirectory));
$regexIterator = new RegexIterator($recursiveIterator, $filePattern, RecursiveRegexIterator::GET_MATCH);

/** @var array<string> $mappingFile */
/** @var list<string> $mappingFile */
foreach ($regexIterator as $mappingFile) {
$mappingPaths[] = $mappingFile[0];
}
Expand Down
1 change: 1 addition & 0 deletions src/Driver/Traits/JsonMappingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ protected function loadMappingFile(string $mappingFile): array
throw new DriverException(sprintf('Malformed XML mapping file "%s".', $mappingFile), 0);
}

/** @var array<int|string, mixed> $mappings */
return $mappings;
}
}
1 change: 1 addition & 0 deletions src/Driver/Traits/PhpMappingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected function loadMappingFile(string $mappingFile): array
throw new DriverException(sprintf('Malformed XML mapping file "%s".', $mappingFile), 0);
}

/** @var array<int|string, mixed> $mappings */
return $mappings;
}
}
1 change: 1 addition & 0 deletions src/Driver/Traits/XmlMappingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ protected function loadMappingFile(string $mappingFile): array
throw new DriverException(sprintf('Malformed XML mapping file "%s".', $mappingFile), 0);
}

/** @var array<int|string, mixed> $mappings */
return $mappings;
}

Expand Down
1 change: 1 addition & 0 deletions src/Driver/Traits/YamlMappingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected function loadMappingFile(string $mappingFile): array
throw new DriverException(sprintf('Malformed YAML mapping file "%s".', $mappingFile), 0);
}

/** @var array<int|string, mixed> $mappings */
return $mappings;
}
}
4 changes: 2 additions & 2 deletions src/Metadata/MetadataResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static function (string $key, array $mappingSource): string {
*/
protected function normalizeMappingSources(array $mappingSources): array
{
return array_values(array_map(
return array_map(
static function ($mappingSource): array {
if (\is_array($mappingSource) && \array_key_exists('driver', $mappingSource)) {
return ['driver' => $mappingSource['driver']];
Expand All @@ -120,6 +120,6 @@ static function ($mappingSource): array {
return $mappingSource;
},
$mappingSources,
));
);
}
}
4 changes: 2 additions & 2 deletions tests/Mapping/Stubs/AbstractAnnotationDriverStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class AbstractAnnotationDriverStub extends AbstractAnnotationDriver
{
/**
* @return array<ReflectionClass<object>>
* @return list<ReflectionClass<object>>
*/
public function extractMappingClasses(): array
{
Expand All @@ -33,7 +33,7 @@ public function getMetadata(): array
}

/**
* @return array<mixed>
* @return list<mixed>
*/
public function getAnnotations(): array
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Mapping/Stubs/AbstractAttributeDriverStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class AbstractAttributeDriverStub extends AbstractClassDriver
{
/**
* @return array<ReflectionClass<object>>
* @return list<ReflectionClass<object>>
*/
public function extractMappingClasses(): array
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Mapping/Stubs/AbstractClassDriverStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AbstractClassDriverStub extends AbstractClassDriver
/**
* Get mapped metadata.
*
* @return array<MetadataInterface>
* @return list<MetadataInterface>
*/
public function getMetadata(): array
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Mapping/Stubs/AbstractMappingDriverStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AbstractMappingDriverStub extends AbstractMappingDriver
use PhpMappingTrait;

/**
* @return array<ReflectionClass<object>>
* @return list<ReflectionClass<object>>
*/
public function extractMappingData(): array
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Mapping/Stubs/JsonMappingDriverStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class JsonMappingDriverStub implements DriverInterface
/**
* Get supported mapping file extensions.
*
* @return array<string>
* @return list<string>
*/
public function getExtensions(): array
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Mapping/Stubs/YamlMappingDriverStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class YamlMappingDriverStub implements DriverInterface
/**
* Get supported mapping file extensions.
*
* @return array<string>
* @return list<string>
*/
public function getExtensions(): array
{
Expand Down

0 comments on commit cac3cc7

Please sign in to comment.