Skip to content

Commit

Permalink
make version 6.0 PHP 8.1 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
llaville committed Dec 10, 2021
1 parent c2a6002 commit c049bfa
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-6.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion config/set/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions src/Application/Analyser/AbstractSniffAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +32,7 @@ abstract class AbstractSniffAnalyser implements SniffAnalyserInterface
{
/** @var EventDispatcherInterface */
private $dispatcher;
/** @var SniffCollection<SniffInterface> */
/** @var SniffCollectionInterface<SniffInterface> */
private $sniffs;
/** @var string */
private $attributeParentKey;
Expand All @@ -44,14 +45,14 @@ abstract class AbstractSniffAnalyser implements SniffAnalyserInterface
/**
* @param ProfilerInterface $profiler
* @param EventDispatcherInterface $dispatcher
* @param SniffCollection<SniffInterface> $sniffs
* @param SniffCollectionInterface<SniffInterface> $sniffs
* @param string $attributeParentKey
* @param string $attributeKey
*/
public function __construct(
ProfilerInterface $profiler,
EventDispatcherInterface $dispatcher,
SniffCollection $sniffs,
SniffCollectionInterface $sniffs,
string $attributeParentKey,
string $attributeKey
) {
Expand Down
8 changes: 4 additions & 4 deletions src/Application/Analyser/CompatibilityAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,13 +64,13 @@ final class CompatibilityAnalyser extends AbstractSniffAnalyser
* Initializes the compatibility analyser
*
* @param ProfilerInterface $profiler
* @param SniffCollection<SniffInterface> $sniffCollection
* @param SniffCollectionInterface<SniffInterface> $sniffCollection
* @param ReferenceCollectionInterface<array> $referenceCollection
* @param EventDispatcherInterface $compatibilityEventDispatcher
*/
public function __construct(
ProfilerInterface $profiler,
SniffCollection $sniffCollection,
SniffCollectionInterface $sniffCollection,
ReferenceCollectionInterface $referenceCollection,
EventDispatcherInterface $compatibilityEventDispatcher
) {
Expand Down
9 changes: 5 additions & 4 deletions src/Application/Collection/SniffCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>
* @phpstan-implements SniffCollectionInterface<T>
* @since Release 5.4.0
*/
class SniffCollection implements IteratorAggregate
class SniffCollection implements SniffCollectionInterface
{
/** @var Traversable<T> */
protected $sniffs;
Expand All @@ -32,7 +33,7 @@ public function __construct(iterable $sniffs)
/**
* {@inheritDoc}
*/
public function getIterator()
public function getIterator(): Traversable
{
return $this->sniffs;
}
Expand Down
14 changes: 14 additions & 0 deletions src/Application/Collection/SniffCollectionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php declare(strict_types=1);

namespace Bartlett\CompatInfo\Application\Collection;

use IteratorAggregate;

/**
* @phpstan-template T of \Bartlett\CompatInfo\Application\Sniffs\SniffInterface
* @phpstan-extends IteratorAggregate<T>
* @since Release 6.0.0
*/
interface SniffCollectionInterface extends IteratorAggregate
{
}
14 changes: 7 additions & 7 deletions src/Application/Sniffs/KeywordBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,13 +17,13 @@ final class KeywordBag implements IteratorAggregate, Countable
{
/**
* Keyword storage
* @var string[]
* @var array<string, string>
*/
private $keywords;

/**
* KeywordBag constructor.
* @param string[] $keywords
* @param array<string, string> $keywords
*/
public function __construct(array $keywords = [])
{
Expand All @@ -33,29 +33,29 @@ public function __construct(array $keywords = [])
/**
* {@inheritDoc}
*/
public function getIterator()
public function getIterator(): Traversable
{
return new ArrayIterator($this->keywords);
}

/**
* {@inheritDoc}
*/
public function count()
public function count(): int
{
return count($this->keywords);
}

/**
* @return string[]
* @return array<string, string>
*/
public function all(): array
{
return $this->keywords;
}

/**
* @param string[] $keywords
* @param array<string, string> $keywords
*/
public function add(array $keywords = []): void
{
Expand Down
28 changes: 14 additions & 14 deletions src/Application/Sniffs/Keywords/ReservedSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>
*/
$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.
Expand Down

0 comments on commit c049bfa

Please sign in to comment.