Skip to content

Commit

Permalink
PHP73 adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
magicsunday committed Aug 2, 2024
1 parent a73bbaf commit 84563c7
Show file tree
Hide file tree
Showing 20 changed files with 122 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '8.1', '8.2', '8.3' ]
php: [ '7.3', '7.4', '8.0' ]

steps:
- id: checkout
Expand Down
16 changes: 2 additions & 14 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
->setRiskyAllowed(true)
->setRules([
'@PSR12' => true,
'@PER-CS2.0' => true,
'@Symfony' => true,

// Additional custom rules
Expand All @@ -57,19 +56,9 @@
'phpdoc_to_comment' => false,
'phpdoc_no_alias_tag' => false,
'no_superfluous_phpdoc_tags' => false,
'phpdoc_separation' => [
'groups' => [
[
'author',
'license',
'link',
],
],
],
'phpdoc_separation' => true,
'no_alias_functions' => true,
'whitespace_after_comma_in_array' => [
'ensure_single_space' => true,
],
'whitespace_after_comma_in_array' => true,
'single_line_throw' => false,
'self_accessor' => false,
'global_namespace_import' => [
Expand All @@ -79,7 +68,6 @@
],
'function_declaration' => [
'closure_function_spacing' => 'one',
'closure_fn_spacing' => 'one',
],
'binary_operator_spaces' => [
'operators' => [
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
"issues": "https://github.com/magicsunday/jsonmapper/issues"
},
"require": {
"php": ">=8.1.0 <8.4.0",
"php": ">=7.3.0 <8.1.0",
"ext-json": "*",
"symfony/property-info": "^6.0 || ^7.0",
"symfony/property-access": "^6.0 || ^7.0",
"doctrine/inflector": "^2.0",
"doctrine/annotations": "^2.0"
"symfony/property-info": "^5.0 || ^6.0 || ^7.0",
"symfony/property-access": "^5.0 || ^6.0 || ^7.0",
"doctrine/inflector": "^1.0 || ^2.0",
"doctrine/annotations": "^1.0 || ^2.0"
},
"require-dev": {
"phpdocumentor/reflection-docblock": "^5.0",
"friendsofphp/php-cs-fixer": "^3.50",
"overtrue/phplint": "^3.4 || ^9.0",
"phpunit/phpunit": "^10.0 || ^11.0",
"phpdocumentor/reflection-docblock": "^4.0 || ^5.0",
"friendsofphp/php-cs-fixer": "^2.0 || ^3.0",
"overtrue/phplint": "^2.0 || ^3.0 || ^9.0",
"phpunit/phpunit": "^9.0 || ^10.0 || ^11.0",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-strict-rules": "^1.5",
Expand Down
9 changes: 4 additions & 5 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
colors="true"
columns="max"
stderr="true"
bootstrap="./.build/vendor/autoload.php"
cacheDirectory=".phpunit.cache"
>
<testsuites>
<testsuite name="Integration Tests">
<directory>./test</directory>
</testsuite>
</testsuites>
<source>
<coverage>
<include>
<directory>./src</directory>
<directory suffix=".php">./src</directory>
</include>
</source>
</coverage>
</phpunit>
8 changes: 1 addition & 7 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Rector\Php80\Rector\FunctionLike\MixedTypeRector;
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector;
Expand All @@ -44,17 +41,14 @@
SetList::CODING_STYLE,
SetList::CODE_QUALITY,
SetList::DEAD_CODE,
LevelSetList::UP_TO_PHP_81,
LevelSetList::UP_TO_PHP_73,
]);

// Skip some rules
$rectorConfig->skip([
CatchExceptionNameMatchingTypeRector::class,
ClassPropertyAssignToConstructorPromotionRector::class,
LocallyCalledStaticMethodToNonStaticRector::class,
MixedTypeRector::class,
ParamTypeByMethodCallTypeRector::class,
ReadOnlyPropertyRector::class,
RemoveUselessParamTagRector::class,
RemoveUselessReturnTagRector::class,
RemoveUselessVarTagRector::class,
Expand Down
16 changes: 8 additions & 8 deletions src/JsonMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,41 +46,41 @@ class JsonMapper
/**
* @var PropertyInfoExtractorInterface
*/
private PropertyInfoExtractorInterface $extractor;
private $extractor;

/**
* @var PropertyAccessorInterface
*/
private PropertyAccessorInterface $accessor;
private $accessor;

/**
* The property name converter instance.
*
* @var PropertyNameConverterInterface|null
*/
protected ?PropertyNameConverterInterface $nameConverter;
protected $nameConverter;

/**
* Override class names that JsonMapper uses to create objects. Useful when your
* setter methods accept abstract classes or interfaces.
*
* @var string[]|Closure[]
*/
private array $classMap;
private $classMap;

/**
* The default value type instance.
*
* @var Type
*/
private Type $defaultType;
private $defaultType;

/**
* The custom types.
*
* @var Closure[]
*/
private array $types = [];
private $types = [];

/**
* JsonMapper constructor.
Expand Down Expand Up @@ -302,7 +302,7 @@ private function getReflectionProperty(string $className, string $propertyName):
{
try {
return new ReflectionProperty($className, $propertyName);
} catch (ReflectionException) {
} catch (ReflectionException $exception) {
return null;
}
}
Expand Down Expand Up @@ -421,7 +421,7 @@ private function getDefaultValue(string $className, string $propertyName)
return null;
}

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CamelCasePropertyNameConverter implements PropertyNameConverterInterface
/**
* @var Inflector
*/
private Inflector $inflector;
private $inflector;

/**
* CamelCasePropertyNameConverter constructor.
Expand Down
3 changes: 2 additions & 1 deletion test/Annotation/ReplacePropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class ReplacePropertyTest extends TestCase
{
/**
* Tests replacing a property.
*
* @test
*/
#[Test]
public function replaceProperty(): void
{
$result = $this->getJsonMapper()
Expand Down
2 changes: 1 addition & 1 deletion test/Classes/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Base
/**
* @var string
*/
private string $privateProperty = '';
private $privateProperty = '';

/**
* @return string
Expand Down
2 changes: 1 addition & 1 deletion test/Classes/CustomClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ class CustomClass
*
* or alternatively use Collection<Person>
*/
public array $persons = [];
public $persons = [];
}
13 changes: 7 additions & 6 deletions test/Classes/Initialized.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace MagicSunday\Test\Classes;

use MagicSunday\JsonMapper\Annotation\ReplaceNullWithDefaultValue;
/**
* Class Initialized.
*
Expand All @@ -23,21 +24,21 @@ class Initialized
/**
* @var int
*
* @MagicSunday\JsonMapper\Annotation\ReplaceNullWithDefaultValue
* @ReplaceNullWithDefaultValue
*/
public int $integer = 10;
public $integer = 10;

/**
* @var bool
*
* @MagicSunday\JsonMapper\Annotation\ReplaceNullWithDefaultValue
* @ReplaceNullWithDefaultValue
*/
public bool $bool = false;
public $bool = false;

/**
* @var array<string>
*
* @MagicSunday\JsonMapper\Annotation\ReplaceNullWithDefaultValue
* @ReplaceNullWithDefaultValue
*/
public array $array = [];
public $array = [];
}
2 changes: 1 addition & 1 deletion test/Classes/MultidimensionalArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ class MultidimensionalArray
*
* or alternatively use @var array<array<Person>>
*/
public array $persons;
public $persons;
}
4 changes: 2 additions & 2 deletions test/Classes/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class Person
/**
* @var bool
*/
public bool $is_vip = false;
public $is_vip = false;

/**
* @var string
*/
public string $name;
public $name;
}
2 changes: 1 addition & 1 deletion test/Classes/PlainArrayClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PlainArrayClass
/**
* @var array<int>
*/
public array $values;
public $values;

/**
* @return array<int>
Expand Down
8 changes: 5 additions & 3 deletions test/Classes/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@
class Simple
{
/**
* PHP7.4 typed property.
* PHP7.4 typed property
*
* @var int
*/
public int $id;
public $id;

/**
* PHP7.4 typed property.
*
* @var string
*/
public string $name;
public $name;

/**
* @var int
Expand Down
2 changes: 1 addition & 1 deletion test/Classes/VariadicSetterClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class VariadicSetterClass
/**
* @var int[]
*/
private array $values;
private $values;

/**
* @return int[]
Expand Down
6 changes: 3 additions & 3 deletions test/Classes/VipPerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ class VipPerson extends Person
/**
* @var bool
*/
public bool $is_vip = true;
public $is_vip = true;

/**
* Number of oscars won.
*
* @var int
*/
public int $oscars;
public $oscars;

/**
* @var string
*/
public string $name;
public $name;
}
3 changes: 2 additions & 1 deletion test/Converter/CamelCasePropertyNameConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class CamelCasePropertyNameConverterTest extends TestCase
{
/**
* Tests mapping json properties to camel case.
*
* @test
*/
#[Test]
public function checkCamelCasePropertyNameConverter(): void
{
$converter = new CamelCasePropertyNameConverter();
Expand Down
Loading

0 comments on commit 84563c7

Please sign in to comment.