Skip to content

Commit

Permalink
Upgrade code to be compatible with php ^7.4|^8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jojo1981 committed Sep 6, 2021
1 parent fbbca40 commit 91a148a
Show file tree
Hide file tree
Showing 18 changed files with 433 additions and 303 deletions.
2 changes: 1 addition & 1 deletion .coveralls.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
service_name: travis-ci
repo_token: MgOtISKjZiYfluYLhf9SQZUHQ6YyrisJL
coverage_clover: build/reports/clover.xml
json_path: build/reports/coveralls-upload.json
json_path: build/reports/coveralls-upload.json
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/var
/vendor
composer.lock
phpunit.xml
phpunit.xml
.phpunit.result.cache
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
language: php

env:
- XDEBUG_MODE="coverage"

php:
- '7.1'
- '7.2'
- '7.3'
- '7.4'
- '8.0'

before_script: echo 'xdebug.mode=coverage' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini

before-install:
- composer self-update
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ $factory = (new \Jojo1981\DataResolver\Factory())
$resolverBuilderFactory = $factory->getResolverBuilderFactory();

// and you're ready to go
```
```
25 changes: 18 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,33 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^7.1",
"php": "^7.4|^8.0",
"dg/bypass-finals": "^1.3",
"doctrine/collections": "^1.6",
"jojo1981/data-resolver": "^1.0",
"jojo1981/typed-collection": "^2.0"
},
"require-dev": {
"php-coveralls/php-coveralls": "2.1.x-dev",
"phpunit/phpunit": "^7.5"
"jojo1981/data-resolver": "^1.0|^2.0",
"jojo1981/typed-collection": "^2.0|^3.0"
},
"autoload": {
"psr-4": {
"Jojo1981\\DataResolverHandlers\\": "src/"
}
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.4",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.5",
"roave/security-advisories": "dev-latest"
},
"autoload-dev": {
"psr-4": {
"tests\\Jojo1981\\DataResolverHandlers\\": "tests/"
}
},
"config": {
"bin-dir": "bin",
"sort-packages": true
},
"scripts": {
"test": "bin/phpunit"
}
}
27 changes: 14 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/7.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
colors="true"
bootstrap="./vendor/autoload.php"
bootstrap="tests/bootstrap.php"
>
<php>
<env name="XDEBUG_MODE" value="coverage"/>
</php>

<testsuites>
<testsuite name="Data Resolver Handlers Test Suite">
<directory>./tests</directory>
<testsuite name="Data Resolver Handlers - Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<coverage cacheDirectory="var/cache">
<include>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-clover" target="./build/reports/clover.xml"/>
</logging>
</include>
<report>
<clover outputFile="build/reports/clover.xml"/>
</report>
</coverage>

</phpunit>
19 changes: 11 additions & 8 deletions src/AbstractCollectionSequenceHandler.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of the jojo1981/data-resolver-handlers package
*
Expand All @@ -11,6 +11,9 @@

use Jojo1981\DataResolver\Handler\Exception\HandlerException;
use Jojo1981\DataResolver\Handler\SequenceHandlerInterface;
use Traversable;
use function get_class;
use function sprintf;

