Skip to content

Commit

Permalink
Added Symfony 5 support (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimanKuskov authored Nov 12, 2020
1 parent 993b55f commit 97dc573
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 33 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand Down
31 changes: 12 additions & 19 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
bootstrap="./tests/bootstrap.php"
>
<testsuites>
<testsuite name="OnMoon Dto Mapper Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" colors="true" beStrictAboutOutputDuringTests="true" beStrictAboutTodoAnnotatedTests="true" bootstrap="./tests/bootstrap.php">
<coverage>
<include>
<directory>./src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="OnMoon Dto Mapper Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
15 changes: 10 additions & 5 deletions src/DtoMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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');
}
Expand Down
14 changes: 7 additions & 7 deletions src/Exception/CannotMapToDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/Exception/MapperReturnedNotAString.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace OnMoon\DtoMapper\Exception;

use Safe\Exceptions\StringsException;

use function Safe\sprintf;

class MapperReturnedNotAString extends DtoMapperError
Expand Down
1 change: 1 addition & 0 deletions src/Exception/NotADateTimeValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace OnMoon\DtoMapper\Exception;

use Safe\Exceptions\StringsException;

use function Safe\sprintf;

class NotADateTimeValue extends DtoMapperError
Expand Down
1 change: 1 addition & 0 deletions src/Exception/NotAnArrayValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace OnMoon\DtoMapper\Exception;

use Safe\Exceptions\StringsException;

use function Safe\sprintf;

class NotAnArrayValue extends DtoMapperError
Expand Down
1 change: 1 addition & 0 deletions src/Exception/UnexpectedNullValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace OnMoon\DtoMapper\Exception;

use Safe\Exceptions\StringsException;

use function Safe\sprintf;

class UnexpectedNullValue extends DtoMapperError
Expand Down
1 change: 1 addition & 0 deletions src/Exception/UnexpectedScalarValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace OnMoon\DtoMapper\Exception;

use Safe\Exceptions\StringsException;

use function Safe\sprintf;

class UnexpectedScalarValue extends DtoMapperError
Expand Down

0 comments on commit 97dc573

Please sign in to comment.