Skip to content

Commit cdd8cdc

Browse files
committed
PHP73 adjustments
1 parent 3ed8637 commit cdd8cdc

31 files changed

+163
-123
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: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
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;
22+
use function is_object;
1923
use MagicSunday\JsonMapper\Annotation\ReplaceNullWithDefaultValue;
2024
use MagicSunday\JsonMapper\Annotation\ReplaceProperty;
2125
use MagicSunday\JsonMapper\Converter\PropertyNameConverterInterface;
@@ -27,16 +31,12 @@
2731
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
2832
use Symfony\Component\PropertyInfo\Type;
2933

30-
use function array_key_exists;
31-
use function in_array;
32-
use function is_array;
33-
use function is_object;
34-
3534
/**
3635
* JsonMapper.
3736
*
3837
* @author Rico Sonntag <[email protected]>
3938
* @license https://opensource.org/licenses/MIT
39+
*
4040
* @link https://github.com/magicsunday/jsonmapper/
4141
*
4242
* @template TEntity
@@ -47,41 +47,41 @@ class JsonMapper
4747
/**
4848
* @var PropertyInfoExtractorInterface
4949
*/
50-
private PropertyInfoExtractorInterface $extractor;
50+
private $extractor;
5151

5252
/**
5353
* @var PropertyAccessorInterface
5454
*/
55-
private PropertyAccessorInterface $accessor;
55+
private $accessor;
5656

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

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

7272
/**
7373
* The default value type instance.
7474
*
7575
* @var Type
7676
*/
77-
private Type $defaultType;
77+
private $defaultType;
7878

7979
/**
8080
* The custom types.
8181
*
8282
* @var Closure[]
8383
*/
84-
private array $types = [];
84+
private $types = [];
8585

8686
/**
8787
* JsonMapper constructor.
@@ -311,7 +311,7 @@ private function getReflectionProperty(string $className, string $propertyName):
311311
{
312312
try {
313313
return new ReflectionProperty($className, $propertyName);
314-
} catch (ReflectionException) {
314+
} catch (ReflectionException $exception) {
315315
return null;
316316
}
317317
}
@@ -422,15 +422,15 @@ private function hasClassAnnotation(string $className, string $annotationName):
422422
*
423423
* @return mixed|null
424424
*/
425-
private function getDefaultValue(string $className, string $propertyName): mixed
425+
private function getDefaultValue(string $className, string $propertyName)
426426
{
427427
$reflectionProperty = $this->getReflectionProperty($className, $propertyName);
428428

429429
if (!($reflectionProperty instanceof ReflectionProperty)) {
430430
return null;
431431
}
432432

433-
return $reflectionProperty->getDefaultValue();
433+
return $reflectionProperty->getDeclaringClass()->getDefaultProperties()[$propertyName] ?? null;
434434
}
435435

436436
/**
@@ -440,7 +440,7 @@ private function getDefaultValue(string $className, string $propertyName): mixed
440440
*
441441
* @return bool
442442
*/
443-
private function isNumericIndexArray(mixed $json): bool
443+
private function isNumericIndexArray($json): bool
444444
{
445445
foreach ($json as $propertyName => $propertyValue) {
446446
if (is_int($propertyName)) {
@@ -458,7 +458,7 @@ private function isNumericIndexArray(mixed $json): bool
458458
*
459459
* @return bool
460460
*/
461-
private function isIterableWithArraysOrObjects(mixed $json): bool
461+
private function isIterableWithArraysOrObjects($json): bool
462462
{
463463
// Return false if JSON is not an array or object (is_iterable won't work here)
464464
if (!is_array($json) && !is_object($json)) {
@@ -513,7 +513,7 @@ private function assertClassesExists(string $className, ?string $collectionClass
513513
* @param string $name
514514
* @param mixed $value
515515
*/
516-
private function setProperty(object $entity, string $name, mixed $value): void
516+
private function setProperty(object $entity, string $name, $value): void
517517
{
518518
// Handle variadic setters
519519
if (is_array($value)) {
@@ -573,7 +573,7 @@ private function getType(string $className, string $propertyName): Type
573573
*
574574
* @throws DomainException
575575
*/
576-
private function getValue(mixed $json, Type $type): mixed
576+
private function getValue($json, Type $type)
577577
{
578578
if ((is_array($json) || is_object($json)) && $type->isCollection()) {
579579
$collectionType = $this->getCollectionValueType($type);
@@ -655,7 +655,7 @@ private function getClassNameFromType(Type $type): string
655655
*
656656
* @throws DomainException
657657
*/
658-
private function getMappedClassName(string $className, mixed $json): string
658+
private function getMappedClassName(string $className, $json): string
659659
{
660660
if (array_key_exists($className, $this->classMap)) {
661661
$classNameOrClosure = $this->classMap[$className];
@@ -683,7 +683,7 @@ private function getMappedClassName(string $className, mixed $json): string
683683
*
684684
* @throws DomainException
685685
*/
686-
private function getClassName(mixed $json, Type $type): string
686+
private function getClassName($json, Type $type): string
687687
{
688688
return $this->getMappedClassName(
689689
$this->getClassNameFromType($type),
@@ -701,7 +701,7 @@ private function getClassName(mixed $json, Type $type): string
701701
*
702702
* @throws DomainException
703703
*/
704-
private function asCollection(mixed $json, Type $type): ?array
704+
private function asCollection($json, Type $type): ?array
705705
{
706706
if ($json === null) {
707707
return null;
@@ -726,7 +726,7 @@ private function asCollection(mixed $json, Type $type): ?array
726726
*
727727
* @throws DomainException
728728
*/
729-
private function asObject(mixed $json, Type $type): mixed
729+
private function asObject($json, Type $type)
730730
{
731731
/** @var class-string<TEntity> $className */
732732
$className = $this->getClassName($json, $type);
@@ -762,7 +762,7 @@ private function isCustomType(string $typeClassName): bool
762762
*
763763
* @return mixed
764764
*/
765-
private function callCustomClosure(mixed $json, string $typeClassName): mixed
765+
private function callCustomClosure($json, string $typeClassName)
766766
{
767767
$callback = $this->types[$typeClassName];
768768

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)