/**
* @package Jojo1981\DataResolverHandlers
Expand All @@ -31,9 +34,9 @@ final public function supports($data): bool
/**
* @param mixed $data
* @throws HandlerException
* @return \Traversable
* @return Traversable
*/
final public function getIterator($data): \Traversable
final public function getIterator($data): Traversable
{
if (!$this->supports($data)) {
$this->throwUnsupportedException('getIterator');
Expand Down Expand Up @@ -93,10 +96,10 @@ final public function count($data): int
*/
private function throwUnsupportedException(string $methodName): void
{
throw new HandlerException(\sprintf(
throw new HandlerException(sprintf(
'The `%s` can only handle instances of `%s`. Illegal invocation of method `%s`. You should invoke ' .
'the `%s` method first!',
\get_class($this),
get_class($this),
$this->getSupportedType(),
$methodName,
'supports'
Expand All @@ -110,9 +113,9 @@ abstract protected function getSupportedType(): string;

/**
* @param mixed $data
* @return \Traversable
* @return Traversable
*/
abstract protected function performGetIterator($data): \Traversable;
abstract protected function performGetIterator($data): Traversable;

/**
* @param mixed $data
Expand All @@ -133,4 +136,4 @@ abstract protected function performFlatten($data, callable $callback);
* @return int
*/
abstract protected function performCount($data): int;
}
}
16 changes: 10 additions & 6 deletions src/DoctrineCollectionMergeHandlerDecorator.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of the jojo1981/data-resolver-handlers package
*
Expand All @@ -13,14 +13,18 @@
use Doctrine\Common\Collections\Collection;
use Jojo1981\DataResolver\Handler\MergeHandlerInterface;
use Jojo1981\DataResolver\Resolver\Context;
use function array_push;
use function get_class;
use function gettype;
use function is_object;

/**
* @package Jojo1981\DataResolverHandlers
*/
class DoctrineCollectionMergeHandlerDecorator implements MergeHandlerInterface
final class DoctrineCollectionMergeHandlerDecorator implements MergeHandlerInterface
{
/** @var MergeHandlerInterface */
private $mergeHandler;
private MergeHandlerInterface $mergeHandler;

/**
* @param MergeHandlerInterface $mergeHandler
Expand Down Expand Up @@ -55,7 +59,7 @@ private function mergeCollections(array $collections): ArrayCollection
if ($collection->isEmpty()) {
continue;
}
\array_push($elements, ...$collection->getValues());
array_push($elements, ...$collection->getValues());
}

return new ArrayCollection($elements);
Expand Down Expand Up @@ -92,6 +96,6 @@ private function areAllElementsOfTypeCollectionAndAreAllValuesOfSameType(array $
*/
private function getType($item): string
{
return \is_object($item) ? \get_class($item) : \gettype($item);
return is_object($item) ? get_class($item) : gettype($item);
}
}
}
18 changes: 11 additions & 7 deletions src/DoctrineCollectionSequenceHandler.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of the jojo1981/data-resolver-handlers package
*
Expand All @@ -10,11 +10,15 @@
namespace Jojo1981\DataResolverHandlers;

use Doctrine\Common\Collections\Collection;
use Exception;
use Traversable;
use function array_values;
use function is_array;

/**
* @package Jojo1981\DataResolverHandlers
*/
class DoctrineCollectionSequenceHandler extends AbstractCollectionSequenceHandler
final class DoctrineCollectionSequenceHandler extends AbstractCollectionSequenceHandler
{
/**
* @return string
Expand All @@ -26,10 +30,10 @@ protected function getSupportedType(): string

/**
* @param mixed|Collection $data
* @throws \Exception
* @return \Traversable
* @throws Exception
* @return Traversable
*/
protected function performGetIterator($data): \Traversable
protected function performGetIterator($data): Traversable
{
return $data->getIterator();
}
Expand Down Expand Up @@ -59,7 +63,7 @@ public function performFlatten($data, callable $callback): Collection
if (null === $callbackResult) {
continue;
}
$callbackResult = !\is_array($callbackResult) ? [$callbackResult] : \array_values($callbackResult);
$callbackResult = !is_array($callbackResult) ? [$callbackResult] : array_values($callbackResult);
foreach ($callbackResult as $item) {
$this->addToCollection($result, $item);
}
Expand Down Expand Up @@ -92,4 +96,4 @@ private function addToCollection(Collection $target, $element): void
$target->add($element);
}
}
}
}
15 changes: 9 additions & 6 deletions src/TypedCollectionMergeHandlerDecorator.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of the jojo1981/data-resolver-handlers package
*
Expand All @@ -13,14 +13,16 @@
use Jojo1981\DataResolver\Resolver\Context;
use Jojo1981\TypedCollection\Collection;
use Jojo1981\TypedCollection\Exception\CollectionException;
use RuntimeException;
use function array_shift;

/**
* @package Jojo1981\DataResolverHandlers
*/
class TypedCollectionMergeHandlerDecorator implements MergeHandlerInterface
final class TypedCollectionMergeHandlerDecorator implements MergeHandlerInterface
{
/** @var MergeHandlerInterface */
private $mergeHandler;
private MergeHandlerInterface $mergeHandler;

/**
* @param MergeHandlerInterface $mergeHandler
Expand All @@ -33,8 +35,9 @@ public function __construct(MergeHandlerInterface $mergeHandler)
/**
* @param Context $context
* @param array $elements
* @throws CollectionException
* @return mixed
* @throws RuntimeException
* @throws CollectionException
*/
public function merge(Context $context, array $elements)
{
Expand All @@ -52,7 +55,7 @@ public function merge(Context $context, array $elements)
private function getTypeFromElements(array $elements): string
{
/** @var Collection $element */
$element = \array_shift($elements);
$element = array_shift($elements);

return $element->getType();
}
Expand All @@ -78,4 +81,4 @@ private function areAllElementsOfTypeCollectionAndSameType(array $elements): boo

return true;
}
}
}
Loading

0 comments on commit 91a148a

Please sign in to comment.