From c049bfa05ef6c7b2a5c73328b2bc45cf5bddeb02 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Fri, 10 Dec 2021 08:27:19 +0000 Subject: [PATCH] make version 6.0 PHP 8.1 compatible --- CHANGELOG-6.x.md | 1 + config/set/default.php | 3 +- .../Analyser/AbstractSniffAnalyser.php | 7 +++-- .../Analyser/CompatibilityAnalyser.php | 8 +++--- .../Collection/SniffCollection.php | 9 +++--- .../Collection/SniffCollectionInterface.php | 14 ++++++++++ src/Application/Sniffs/KeywordBag.php | 14 +++++----- .../Sniffs/Keywords/ReservedSniff.php | 28 +++++++++---------- 8 files changed, 51 insertions(+), 33 deletions(-) create mode 100644 src/Application/Collection/SniffCollectionInterface.php diff --git a/CHANGELOG-6.x.md b/CHANGELOG-6.x.md index 3d679ff8..1efce29e 100644 --- a/CHANGELOG-6.x.md +++ b/CHANGELOG-6.x.md @@ -11,6 +11,7 @@ using the [Keep a CHANGELOG](http://keepachangelog.com) principles. - Phar manifest (`--manifest` option) is available with Phar version only (build with `box-project/box` [3.10](https://github.com/box-project/box/releases/tag/3.10.0) or greater) - [Mega-Linter](https://github.com/megalinter/megalinter) v5 support as QA tool to avoid technical debt +- [#308](https://github.com/llaville/php-compatinfo/issues/308) : Support to PHP 8.1 ### Fixed diff --git a/config/set/default.php b/config/set/default.php index 4833ee3e..53453193 100644 --- a/config/set/default.php +++ b/config/set/default.php @@ -3,6 +3,7 @@ use Bartlett\CompatInfo\Application\Collection\ReferenceCollection; use Bartlett\CompatInfo\Application\Collection\ReferenceCollectionInterface; use Bartlett\CompatInfo\Application\Collection\SniffCollection; +use Bartlett\CompatInfo\Application\Collection\SniffCollectionInterface; use Bartlett\CompatInfo\Application\Extension\ExtensionInterface; use Bartlett\CompatInfo\Application\Logger\DefaultLogger; use Bartlett\CompatInfo\Application\Profiler\Profiler; @@ -90,7 +91,7 @@ $services->load('Bartlett\CompatInfo\\', __DIR__ . '/../../src'); // @link https://symfony.com/doc/current/service_container/tags.html#reference-tagged-services - $services->set(SniffCollection::class) + $services->set(SniffCollectionInterface::class, SniffCollection::class) ->arg('$sniffs', tagged_iterator('phpcompatinfo.sniff')) // for unit tests ->public() diff --git a/src/Application/Analyser/AbstractSniffAnalyser.php b/src/Application/Analyser/AbstractSniffAnalyser.php index 4d062e4f..8116ce08 100644 --- a/src/Application/Analyser/AbstractSniffAnalyser.php +++ b/src/Application/Analyser/AbstractSniffAnalyser.php @@ -12,6 +12,7 @@ namespace Bartlett\CompatInfo\Application\Analyser; use Bartlett\CompatInfo\Application\Collection\SniffCollection; +use Bartlett\CompatInfo\Application\Collection\SniffCollectionInterface; use Bartlett\CompatInfo\Application\DataCollector\ErrorHandler; use Bartlett\CompatInfo\Application\Event\AfterProcessNodeEvent; use Bartlett\CompatInfo\Application\Event\AfterTraverseAstEvent; @@ -31,7 +32,7 @@ abstract class AbstractSniffAnalyser implements SniffAnalyserInterface { /** @var EventDispatcherInterface */ private $dispatcher; - /** @var SniffCollection */ + /** @var SniffCollectionInterface */ private $sniffs; /** @var string */ private $attributeParentKey; @@ -44,14 +45,14 @@ abstract class AbstractSniffAnalyser implements SniffAnalyserInterface /** * @param ProfilerInterface $profiler * @param EventDispatcherInterface $dispatcher - * @param SniffCollection $sniffs + * @param SniffCollectionInterface $sniffs * @param string $attributeParentKey * @param string $attributeKey */ public function __construct( ProfilerInterface $profiler, EventDispatcherInterface $dispatcher, - SniffCollection $sniffs, + SniffCollectionInterface $sniffs, string $attributeParentKey, string $attributeKey ) { diff --git a/src/Application/Analyser/CompatibilityAnalyser.php b/src/Application/Analyser/CompatibilityAnalyser.php index 5fe97d67..8adf0aea 100644 --- a/src/Application/Analyser/CompatibilityAnalyser.php +++ b/src/Application/Analyser/CompatibilityAnalyser.php @@ -15,12 +15,12 @@ namespace Bartlett\CompatInfo\Application\Analyser; use Bartlett\CompatInfo\Application\Collection\ReferenceCollectionInterface; -use Bartlett\CompatInfo\Application\Collection\SniffCollection; +use Bartlett\CompatInfo\Application\Collection\SniffCollectionInterface; use Bartlett\CompatInfo\Application\DataCollector\VersionDataCollector; use Bartlett\CompatInfo\Application\DataCollector\VersionUpdater; use Bartlett\CompatInfo\Application\Profiler\ProfilerInterface; -use Bartlett\CompatInfo\Application\Sniffs\SniffInterface; +use Bartlett\CompatInfo\Application\Sniffs\SniffInterface; use PhpParser\Node; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -64,13 +64,13 @@ final class CompatibilityAnalyser extends AbstractSniffAnalyser * Initializes the compatibility analyser * * @param ProfilerInterface $profiler - * @param SniffCollection $sniffCollection + * @param SniffCollectionInterface $sniffCollection * @param ReferenceCollectionInterface $referenceCollection * @param EventDispatcherInterface $compatibilityEventDispatcher */ public function __construct( ProfilerInterface $profiler, - SniffCollection $sniffCollection, + SniffCollectionInterface $sniffCollection, ReferenceCollectionInterface $referenceCollection, EventDispatcherInterface $compatibilityEventDispatcher ) { diff --git a/src/Application/Collection/SniffCollection.php b/src/Application/Collection/SniffCollection.php index 57e567e8..567d4b6b 100644 --- a/src/Application/Collection/SniffCollection.php +++ b/src/Application/Collection/SniffCollection.php @@ -6,15 +6,16 @@ namespace Bartlett\CompatInfo\Application\Collection; -use IteratorAggregate; +use Bartlett\CompatInfo\Application\Sniffs\SniffInterface; + use Traversable; /** * @phpstan-template T of \Bartlett\CompatInfo\Application\Sniffs\SniffInterface - * @phpstan-implements IteratorAggregate + * @phpstan-implements SniffCollectionInterface * @since Release 5.4.0 */ -class SniffCollection implements IteratorAggregate +class SniffCollection implements SniffCollectionInterface { /** @var Traversable */ protected $sniffs; @@ -32,7 +33,7 @@ public function __construct(iterable $sniffs) /** * {@inheritDoc} */ - public function getIterator() + public function getIterator(): Traversable { return $this->sniffs; } diff --git a/src/Application/Collection/SniffCollectionInterface.php b/src/Application/Collection/SniffCollectionInterface.php new file mode 100644 index 00000000..611ac43d --- /dev/null +++ b/src/Application/Collection/SniffCollectionInterface.php @@ -0,0 +1,14 @@ + + * @since Release 6.0.0 + */ +interface SniffCollectionInterface extends IteratorAggregate +{ +} diff --git a/src/Application/Sniffs/KeywordBag.php b/src/Application/Sniffs/KeywordBag.php index 2195bd1c..68d1c4fc 100644 --- a/src/Application/Sniffs/KeywordBag.php +++ b/src/Application/Sniffs/KeywordBag.php @@ -5,7 +5,7 @@ use ArrayIterator; use Countable; use IteratorAggregate; - +use Traversable; use function array_key_exists; use function array_merge; use function substr_count; @@ -17,13 +17,13 @@ final class KeywordBag implements IteratorAggregate, Countable { /** * Keyword storage - * @var string[] + * @var array */ private $keywords; /** * KeywordBag constructor. - * @param string[] $keywords + * @param array $keywords */ public function __construct(array $keywords = []) { @@ -33,7 +33,7 @@ public function __construct(array $keywords = []) /** * {@inheritDoc} */ - public function getIterator() + public function getIterator(): Traversable { return new ArrayIterator($this->keywords); } @@ -41,13 +41,13 @@ public function getIterator() /** * {@inheritDoc} */ - public function count() + public function count(): int { return count($this->keywords); } /** - * @return string[] + * @return array */ public function all(): array { @@ -55,7 +55,7 @@ public function all(): array } /** - * @param string[] $keywords + * @param array $keywords */ public function add(array $keywords = []): void { diff --git a/src/Application/Sniffs/Keywords/ReservedSniff.php b/src/Application/Sniffs/Keywords/ReservedSniff.php index 8c1a13c0..8e40f2a7 100644 --- a/src/Application/Sniffs/Keywords/ReservedSniff.php +++ b/src/Application/Sniffs/Keywords/ReservedSniff.php @@ -32,21 +32,21 @@ public function enterSniff(): void /** * The following words cannot be used to name a class, interface or trait, * and they are also prohibited from being used in namespaces. + * @var array */ - $this->forbiddenNames = new KeywordBag( - [ - 'bool' => '7.0', - 'int' => '7.0', - 'float' => '7.0', - 'string' => '7.0', - 'null' => '7.0', - 'true' => '7.0', - 'false' => '7.0', - 'void', '7.1', - 'iterable' => '7.1', - 'object' => '7.2', - ] - ); + $forbiddenNames = [ + 'bool' => '7.0', + 'int' => '7.0', + 'float' => '7.0', + 'string' => '7.0', + 'null' => '7.0', + 'true' => '7.0', + 'false' => '7.0', + 'void', '7.1', + 'iterable' => '7.1', + 'object' => '7.2', + ]; + $this->forbiddenNames = new KeywordBag($forbiddenNames); /** * Furthermore, the following names should not be used.