From 97dc573ef8f15970b14b98b8357dc77990f5cd5a Mon Sep 17 00:00:00 2001 From: DimanKuskov Date: Thu, 12 Nov 2020 11:52:47 +0300 Subject: [PATCH] Added Symfony 5 support (#3) --- composer.json | 4 +-- phpunit.xml.dist | 31 +++++++++------------- src/DtoMapper.php | 15 +++++++---- src/Exception/CannotMapToDto.php | 14 +++++----- src/Exception/MapperReturnedNotAString.php | 1 + src/Exception/NotADateTimeValue.php | 1 + src/Exception/NotAnArrayValue.php | 1 + src/Exception/UnexpectedNullValue.php | 1 + src/Exception/UnexpectedScalarValue.php | 1 + 9 files changed, 36 insertions(+), 33 deletions(-) diff --git a/composer.json b/composer.json index 2abf44b..329db43 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "require": { "php": "^7.4", "thecodingmachine/safe": "^1.1", - "symfony/property-info": "^4.0" + "symfony/property-info": "^4.0|^5.0" }, "autoload": { "psr-4": { @@ -34,7 +34,7 @@ "all": "composer stan && composer test && composer cs && composer sec" }, "require-dev": { - "doctrine/coding-standard": "^7.0", + "doctrine/coding-standard": "^8.2", "phpstan/phpstan": "^0.12.19", "phpunit/phpunit": "^9.1", "sensiolabs/security-checker": "^6.0", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 10f717f..e906acf 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,20 +1,13 @@ - - - - ./tests/ - - - - - - ./src/ - - - \ No newline at end of file + + + + ./src/ + + + + + ./tests/ + + + diff --git a/src/DtoMapper.php b/src/DtoMapper.php index cd8a7a7..a5ec9ff 100644 --- a/src/DtoMapper.php +++ b/src/DtoMapper.php @@ -25,6 +25,7 @@ use Safe\Exceptions\VarException; use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor; use Symfony\Component\PropertyInfo\PropertyInfoExtractor; + use function array_key_exists; use function array_map; use function class_exists; @@ -171,7 +172,7 @@ private function getPropertyValue($rawValue, ReflectionProperty $property, $from throw CannotMapToDto::becausePhpDocIsCorrupt($property->getName(), $className); } - $itemClassName = $docIterableType->getClassName()??$docIterableType->getBuiltinType(); + $itemClassName = $docIterableType->getClassName() ?? $docIterableType->getBuiltinType(); $isBuiltIn = ($docIterableType->getClassName() === null); $result = []; @@ -238,9 +239,13 @@ private function getNotIterableValue($rawValue, string $typeName, bool $isBuiltI */ private function getValue($object, string $item) { - if (((is_array($object) || $object instanceof ArrayObject) && - (isset($object[$item]) || array_key_exists($item, (array) $object))) - || ($object instanceof ArrayAccess && isset($object[$item])) + if ( + ((is_array($object) || + $object instanceof ArrayObject) && + (isset($object[$item]) || + array_key_exists($item, (array) $object))) || + ($object instanceof ArrayAccess && + isset($object[$item])) ) { return $object[$item]; } @@ -339,7 +344,7 @@ static function (string $value) { return $ret; } - private static function strToLowerEn(string $str) : string + private static function strToLowerEn(string $str): string { return strtr($str, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); } diff --git a/src/Exception/CannotMapToDto.php b/src/Exception/CannotMapToDto.php index 50d8700..fe4eec3 100644 --- a/src/Exception/CannotMapToDto.php +++ b/src/Exception/CannotMapToDto.php @@ -8,7 +8,7 @@ class CannotMapToDto extends DtoMapperError { - public static function becausePhpDocIsNotReadable(string $name, string $class) : self + public static function becausePhpDocIsNotReadable(string $name, string $class): self { return new self( sprintf( @@ -19,7 +19,7 @@ public static function becausePhpDocIsNotReadable(string $name, string $class) : ); } - public static function becausePhpDocIsMultiple(string $name, string $class) : self + public static function becausePhpDocIsMultiple(string $name, string $class): self { return new self( sprintf( @@ -30,7 +30,7 @@ public static function becausePhpDocIsMultiple(string $name, string $class) : se ); } - public static function becausePhpDocIsNotAnArray(string $name, string $class) : self + public static function becausePhpDocIsNotAnArray(string $name, string $class): self { return new self( sprintf( @@ -41,7 +41,7 @@ public static function becausePhpDocIsNotAnArray(string $name, string $class) : ); } - public static function becausePhpDocIsCorrupt(string $name, string $class) : self + public static function becausePhpDocIsCorrupt(string $name, string $class): self { return new self( sprintf( @@ -52,7 +52,7 @@ public static function becausePhpDocIsCorrupt(string $name, string $class) : sel ); } - public static function becauseNoPhpType(string $name, string $class) : self + public static function becauseNoPhpType(string $name, string $class): self { return new self( sprintf( @@ -63,7 +63,7 @@ public static function becauseNoPhpType(string $name, string $class) : self ); } - public static function becauseClassDoesNotExist(string $childClass, string $name, string $class) : self + public static function becauseClassDoesNotExist(string $childClass, string $name, string $class): self { return new self( sprintf( @@ -75,7 +75,7 @@ public static function becauseClassDoesNotExist(string $childClass, string $name ); } - public static function becauseRootClassDoesNotExist(string $class) : self + public static function becauseRootClassDoesNotExist(string $class): self { return new self( sprintf( diff --git a/src/Exception/MapperReturnedNotAString.php b/src/Exception/MapperReturnedNotAString.php index 2f013ec..df2f21a 100644 --- a/src/Exception/MapperReturnedNotAString.php +++ b/src/Exception/MapperReturnedNotAString.php @@ -5,6 +5,7 @@ namespace OnMoon\DtoMapper\Exception; use Safe\Exceptions\StringsException; + use function Safe\sprintf; class MapperReturnedNotAString extends DtoMapperError diff --git a/src/Exception/NotADateTimeValue.php b/src/Exception/NotADateTimeValue.php index 3f23ae5..ffa1e03 100644 --- a/src/Exception/NotADateTimeValue.php +++ b/src/Exception/NotADateTimeValue.php @@ -5,6 +5,7 @@ namespace OnMoon\DtoMapper\Exception; use Safe\Exceptions\StringsException; + use function Safe\sprintf; class NotADateTimeValue extends DtoMapperError diff --git a/src/Exception/NotAnArrayValue.php b/src/Exception/NotAnArrayValue.php index a6c48cb..98fb73e 100644 --- a/src/Exception/NotAnArrayValue.php +++ b/src/Exception/NotAnArrayValue.php @@ -5,6 +5,7 @@ namespace OnMoon\DtoMapper\Exception; use Safe\Exceptions\StringsException; + use function Safe\sprintf; class NotAnArrayValue extends DtoMapperError diff --git a/src/Exception/UnexpectedNullValue.php b/src/Exception/UnexpectedNullValue.php index 17d9fa8..3eec157 100644 --- a/src/Exception/UnexpectedNullValue.php +++ b/src/Exception/UnexpectedNullValue.php @@ -5,6 +5,7 @@ namespace OnMoon\DtoMapper\Exception; use Safe\Exceptions\StringsException; + use function Safe\sprintf; class UnexpectedNullValue extends DtoMapperError diff --git a/src/Exception/UnexpectedScalarValue.php b/src/Exception/UnexpectedScalarValue.php index c793453..c619799 100644 --- a/src/Exception/UnexpectedScalarValue.php +++ b/src/Exception/UnexpectedScalarValue.php @@ -5,6 +5,7 @@ namespace OnMoon\DtoMapper\Exception; use Safe\Exceptions\StringsException; + use function Safe\sprintf; class UnexpectedScalarValue extends DtoMapperError