Skip to content

Commit db4168c

Browse files
committed
PHP73 adjustments
1 parent 75c54d9 commit db4168c

31 files changed

+162
-122
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
php: [ '8.1', '8.2', '8.3' ]
14+
php: [ '7.3', '7.4', '8.0' ]
1515

1616
steps:
1717
- id: checkout
@@ -23,7 +23,7 @@ jobs:
2323
uses: shivammathur/setup-php@v2
2424
with:
2525
php-version: ${{ matrix.php }}
26-
tools: composer:v2, php-cs-fixer
26+
tools: composer:v2
2727

2828
- name: Validate composer.json and composer.lock
2929
run: composer validate

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ composer.lock
1515

1616
# Cache
1717
.php-cs-fixer.cache
18+
.php_cs.cache
1819
.phplint.cache
1920
.phpunit.result.cache
2021
.phpunit.cache

.php-cs-fixer.dist.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
->setRiskyAllowed(true)
4141
->setRules([
4242
'@PSR12' => true,
43-
'@PER-CS2.0' => true,
4443
'@Symfony' => true,
4544

4645
// Additional custom rules
@@ -57,19 +56,9 @@
5756
'phpdoc_to_comment' => false,
5857
'phpdoc_no_alias_tag' => false,
5958
'no_superfluous_phpdoc_tags' => false,
60-
'phpdoc_separation' => [
61-
'groups' => [
62-
[
63-
'author',
64-
'license',
65-
'link',
66-
],
67-
],
68-
],
59+
'phpdoc_separation' => true,
6960
'no_alias_functions' => true,
70-
'whitespace_after_comma_in_array' => [
71-
'ensure_single_space' => true,
72-
],
61+
'whitespace_after_comma_in_array' => true,
7362
'single_line_throw' => false,
7463
'self_accessor' => false,
7564
'global_namespace_import' => [
@@ -79,7 +68,6 @@
7968
],
8069
'function_declaration' => [
8170
'closure_function_spacing' => 'one',
82-
'closure_fn_spacing' => 'one',
8371
],
8472
'binary_operator_spaces' => [
8573
'operators' => [

composer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
"issues": "https://github.com/magicsunday/jsonmapper/issues"
1515
},
1616
"require": {
17-
"php": ">=8.1.0 <8.4.0",
17+
"php": ">=7.3.0 <8.1.0",
1818
"ext-json": "*",
19-
"symfony/property-info": "^6.0 || ^7.0",
20-
"symfony/property-access": "^6.0 || ^7.0",
21-
"doctrine/inflector": "^2.0",
22-
"doctrine/annotations": "^2.0"
19+
"symfony/property-info": "^5.0 || ^6.0 || ^7.0",
20+
"symfony/property-access": "^5.0 || ^6.0 || ^7.0",
21+
"doctrine/inflector": "^1.0 || ^2.0",
22+
"doctrine/annotations": "^1.0 || ^2.0"
2323
},
2424
"require-dev": {
25-
"phpdocumentor/reflection-docblock": "^5.0",
26-
"friendsofphp/php-cs-fixer": "^3.50",
27-
"overtrue/phplint": "^3.4 || ^9.0",
28-
"phpunit/phpunit": "^10.0 || ^11.0",
25+
"phpdocumentor/reflection-docblock": "^4.0 || ^5.0",
26+
"friendsofphp/php-cs-fixer": "^2.0",
27+
"overtrue/phplint": "^2.0 || ^3.0 || ^9.0",
28+
"phpunit/phpunit": "^9.0 || ^10.0 || ^11.0",
2929
"phpstan/phpstan": "^1.10",
3030
"phpstan/phpstan-phpunit": "^1.3",
3131
"phpstan/phpstan-strict-rules": "^1.5",

phpunit.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
44
colors="true"
55
columns="max"
66
stderr="true"
77
bootstrap="./.build/vendor/autoload.php"
8-
cacheDirectory=".phpunit.cache"
98
>
109
<testsuites>
1110
<testsuite name="Integration Tests">
1211
<directory>./test</directory>
1312
</testsuite>
1413
</testsuites>
15-
<source>
14+
<coverage>
1615
<include>
17-
<directory>./src</directory>
16+
<directory suffix=".php">./src</directory>
1817
</include>
19-
</source>
18+
</coverage>
2019
</phpunit>

rector.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
1616
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
1717
use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
18-
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
19-
use Rector\Php80\Rector\FunctionLike\MixedTypeRector;
20-
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
2118
use Rector\Set\ValueObject\LevelSetList;
2219
use Rector\Set\ValueObject\SetList;
2320
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector;
@@ -44,17 +41,14 @@
4441
SetList::CODING_STYLE,
4542
SetList::CODE_QUALITY,
4643
SetList::DEAD_CODE,
47-
LevelSetList::UP_TO_PHP_81,
44+
LevelSetList::UP_TO_PHP_73,
4845
]);
4946

5047
// Skip some rules
5148
$rectorConfig->skip([
5249
CatchExceptionNameMatchingTypeRector::class,
53-
ClassPropertyAssignToConstructorPromotionRector::class,
5450
LocallyCalledStaticMethodToNonStaticRector::class,
55-
MixedTypeRector::class,
5651
ParamTypeByMethodCallTypeRector::class,
57-
ReadOnlyPropertyRector::class,
5852
RemoveUselessParamTagRector::class,
5953
RemoveUselessReturnTagRector::class,
6054
RemoveUselessVarTagRector::class,

src/JsonMapper.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111

1212
namespace MagicSunday;
1313

14+
use function array_key_exists;
1415
use Closure;
1516
use Doctrine\Common\Annotations\Annotation;
1617
use Doctrine\Common\Annotations\AnnotationReader;
1718
use DomainException;
19+
use function in_array;
1820
use InvalidArgumentException;
21+
use function is_array;
1922
use MagicSunday\JsonMapper\Annotation\ReplaceNullWithDefaultValue;
2023
use MagicSunday\JsonMapper\Annotation\ReplaceProperty;
2124
use MagicSunday\JsonMapper\Converter\PropertyNameConverterInterface;
@@ -27,15 +30,12 @@
2730
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
2831
use Symfony\Component\PropertyInfo\Type;
2932

30-
use function array_key_exists;
31-
use function in_array;
32-
use function is_array;
33-
3433
/**
3534
* JsonMapper.
3635
*
3736
* @author Rico Sonntag <[email protected]>
3837
* @license https://opensource.org/licenses/MIT
38+
*
3939
* @link https://github.com/magicsunday/jsonmapper/
4040
*
4141
* @template TEntity
@@ -46,41 +46,41 @@ class JsonMapper
4646
/**
4747
* @var PropertyInfoExtractorInterface
4848
*/
49-
private PropertyInfoExtractorInterface $extractor;
49+
private $extractor;
5050

5151
/**
5252
* @var PropertyAccessorInterface
5353
*/
54-
private PropertyAccessorInterface $accessor;
54+
private $accessor;
5555

5656
/**
5757
* The property name converter instance.
5858
*
5959
* @var PropertyNameConverterInterface|null
6060
*/
61-
protected ?PropertyNameConverterInterface $nameConverter;
61+
protected $nameConverter;
6262

6363
/**
6464
* Override class names that JsonMapper uses to create objects. Useful when your
6565
* setter methods accept abstract classes or interfaces.
6666
*
6767
* @var string[]|Closure[]
6868
*/
69-
private array $classMap;
69+
private $classMap;
7070

7171
/**
7272
* The default value type instance.
7373
*
7474
* @var Type
7575
*/
76-
private Type $defaultType;
76+
private $defaultType;
7777

7878
/**
7979
* The custom types.
8080
*
8181
* @var Closure[]
8282
*/
83-
private array $types = [];
83+
private $types = [];
8484

8585
/**
8686
* JsonMapper constructor.
@@ -308,7 +308,7 @@ private function getReflectionProperty(string $className, string $propertyName):
308308
{
309309
try {
310310
return new ReflectionProperty($className, $propertyName);
311-
} catch (ReflectionException) {
311+
} catch (ReflectionException $exception) {
312312
return null;
313313
}
314314
}
@@ -419,15 +419,15 @@ private function hasClassAnnotation(string $className, string $annotationName):
419419
*
420420
* @return mixed|null
421421
*/
422-
private function getDefaultValue(string $className, string $propertyName): mixed
422+
private function getDefaultValue(string $className, string $propertyName)
423423
{
424424
$reflectionProperty = $this->getReflectionProperty($className, $propertyName);
425425

426426
if (!($reflectionProperty instanceof ReflectionProperty)) {
427427
return null;
428428
}
429429

430-
return $reflectionProperty->getDefaultValue();
430+
return $reflectionProperty->getDeclaringClass()->getDefaultProperties()[$propertyName] ?? null;
431431
}
432432

433433
/**
@@ -437,7 +437,7 @@ private function getDefaultValue(string $className, string $propertyName): mixed
437437
*
438438
* @return bool
439439
*/
440-
private function isNumericIndexArray(mixed $json): bool
440+
private function isNumericIndexArray($json): bool
441441
{
442442
foreach ($json as $propertyName => $propertyValue) {
443443
if (is_int($propertyName)) {
@@ -455,7 +455,7 @@ private function isNumericIndexArray(mixed $json): bool
455455
*
456456
* @return bool
457457
*/
458-
private function isIterableWithArraysOrObjects(mixed $json): bool
458+
private function isIterableWithArraysOrObjects($json): bool
459459
{
460460
// Return false if JSON is not an array or object (is_iterable won't work here)
461461
if (!is_array($json) && !is_object($json)) {
@@ -510,7 +510,7 @@ private function assertClassesExists(string $className, ?string $collectionClass
510510
* @param string $name
511511
* @param mixed $value
512512
*/
513-
private function setProperty(object $entity, string $name, mixed $value): void
513+
private function setProperty(object $entity, string $name, $value): void
514514
{
515515
// Handle variadic setters
516516
if (is_array($value)) {
@@ -570,7 +570,7 @@ private function getType(string $className, string $propertyName): Type
570570
*
571571
* @throws DomainException
572572
*/
573-
private function getValue(mixed $json, Type $type): mixed
573+
private function getValue($json, Type $type)
574574
{
575575
if ((is_array($json) || is_object($json)) && $type->isCollection()) {
576576
$collectionType = $this->getCollectionValueType($type);
@@ -652,7 +652,7 @@ private function getClassNameFromType(Type $type): string
652652
*
653653
* @throws DomainException
654654
*/
655-
private function getMappedClassName(string $className, mixed $json): string
655+
private function getMappedClassName(string $className, $json): string
656656
{
657657
if (array_key_exists($className, $this->classMap)) {
658658
$classNameOrClosure = $this->classMap[$className];
@@ -680,7 +680,7 @@ private function getMappedClassName(string $className, mixed $json): string
680680
*
681681
* @throws DomainException
682682
*/
683-
private function getClassName(mixed $json, Type $type): string
683+
private function getClassName($json, Type $type): string
684684
{
685685
return $this->getMappedClassName(
686686
$this->getClassNameFromType($type),
@@ -698,7 +698,7 @@ private function getClassName(mixed $json, Type $type): string
698698
*
699699
* @throws DomainException
700700
*/
701-
private function asCollection(mixed $json, Type $type): ?array
701+
private function asCollection($json, Type $type): ?array
702702
{
703703
if ($json === null) {
704704
return null;
@@ -723,7 +723,7 @@ private function asCollection(mixed $json, Type $type): ?array
723723
*
724724
* @throws DomainException
725725
*/
726-
private function asObject(mixed $json, Type $type): mixed
726+
private function asObject($json, Type $type)
727727
{
728728
/** @var class-string<TEntity> $className */
729729
$className = $this->getClassName($json, $type);
@@ -759,7 +759,7 @@ private function isCustomType(string $typeClassName): bool
759759
*
760760
* @return mixed
761761
*/
762-
private function callCustomClosure(mixed $json, string $typeClassName): mixed
762+
private function callCustomClosure($json, string $typeClassName)
763763
{
764764
$callback = $this->types[$typeClassName];
765765

src/JsonMapper/Converter/CamelCasePropertyNameConverter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
*
2020
* @author Rico Sonntag <[email protected]>
2121
* @license https://opensource.org/licenses/MIT
22+
*
2223
* @link https://github.com/magicsunday/jsonmapper/
2324
*/
2425
class CamelCasePropertyNameConverter implements PropertyNameConverterInterface
2526
{
2627
/**
2728
* @var Inflector
2829
*/
29-
private Inflector $inflector;
30+
private $inflector;
3031

3132
/**
3233
* CamelCasePropertyNameConverter constructor.

src/JsonMapper/Converter/PropertyNameConverterInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*
1717
* @author Rico Sonntag <[email protected]>
1818
* @license https://opensource.org/licenses/MIT
19+
*
1920
* @link https://github.com/magicsunday/jsonmapper/
2021
*/
2122
interface PropertyNameConverterInterface

test/Annotation/ReplacePropertyTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020
*
2121
* @author Rico Sonntag <[email protected]>
2222
* @license https://opensource.org/licenses/MIT
23+
*
2324
* @link https://github.com/magicsunday/jsonmapper/
2425
*/
2526
class ReplacePropertyTest extends TestCase
2627
{
2728
/**
2829
* Tests replacing a property.
30+
*
31+
* @test
2932
*/
30-
#[Test]
3133
public function replaceProperty(): void
3234
{
3335
$result = $this->getJsonMapper()

test/Classes/Base.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*
1717
* @author Rico Sonntag <[email protected]>
1818
* @license https://opensource.org/licenses/MIT
19+
*
1920
* @link https://github.com/magicsunday/jsonmapper/
2021
*/
2122
class Base
@@ -61,7 +62,7 @@ class Base
6162
/**
6263
* @var string
6364
*/
64-
private string $privateProperty = '';
65+
private $privateProperty = '';
6566

6667
/**
6768
* @return string

0 commit comments

Comments
 (0)