Skip to content

Commit

Permalink
chore(cs): fix composer.lock for phpstan and php cs fixer, also fixes…
Browse files Browse the repository at this point in the history
… cs regarding last version of php-cs-fixer (#45)
  • Loading branch information
joelwurtz authored Mar 8, 2024
1 parent cae8b2b commit f0bb0fe
Show file tree
Hide file tree
Showing 18 changed files with 1,940 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
vendor/
composer.lock
/composer.lock
.php-cs-fixer.cache
.phpunit.result.cache
tests/cache/
Expand Down
2 changes: 1 addition & 1 deletion src/AutoMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function hasMapper(string $source, string $target): bool
return null !== $this->getMetadata($source, $target);
}

public function map(array|object $source, string|array|object $target, array $context = []): null|array|object
public function map(array|object $source, string|array|object $target, array $context = []): array|object|null
{
$sourceType = $targetType = null;

Expand Down
2 changes: 1 addition & 1 deletion src/AutoMapperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ interface AutoMapperInterface
*
* @return array|object|null The mapped object
*/
public function map(array|object $source, string|array|object $target, array $context = []): null|array|object;
public function map(array|object $source, string|array|object $target, array $context = []): array|object|null;
}
2 changes: 1 addition & 1 deletion src/Extractor/CustomTransformerExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(
/**
* @param class-string<CustomTransformerInterface> $customTransformerClass
*/
public function extract(string $customTransformerClass, Expr|null $propertyToTransform, Expr $sourceObject): Expr
public function extract(string $customTransformerClass, ?Expr $propertyToTransform, Expr $sourceObject): Expr
{
if (!$propertyToTransform && is_a($customTransformerClass, CustomModelTransformerInterface::class, allow_string: true)) {
throw new \LogicException('CustomModelTransformerInterface must use $propertyToTransform.');
Expand Down
4 changes: 2 additions & 2 deletions src/Extractor/SourceTargetMappingExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function getPropertiesMapping(MapperGeneratorMetadataInterface $mapperMet
return $mapping;
}

private function toPropertyMapping(MapperGeneratorMetadataInterface $mapperMetadata, string $property, bool $onlyCustomTransformer = false): PropertyMapping|null
private function toPropertyMapping(MapperGeneratorMetadataInterface $mapperMetadata, string $property, bool $onlyCustomTransformer = false): ?PropertyMapping
{
$targetMutatorConstruct = $this->getWriteMutator($mapperMetadata->getSource(), $mapperMetadata->getTarget(), $property, [
'enable_constructor_extraction' => true,
Expand Down Expand Up @@ -106,7 +106,7 @@ private function toPropertyMapping(MapperGeneratorMetadataInterface $mapperMetad
);
}

private function guessMaxDepth(MapperMetadataInterface $mapperMetadata, string $property): int|null
private function guessMaxDepth(MapperMetadataInterface $mapperMetadata, string $property): ?int
{
$maxDepthSource = $this->getMaxDepth($mapperMetadata->getSource(), $property);
$maxDepthTarget = $this->getMaxDepth($mapperMetadata->getTarget(), $property);
Expand Down
14 changes: 7 additions & 7 deletions src/Generator/CreateTargetStatementsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(
private DiscriminatorStatementsGenerator $discriminatorStatementsGenerator,
private CachedReflectionStatementsGenerator $cachedReflectionStatementsGenerator,
private CustomTransformerExtractor $customTransformerExtractor,
Parser|null $parser = null,
?Parser $parser = null,
) {
$this->parser = $parser ?? (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
}
Expand Down Expand Up @@ -62,7 +62,7 @@ public function generate(MapperGeneratorMetadataInterface $mapperMetadata, Varia
]);
}

private function targetAsArray(MapperGeneratorMetadataInterface $mapperMetadata): Stmt|null
private function targetAsArray(MapperGeneratorMetadataInterface $mapperMetadata): ?Stmt
{
if ($mapperMetadata->getTarget() !== 'array') {
return null;
Expand All @@ -73,7 +73,7 @@ private function targetAsArray(MapperGeneratorMetadataInterface $mapperMetadata)
return new Stmt\Expression(new Expr\Assign($variableRegistry->getResult(), new Expr\Array_()));
}

private function sourceAndTargetAsStdClass(MapperGeneratorMetadataInterface $mapperMetadata): Stmt|null
private function sourceAndTargetAsStdClass(MapperGeneratorMetadataInterface $mapperMetadata): ?Stmt
{
if (\stdClass::class !== $mapperMetadata->getSource() || \stdClass::class !== $mapperMetadata->getTarget()) {
return null;
Expand All @@ -92,7 +92,7 @@ private function sourceAndTargetAsStdClass(MapperGeneratorMetadataInterface $map
);
}

private function targetAsStdClass(MapperGeneratorMetadataInterface $mapperMetadata): Stmt|null
private function targetAsStdClass(MapperGeneratorMetadataInterface $mapperMetadata): ?Stmt
{
if (\stdClass::class === $mapperMetadata->getSource() || \stdClass::class !== $mapperMetadata->getTarget()) {
return null;
Expand Down Expand Up @@ -196,7 +196,7 @@ private function constructorArguments(MapperGeneratorMetadataInterface $mapperMe
*
* @return array{Stmt, Arg, int}|null
*/
private function constructorArgument(PropertyMapping $propertyMapping): array|null
private function constructorArgument(PropertyMapping $propertyMapping): ?array
{
if (null === $propertyMapping->writeMutatorConstructor || null === ($parameter = $propertyMapping->writeMutatorConstructor->parameter)) {
return null;
Expand Down Expand Up @@ -264,7 +264,7 @@ private function constructorArgument(PropertyMapping $propertyMapping): array|nu
*
* @return array{Stmt, Arg, int}|null
*/
private function constructorArgumentWithDefaultValue(MapperGeneratorMetadataInterface $mapperMetadata, array $constructArguments, \ReflectionParameter $constructorParameter): array|null
private function constructorArgumentWithDefaultValue(MapperGeneratorMetadataInterface $mapperMetadata, array $constructArguments, \ReflectionParameter $constructorParameter): ?array
{
if (\array_key_exists($constructorParameter->getPosition(), $constructArguments) || !$constructorParameter->isDefaultValueAvailable()) {
return null;
Expand Down Expand Up @@ -303,7 +303,7 @@ private function constructorArgumentWithDefaultValue(MapperGeneratorMetadataInte
* $result = new Foo();
* ```
*/
private function constructorWithoutArgument(MapperGeneratorMetadataInterface $mapperMetadata): Stmt|null
private function constructorWithoutArgument(MapperGeneratorMetadataInterface $mapperMetadata): ?Stmt
{
if (!$mapperMetadata->targetIsAUserDefinedClass()
) {
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/MapperConstructorGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getStatements(MapperGeneratorMetadataInterface $mapperMetadata):
* $this->extractCallbacks['propertyName'] = $extractCallback;
* ```
*/
private function extractCallbackForProperty(PropertyMapping $propertyMapping): Stmt\Expression|null
private function extractCallbackForProperty(PropertyMapping $propertyMapping): ?Stmt\Expression
{
$mapperMetadata = $propertyMapping->mapperMetadata;

Expand All @@ -69,7 +69,7 @@ private function extractCallbackForProperty(PropertyMapping $propertyMapping): S
* $this->hydrateCallback['propertyName'] = $hydrateCallback;
* ```
*/
private function hydrateCallbackForProperty(PropertyMapping $propertyMapping): Stmt\Expression|null
private function hydrateCallbackForProperty(PropertyMapping $propertyMapping): ?Stmt\Expression
{
$mapperMetadata = $propertyMapping->mapperMetadata;

Expand Down
14 changes: 7 additions & 7 deletions src/Generator/PropertyConditionsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
final readonly class PropertyConditionsGenerator
{
public function generate(PropertyMapping $propertyMapping): Expr|null
public function generate(PropertyMapping $propertyMapping): ?Expr
{
$conditions = [];

Expand Down Expand Up @@ -60,7 +60,7 @@ public function generate(PropertyMapping $propertyMapping): Expr|null
* property_exists($source, 'propertyName')
* ```
*/
private function propertyExistsForStdClass(PropertyMapping $propertyMapping): Expr|null
private function propertyExistsForStdClass(PropertyMapping $propertyMapping): ?Expr
{
$variableRegistry = $propertyMapping->mapperMetadata->getVariableRegistry();

Expand All @@ -81,7 +81,7 @@ private function propertyExistsForStdClass(PropertyMapping $propertyMapping): Ex
* array_key_exists('propertyName', $source).
* ```
*/
private function propertyExistsForArray(PropertyMapping $propertyMapping): Expr|null
private function propertyExistsForArray(PropertyMapping $propertyMapping): ?Expr
{
if (!$propertyMapping->checkExists || 'array' !== $propertyMapping->mapperMetadata->getSource()) {
return null;
Expand All @@ -102,7 +102,7 @@ private function propertyExistsForArray(PropertyMapping $propertyMapping): Expr|
* MapperContext::isAllowedAttribute($context, 'propertyName', $source).
* ```
*/
private function isAllowedAttribute(PropertyMapping $propertyMapping): Expr|null
private function isAllowedAttribute(PropertyMapping $propertyMapping): ?Expr
{
$mapperMetadata = $propertyMapping->mapperMetadata;

Expand Down Expand Up @@ -132,7 +132,7 @@ private function isAllowedAttribute(PropertyMapping $propertyMapping): Expr|null
* (null !== $context[MapperContext::GROUPS] ?? null && array_intersect($context[MapperContext::GROUPS] ?? [], ['group1', 'group2']))
* ```
*/
private function sourceGroupsCheck(PropertyMapping $propertyMapping): Expr|null
private function sourceGroupsCheck(PropertyMapping $propertyMapping): ?Expr
{
if (!$propertyMapping->sourceGroups) {
return null;
Expand Down Expand Up @@ -169,7 +169,7 @@ private function sourceGroupsCheck(PropertyMapping $propertyMapping): Expr|null
* (null !== $context[MapperContext::GROUPS] ?? null && array_intersect($context[MapperContext::GROUPS] ?? [], ['group1', 'group2']))
* ```
*/
private function targetGroupsCheck(PropertyMapping $propertyMapping): Expr|null
private function targetGroupsCheck(PropertyMapping $propertyMapping): ?Expr
{
if (!$propertyMapping->targetGroups) {
return null;
Expand Down Expand Up @@ -206,7 +206,7 @@ private function targetGroupsCheck(PropertyMapping $propertyMapping): Expr|null
* ($context[MapperContext::DEPTH] ?? 0) <= $maxDepth
* ```
*/
private function maxDepthCheck(PropertyMapping $propertyMapping): Expr|null
private function maxDepthCheck(PropertyMapping $propertyMapping): ?Expr
{
if (!$propertyMapping->maxDepth) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/Shared/CachedReflectionStatementsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
final readonly class CachedReflectionStatementsGenerator
{
public function createTargetStatement(MapperGeneratorMetadataInterface $mapperMetadata): Stmt|null
public function createTargetStatement(MapperGeneratorMetadataInterface $mapperMetadata): ?Stmt
{
if (!$this->supports($mapperMetadata)) {
return null;
Expand All @@ -64,7 +64,7 @@ public function createTargetStatement(MapperGeneratorMetadataInterface $mapperMe
)));
}

public function mapperConstructorStatement(MapperGeneratorMetadataInterface $mapperMetadata): Stmt\Expression|null
public function mapperConstructorStatement(MapperGeneratorMetadataInterface $mapperMetadata): ?Stmt\Expression
{
if (!$this->supports($mapperMetadata)) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/Shared/ClassDiscriminatorResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
final readonly class ClassDiscriminatorResolver
{
public function __construct(
private ClassDiscriminatorResolverInterface|null $classDiscriminator = null,
private ?ClassDiscriminatorResolverInterface $classDiscriminator = null,
) {
}

Expand All @@ -33,7 +33,7 @@ public function hasClassDiscriminator(MapperGeneratorMetadataInterface $mapperMe
return true;
}

public function propertyMapping(MapperGeneratorMetadataInterface $mapperMetadata): PropertyMapping|null
public function propertyMapping(MapperGeneratorMetadataInterface $mapperMetadata): ?PropertyMapping
{
$classDiscriminatorMapping = $this->classDiscriminator?->getMappingForClass($mapperMetadata->getTarget());

Expand Down
2 changes: 1 addition & 1 deletion src/MapperGeneratorMetadataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function canHaveCircularReference(): bool;
*/
public function shouldMapPrivateProperties(): bool;

public function getCachedTargetReflectionClass(): \ReflectionClass|null; // @phpstan-ignore-line
public function getCachedTargetReflectionClass(): ?\ReflectionClass; // @phpstan-ignore-line

/**
* Fields to set in the constructor: this allows transforming them before the constructor is called.
Expand Down
4 changes: 2 additions & 2 deletions src/MapperMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MapperMetadata implements MapperGeneratorMetadataInterface
private array $customMapping = [];

/** @var list<string>|null */
private array|null $propertiesInConstructor = null;
private ?array $propertiesInConstructor = null;

private VariableRegistry $variableRegistry;

Expand All @@ -57,7 +57,7 @@ public function __construct(
$this->variableRegistry = new VariableRegistry();
}

public function getCachedTargetReflectionClass(): \ReflectionClass|null
public function getCachedTargetReflectionClass(): ?\ReflectionClass
{
return $this->targetReflectionClass;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class CustomTransformersRegistry
private array $customTransformers = [];

/** @var list<CustomTransformerInterface>|null */
private array|null $prioritizedCustomTransformers = null;
private ?array $prioritizedCustomTransformers = null;

public function addCustomTransformer(CustomTransformerInterface $customTransformer): void
{
Expand All @@ -31,7 +31,7 @@ public function addCustomTransformer(CustomTransformerInterface $customTransform
*
* @return class-string<CustomTransformerInterface>|null
*/
public function getCustomTransformerClass(MapperMetadataInterface $mapperMetadata, array $sourceTypes, array $targetTypes, string $propertyName): string|null
public function getCustomTransformerClass(MapperMetadataInterface $mapperMetadata, array $sourceTypes, array $targetTypes, string $propertyName): ?string
{
foreach ($this->prioritizedCustomTransformers() as $customTransformer) {
if (
Expand Down
4 changes: 2 additions & 2 deletions tests/AutoMapperWithCustomTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function testFromSourceToTargetMultipleFieldsTransformation(): void
self::assertSame('1985-07-01', $birthDateDateTime->date->format('Y-m-d'));
}

private static function createUserDTO(string|null $name = null, string|null $city = null): UserDTO
private static function createUserDTO(?string $name = null, ?string $city = null): UserDTO
{
$user = new UserDTO();
$user->id = 666;
Expand All @@ -128,7 +128,7 @@ private static function createUserDTO(string|null $name = null, string|null $cit
return $user;
}

private static function createUser(string|null $name = null, string|null $city = null): User
private static function createUser(?string $name = null, ?string $city = null): User
{
$user = new User(666, $name ?? 'name', 666);
$address = new Address();
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/ClassWithNullablePropertyInConstructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

readonly class ClassWithNullablePropertyInConstructor
{
public function __construct(public int $foo, public int|null $bar = null)
public function __construct(public int $foo, public ?int $bar = null)
{
}
}
2 changes: 1 addition & 1 deletion tests/Normalizer/AutoMapperNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function testItUsesSerializerContext(): void
{
$normalizer = new AutoMapperNormalizer(
new class() implements AutoMapperInterface, AutoMapperRegistryInterface {
public function map(null|array|object $source, string|array|object $target, array $context = []): null|array|object
public function map(array|object|null $source, string|array|object $target, array $context = []): array|object|null
{
return $context;
}
Expand Down
Loading

0 comments on commit f0bb0fe

Please sign in to comment.