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 4c70c34
Show file tree
Hide file tree
Showing 31 changed files with 153 additions and 113 deletions.
6 changes: 3 additions & 3 deletions .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 All @@ -23,7 +23,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2, php-cs-fixer
tools: composer:v2

- name: Validate composer.json and composer.lock
run: composer validate
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
name: CGL
if: ${{ always() && steps.install.conclusion == 'success' }}
run: |
php-cs-fixer fix --dry-run --verbose
composer ci:cgl -- --dry-run
- id: phpstan
name: PHPStan
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ composer.lock

# Cache
.php-cs-fixer.cache
.php_cs.cache
.phplint.cache
.phpunit.result.cache
.phpunit.cache
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
24 changes: 12 additions & 12 deletions src/JsonMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@

namespace MagicSunday;

use function array_key_exists;
use Closure;
use Doctrine\Common\Annotations\Annotation;
use Doctrine\Common\Annotations\AnnotationReader;
use DomainException;
use function in_array;
use InvalidArgumentException;
use function is_array;
use MagicSunday\JsonMapper\Annotation\ReplaceNullWithDefaultValue;
use MagicSunday\JsonMapper\Annotation\ReplaceProperty;
use MagicSunday\JsonMapper\Converter\PropertyNameConverterInterface;
Expand All @@ -27,15 +30,12 @@
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
use Symfony\Component\PropertyInfo\Type;

use function array_key_exists;
use function in_array;
use function is_array;

/**
* JsonMapper.
*
* @author Rico Sonntag <[email protected]>
* @license https://opensource.org/licenses/MIT
*
* @link https://github.com/magicsunday/jsonmapper/
*
* @template TEntity
Expand All @@ -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
3 changes: 2 additions & 1 deletion src/JsonMapper/Converter/CamelCasePropertyNameConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
*
* @author Rico Sonntag <[email protected]>
* @license https://opensource.org/licenses/MIT
*
* @link https://github.com/magicsunday/jsonmapper/
*/
class CamelCasePropertyNameConverter implements PropertyNameConverterInterface
{
/**
* @var Inflector
*/
private Inflector $inflector;
private $inflector;

/**
* CamelCasePropertyNameConverter constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*
* @author Rico Sonntag <[email protected]>
* @license https://opensource.org/licenses/MIT
*
* @link https://github.com/magicsunday/jsonmapper/
*/
interface PropertyNameConverterInterface
Expand Down
4 changes: 3 additions & 1 deletion test/Annotation/ReplacePropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
*
* @author Rico Sonntag <[email protected]>
* @license https://opensource.org/licenses/MIT
*
* @link https://github.com/magicsunday/jsonmapper/
*/
class ReplacePropertyTest extends TestCase
{
/**
* Tests replacing a property.
*
* @test
*/
#[Test]
public function replaceProperty(): void
{
$result = $this->getJsonMapper()
Expand Down
3 changes: 2 additions & 1 deletion test/Classes/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*
* @author Rico Sonntag <[email protected]>
* @license https://opensource.org/licenses/MIT
*
* @link https://github.com/magicsunday/jsonmapper/
*/
class Base
Expand Down Expand Up @@ -61,7 +62,7 @@ class Base
/**
* @var string
*/
private string $privateProperty = '';
private $privateProperty = '';

/**
* @return string
Expand Down
1 change: 1 addition & 0 deletions test/Classes/ClassMap/CollectionSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*
* @author Rico Sonntag <[email protected]>
* @license https://opensource.org/licenses/MIT
*
* @link https://github.com/magicsunday/jsonmapper/
*/
class CollectionSource extends Collection
Expand Down
1 change: 1 addition & 0 deletions test/Classes/ClassMap/CollectionTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*
* @author Rico Sonntag <[email protected]>
* @license https://opensource.org/licenses/MIT
*
* @link https://github.com/magicsunday/jsonmapper/
*/
class CollectionTarget extends ArrayObject
Expand Down
1 change: 1 addition & 0 deletions test/Classes/ClassMap/SourceItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*
* @author Rico Sonntag <[email protected]>
* @license https://opensource.org/licenses/MIT
*
* @link https://github.com/magicsunday/jsonmapper/
*/
class SourceItem
Expand Down
1 change: 1 addition & 0 deletions test/Classes/ClassMap/TargetItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*
* @author Rico Sonntag <[email protected]>
* @license https://opensource.org/licenses/MIT
*
* @link https://github.com/magicsunday/jsonmapper/
*/
class TargetItem
Expand Down
1 change: 1 addition & 0 deletions test/Classes/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*
* @author Rico Sonntag <[email protected]>
* @license https://opensource.org/licenses/MIT
*
* @link https://github.com/magicsunday/jsonmapper/
*
* @template TKey of array-key
Expand Down
3 changes: 2 additions & 1 deletion test/Classes/CustomClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*
* @author Rico Sonntag <[email protected]>
* @license https://opensource.org/licenses/MIT
*
* @link https://github.com/magicsunday/jsonmapper/
*/
class CustomClass
Expand All @@ -25,5 +26,5 @@ class CustomClass
*
* or alternatively use Collection<Person>
*/
public array $persons = [];
public $persons = [];
}
1 change: 1 addition & 0 deletions test/Classes/CustomConstructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*
* @author Rico Sonntag <[email protected]>
* @license https://opensource.org/licenses/MIT
*
* @link https://github.com/magicsunday/jsonmapper/
*/
class CustomConstructor
Expand Down
Loading

0 comments on commit 4c70c34

Please sign in to comment.