diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 5f8d259a..62bdb6d6 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -6,7 +6,7 @@ on: jobs: check: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: Checkout uses: actions/checkout@v3 @@ -15,7 +15,7 @@ jobs: - name: Validate composer.json run: composer validate --strict --no-check-lock cs-fixer: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 name: PHP-CS-Fixer steps: - name: Checkout @@ -23,13 +23,11 @@ jobs: - name: Fix CS uses: docker://oskarstark/php-cs-fixer-ga tests: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: include: - - description: 'No Symfony specified' - php: '7.4' - description: 'No Symfony specified' php: '8.0' - description: 'No Symfony specified' @@ -37,21 +35,15 @@ jobs: - description: 'No Symfony specified' php: '8.2' - description: 'Lowest deps' - php: '7.4' + php: '8.0' composer_option: '--prefer-lowest' env: SYMFONY_DEPRECATIONS_HELPER: max[self]=0 - - description: 'Symfony 4.4' - php: '7.4' - symfony: 4.4.* - description: 'Symfony 5.4' - php: '7.4' - symfony: 5.4.* - - description: 'Symfony 6.0' php: '8.0' - symfony: 6.0.* + symfony: 5.4.* - description: 'Dev deps' - php: '8.1' + php: '8.2' dev: true name: PHP ${{ matrix.php }} tests (${{ matrix.description }}) steps: @@ -74,7 +66,7 @@ jobs: - run: composer update --no-interaction --no-progress --ansi ${{ matrix.composer_option }} - run: vendor/bin/phpunit phpstan: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 name: PHPStan steps: - name: Checkout diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 30e1e3ce..7a91c754 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -10,8 +10,8 @@ ->setRules([ '@Symfony' => true, '@Symfony:risky' => true, - '@PHP71Migration:risky' => true, - '@PHPUnit75Migration:risky' => true, + '@PHP80Migration:risky' => true, + '@PHPUnit84Migration:risky' => true, 'ordered_imports' => true, 'declare_strict_types' => false, 'native_function_invocation' => ['include' => ['@internal']], diff --git a/CHANGELOG.md b/CHANGELOG.md index 01664564..e2eb7a27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.4 (2023-xx-xx) + +* Removed support for unsupported PHP version 7.4 + ## 3.2 (2021-05-28) * Remove Symfony 6 deprecations diff --git a/composer.json b/composer.json index e2e7a497..357b1298 100644 --- a/composer.json +++ b/composer.json @@ -20,19 +20,19 @@ } ], "require": { - "php": "^7.4 || ^8.0" + "php": "^8.0" }, "conflict": { "twig/twig": "<1.42.3 || >=2,<2.9" }, "require-dev": { - "phpstan/phpstan": "^1.8", - "phpunit/phpunit": "^9.5", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^9.6", "psr/container": "^1.0", - "symfony/http-foundation": "^4.4 || ^5.0 || ^6.0", - "symfony/phpunit-bridge": "^6.1", - "symfony/routing": "^4.4 || ^5.0 || ^6.0", - "twig/twig": "^1.42.3 || ^2.9 || ^3.0" + "symfony/http-foundation": "^5.4 || ^6.0", + "symfony/phpunit-bridge": "^6.2", + "symfony/routing": "^5.4 || ^6.0", + "twig/twig": "^2.9 || ^3.0" }, "suggest": { "twig/twig": "for the TwigRenderer and the integration with your templates" diff --git a/src/Knp/Menu/Integration/Symfony/RoutingExtension.php b/src/Knp/Menu/Integration/Symfony/RoutingExtension.php index 7f191916..dc01e277 100644 --- a/src/Knp/Menu/Integration/Symfony/RoutingExtension.php +++ b/src/Knp/Menu/Integration/Symfony/RoutingExtension.php @@ -11,11 +11,8 @@ */ class RoutingExtension implements ExtensionInterface { - private UrlGeneratorInterface $generator; - - public function __construct(UrlGeneratorInterface $generator) + public function __construct(private UrlGeneratorInterface $generator) { - $this->generator = $generator; } public function buildOptions(array $options = []): array diff --git a/src/Knp/Menu/Iterator/CurrentItemFilterIterator.php b/src/Knp/Menu/Iterator/CurrentItemFilterIterator.php index 4baab03f..cf993172 100644 --- a/src/Knp/Menu/Iterator/CurrentItemFilterIterator.php +++ b/src/Knp/Menu/Iterator/CurrentItemFilterIterator.php @@ -9,14 +9,11 @@ */ class CurrentItemFilterIterator extends \FilterIterator { - private MatcherInterface $matcher; - /** * @param \Iterator $iterator */ - public function __construct(\Iterator $iterator, MatcherInterface $matcher) + public function __construct(\Iterator $iterator, private MatcherInterface $matcher) { - $this->matcher = $matcher; parent::__construct($iterator); } diff --git a/src/Knp/Menu/Iterator/RecursiveItemIterator.php b/src/Knp/Menu/Iterator/RecursiveItemIterator.php index a1f9c002..5284690f 100644 --- a/src/Knp/Menu/Iterator/RecursiveItemIterator.php +++ b/src/Knp/Menu/Iterator/RecursiveItemIterator.php @@ -6,6 +6,7 @@ * Recursive iterator iterating on an item * * @extends \IteratorIterator> + * * @implements \RecursiveIterator> */ class RecursiveItemIterator extends \IteratorIterator implements \RecursiveIterator diff --git a/src/Knp/Menu/Loader/ArrayLoader.php b/src/Knp/Menu/Loader/ArrayLoader.php index 9ce3117b..2ccf2275 100644 --- a/src/Knp/Menu/Loader/ArrayLoader.php +++ b/src/Knp/Menu/Loader/ArrayLoader.php @@ -12,17 +12,14 @@ */ class ArrayLoader implements LoaderInterface { - private FactoryInterface $factory; - - public function __construct(FactoryInterface $factory) + public function __construct(private FactoryInterface $factory) { - $this->factory = $factory; } public function load($data): ItemInterface { if (!$this->supports($data)) { - throw new \InvalidArgumentException(\sprintf('Unsupported data. Expected an array but got %s', \is_object($data) ? \get_class($data) : \gettype($data))); + throw new \InvalidArgumentException(\sprintf('Unsupported data. Expected an array but got %s', \get_debug_type($data))); } return $this->fromArray($data); diff --git a/src/Knp/Menu/Loader/NodeLoader.php b/src/Knp/Menu/Loader/NodeLoader.php index 2a3f5107..84c23797 100644 --- a/src/Knp/Menu/Loader/NodeLoader.php +++ b/src/Knp/Menu/Loader/NodeLoader.php @@ -8,17 +8,14 @@ class NodeLoader implements LoaderInterface { - private FactoryInterface $factory; - - public function __construct(FactoryInterface $factory) + public function __construct(private FactoryInterface $factory) { - $this->factory = $factory; } public function load($data): ItemInterface { if (!$data instanceof NodeInterface) { - throw new \InvalidArgumentException(\sprintf('Unsupported data. Expected Knp\Menu\NodeInterface but got %s', \is_object($data) ? \get_class($data) : \gettype($data))); + throw new \InvalidArgumentException(\sprintf('Unsupported data. Expected Knp\Menu\NodeInterface but got %s', \get_debug_type($data))); } $item = $this->factory->createItem($data->getName(), $data->getOptions()); diff --git a/src/Knp/Menu/Matcher/Voter/RegexVoter.php b/src/Knp/Menu/Matcher/Voter/RegexVoter.php index 4c8d2cd2..801c3758 100644 --- a/src/Knp/Menu/Matcher/Voter/RegexVoter.php +++ b/src/Knp/Menu/Matcher/Voter/RegexVoter.php @@ -10,11 +10,8 @@ */ class RegexVoter implements VoterInterface { - private ?string $regexp; - - public function __construct(?string $regexp) + public function __construct(private ?string $regexp) { - $this->regexp = $regexp; } public function matchItem(ItemInterface $item): ?bool diff --git a/src/Knp/Menu/Matcher/Voter/RouteVoter.php b/src/Knp/Menu/Matcher/Voter/RouteVoter.php index 99046f76..6678e5ad 100644 --- a/src/Knp/Menu/Matcher/Voter/RouteVoter.php +++ b/src/Knp/Menu/Matcher/Voter/RouteVoter.php @@ -11,11 +11,8 @@ */ class RouteVoter implements VoterInterface { - private RequestStack $requestStack; - - public function __construct(RequestStack $requestStack) + public function __construct(private RequestStack $requestStack) { - $this->requestStack = $requestStack; } public function matchItem(ItemInterface $item): ?bool @@ -110,7 +107,7 @@ private function isMatchingQueryParameters(Request $request, array $testedRoute) foreach ($testedRoute['query_parameters'] as $name => $value) { // cast both to string so that we handle integer and other non-string parameters, but don't stumble on 0 == 'abc'. - if (!isset($routeQueryParameters[$name]) || is_array($routeQueryParameters[$name]) || (string) $routeQueryParameters[$name] !== (string) $value) { + if (!isset($routeQueryParameters[$name]) || \is_array($routeQueryParameters[$name]) || (string) $routeQueryParameters[$name] !== (string) $value) { return false; } } diff --git a/src/Knp/Menu/Matcher/Voter/UriVoter.php b/src/Knp/Menu/Matcher/Voter/UriVoter.php index 395ca461..617f5f05 100644 --- a/src/Knp/Menu/Matcher/Voter/UriVoter.php +++ b/src/Knp/Menu/Matcher/Voter/UriVoter.php @@ -9,11 +9,8 @@ */ class UriVoter implements VoterInterface { - private ?string $uri; - - public function __construct(?string $uri = null) + public function __construct(private ?string $uri = null) { - $this->uri = $uri; } public function matchItem(ItemInterface $item): ?bool diff --git a/src/Knp/Menu/Provider/ArrayAccessProvider.php b/src/Knp/Menu/Provider/ArrayAccessProvider.php index 7376945d..79b4c7d8 100644 --- a/src/Knp/Menu/Provider/ArrayAccessProvider.php +++ b/src/Knp/Menu/Provider/ArrayAccessProvider.php @@ -13,24 +13,12 @@ */ class ArrayAccessProvider implements MenuProviderInterface { - /** - * @var \ArrayAccess - */ - private \ArrayAccess $registry; - - /** - * @var array - */ - private array $menuIds; - /** * @param \ArrayAccess $registry * @param array $menuIds The map between menu identifiers and registry keys */ - public function __construct(\ArrayAccess $registry, array $menuIds = []) + public function __construct(private \ArrayAccess $registry, private array $menuIds = []) { - $this->registry = $registry; - $this->menuIds = $menuIds; } public function get(string $name, array $options = []): ItemInterface diff --git a/src/Knp/Menu/Provider/LazyProvider.php b/src/Knp/Menu/Provider/LazyProvider.php index 07c8f53d..c42e3370 100644 --- a/src/Knp/Menu/Provider/LazyProvider.php +++ b/src/Knp/Menu/Provider/LazyProvider.php @@ -13,17 +13,11 @@ */ class LazyProvider implements MenuProviderInterface { - /** - * @var array - */ - private array $builders; - /** * @phpstan-param array $builders */ - public function __construct(array $builders) + public function __construct(private array $builders) { - $this->builders = $builders; } public function get(string $name, array $options = []): ItemInterface diff --git a/src/Knp/Menu/Provider/PsrProvider.php b/src/Knp/Menu/Provider/PsrProvider.php index 9e116161..014587d2 100644 --- a/src/Knp/Menu/Provider/PsrProvider.php +++ b/src/Knp/Menu/Provider/PsrProvider.php @@ -13,11 +13,8 @@ */ class PsrProvider implements MenuProviderInterface { - private ContainerInterface $container; - - public function __construct(ContainerInterface $container) + public function __construct(private ContainerInterface $container) { - $this->container = $container; } public function get(string $name, array $options = []): ItemInterface diff --git a/src/Knp/Menu/Renderer/ArrayAccessProvider.php b/src/Knp/Menu/Renderer/ArrayAccessProvider.php index bc5d1e4d..47bccac0 100644 --- a/src/Knp/Menu/Renderer/ArrayAccessProvider.php +++ b/src/Knp/Menu/Renderer/ArrayAccessProvider.php @@ -7,28 +7,13 @@ */ class ArrayAccessProvider implements RendererProviderInterface { - /** - * @var \ArrayAccess - */ - private \ArrayAccess $registry; - - /** - * @var array - */ - private array $rendererIds; - - private string $defaultRenderer; - /** * @param \ArrayAccess $registry * @param string $defaultRenderer The name of the renderer used by default * @param array $rendererIds The map between renderer names and registry keys */ - public function __construct(\ArrayAccess $registry, string $defaultRenderer, array $rendererIds) + public function __construct(private \ArrayAccess $registry, private string $defaultRenderer, private array $rendererIds) { - $this->registry = $registry; - $this->rendererIds = $rendererIds; - $this->defaultRenderer = $defaultRenderer; } public function get(?string $name = null): RendererInterface diff --git a/src/Knp/Menu/Renderer/ListRenderer.php b/src/Knp/Menu/Renderer/ListRenderer.php index 36068f84..b68345f7 100644 --- a/src/Knp/Menu/Renderer/ListRenderer.php +++ b/src/Knp/Menu/Renderer/ListRenderer.php @@ -10,22 +10,11 @@ */ class ListRenderer extends Renderer implements RendererInterface { - /** - * @var MatcherInterface - */ - protected $matcher; - - /** - * @var array - */ - protected $defaultOptions; - /** * @param array $defaultOptions */ - public function __construct(MatcherInterface $matcher, array $defaultOptions = [], ?string $charset = null) + public function __construct(protected MatcherInterface $matcher, protected array $defaultOptions = [], ?string $charset = null) { - $this->matcher = $matcher; $this->defaultOptions = \array_merge([ 'depth' => null, 'matchingDepth' => null, @@ -158,7 +147,7 @@ protected function renderItem(ItemInterface $item, array $options): string $html = $this->format('renderHtmlAttributes($attributes).'>', 'li', $item->getLevel(), $options); // render the text/link inside the li tag - //$html .= $this->format($item->getUri() ? $item->renderLink() : $item->renderLabel(), 'link', $item->getLevel()); + // $html .= $this->format($item->getUri() ? $item->renderLink() : $item->renderLabel(), 'link', $item->getLevel()); $html .= $this->renderLink($item, $options); // renders the embedded ul diff --git a/src/Knp/Menu/Renderer/PsrProvider.php b/src/Knp/Menu/Renderer/PsrProvider.php index ff865e6f..89830ea5 100644 --- a/src/Knp/Menu/Renderer/PsrProvider.php +++ b/src/Knp/Menu/Renderer/PsrProvider.php @@ -12,17 +12,11 @@ */ class PsrProvider implements RendererProviderInterface { - private ContainerInterface $container; - - private string $defaultRenderer; - /** * @param string $defaultRenderer id of the default renderer (it should exist in the container to avoid weird failures) */ - public function __construct(ContainerInterface $container, string $defaultRenderer) + public function __construct(private ContainerInterface $container, private string $defaultRenderer) { - $this->container = $container; - $this->defaultRenderer = $defaultRenderer; } public function get(?string $name = null): RendererInterface diff --git a/src/Knp/Menu/Renderer/Renderer.php b/src/Knp/Menu/Renderer/Renderer.php index e9f6c301..52b6b74b 100644 --- a/src/Knp/Menu/Renderer/Renderer.php +++ b/src/Knp/Menu/Renderer/Renderer.php @@ -4,10 +4,7 @@ abstract class Renderer { - /** - * @var string - */ - protected $charset = 'UTF-8'; + protected string $charset = 'UTF-8'; public function __construct(?string $charset = null) { diff --git a/src/Knp/Menu/Renderer/TwigRenderer.php b/src/Knp/Menu/Renderer/TwigRenderer.php index ecdc7658..99e4e6b1 100644 --- a/src/Knp/Menu/Renderer/TwigRenderer.php +++ b/src/Knp/Menu/Renderer/TwigRenderer.php @@ -8,26 +8,15 @@ class TwigRenderer implements RendererInterface { - private Environment $environment; - - private MatcherInterface $matcher; - - /** - * @var array - */ - private array $defaultOptions; - /** * @param array $defaultOptions */ public function __construct( - Environment $environment, + private Environment $environment, string $template, - MatcherInterface $matcher, - array $defaultOptions = [] + private MatcherInterface $matcher, + private array $defaultOptions = [] ) { - $this->environment = $environment; - $this->matcher = $matcher; $this->defaultOptions = \array_merge([ 'depth' => null, 'matchingDepth' => null, diff --git a/src/Knp/Menu/Twig/Helper.php b/src/Knp/Menu/Twig/Helper.php index a4f6876f..5ecb9620 100644 --- a/src/Knp/Menu/Twig/Helper.php +++ b/src/Knp/Menu/Twig/Helper.php @@ -13,24 +13,12 @@ */ class Helper { - private RendererProviderInterface $rendererProvider; - - private ?MenuProviderInterface $menuProvider; - - private ?MenuManipulator $menuManipulator; - - private ?MatcherInterface $matcher; - public function __construct( - RendererProviderInterface $rendererProvider, - ?MenuProviderInterface $menuProvider = null, - ?MenuManipulator $menuManipulator = null, - ?MatcherInterface $matcher = null + private RendererProviderInterface $rendererProvider, + private ?MenuProviderInterface $menuProvider = null, + private ?MenuManipulator $menuManipulator = null, + private ?MatcherInterface $matcher = null ) { - $this->rendererProvider = $rendererProvider; - $this->menuProvider = $menuProvider; - $this->menuManipulator = $menuManipulator; - $this->matcher = $matcher; } /** @@ -106,9 +94,11 @@ public function render($menu, array $options = [], ?string $renderer = null): st * * @param mixed $menu * @param mixed $subItem A string or array to append onto the end of the array + * * @phpstan-param string|ItemInterface|array|\Traversable $subItem * * @return array> + * * @phpstan-return list */ public function getBreadcrumbsArray($menu, $subItem = null): array diff --git a/src/Knp/Menu/Twig/MenuExtension.php b/src/Knp/Menu/Twig/MenuExtension.php index 7df1c4b3..25d2c590 100644 --- a/src/Knp/Menu/Twig/MenuExtension.php +++ b/src/Knp/Menu/Twig/MenuExtension.php @@ -12,17 +12,8 @@ class MenuExtension extends AbstractExtension { - private Helper $helper; - - private ?MatcherInterface $matcher; - - private ?MenuManipulator $menuManipulator; - - public function __construct(Helper $helper, ?MatcherInterface $matcher = null, ?MenuManipulator $menuManipulator = null) + public function __construct(private Helper $helper, private ?MatcherInterface $matcher = null, private ?MenuManipulator $menuManipulator = null) { - $this->helper = $helper; - $this->matcher = $matcher; - $this->menuManipulator = $menuManipulator; } /** @@ -87,6 +78,7 @@ public function render($menu, array $options = [], ?string $renderer = null): st * * @param ItemInterface|string|array $menu * @param string|array|null $subItem + * * @phpstan-param string|ItemInterface|array|\Traversable $subItem * * @return array> diff --git a/src/Knp/Menu/Util/MenuManipulator.php b/src/Knp/Menu/Util/MenuManipulator.php index c5066801..5abb0d22 100644 --- a/src/Knp/Menu/Util/MenuManipulator.php +++ b/src/Knp/Menu/Util/MenuManipulator.php @@ -207,6 +207,7 @@ public function toArray(ItemInterface $item, ?int $depth = null): array * * [['label' => 'subItem1', 'url' => '@homepage'], ['label' => 'subItem2']] * * @param string|ItemInterface|array|\Traversable $subItem A string or array to append onto the end of the array + * * @phpstan-param string|ItemInterface|array|\Traversable $subItem * * @return array> diff --git a/tests/Knp/Menu/Tests/Loader/ArrayLoaderTest.php b/tests/Knp/Menu/Tests/Loader/ArrayLoaderTest.php index 92db6818..20fefdc9 100644 --- a/tests/Knp/Menu/Tests/Loader/ArrayLoaderTest.php +++ b/tests/Knp/Menu/Tests/Loader/ArrayLoaderTest.php @@ -84,11 +84,9 @@ public function testLoadInvalidData(): void } /** - * @param mixed $data - * * @dataProvider provideSupportingData */ - public function testSupports($data, bool $expected): void + public function testSupports(mixed $data, bool $expected): void { $loader = new ArrayLoader(new MenuFactory()); diff --git a/tests/Knp/Menu/Tests/MenuTestCase.php b/tests/Knp/Menu/Tests/MenuTestCase.php index 1ce52c52..50b0af59 100644 --- a/tests/Knp/Menu/Tests/MenuTestCase.php +++ b/tests/Knp/Menu/Tests/MenuTestCase.php @@ -9,45 +9,21 @@ abstract class MenuTestCase extends TestCase { - /** - * @var ItemInterface|null - */ - protected $menu; + protected ItemInterface|null $menu; - /** - * @var ItemInterface|null - */ - protected $pt1; + protected ItemInterface|null $pt1; - /** - * @var ItemInterface|null - */ - protected $ch1; + protected ItemInterface|null $ch1; - /** - * @var ItemInterface|null - */ - protected $ch2; + protected ItemInterface|null $ch2; - /** - * @var ItemInterface|null - */ - protected $ch3; + protected ItemInterface|null $ch3; - /** - * @var ItemInterface|null - */ - protected $pt2; + protected ItemInterface|null $pt2; - /** - * @var ItemInterface|null - */ - protected $ch4; + protected ItemInterface|null $ch4; - /** - * @var ItemInterface|null - */ - protected $gc1; + protected ItemInterface|null $gc1; protected function setUp(): void { diff --git a/tests/Knp/Menu/Tests/Renderer/AbstractRendererTest.php b/tests/Knp/Menu/Tests/Renderer/AbstractRendererTest.php index f936d627..e568c2be 100644 --- a/tests/Knp/Menu/Tests/Renderer/AbstractRendererTest.php +++ b/tests/Knp/Menu/Tests/Renderer/AbstractRendererTest.php @@ -12,10 +12,7 @@ abstract class AbstractRendererTest extends MenuTestCase { - /** - * @var RendererInterface|null - */ - protected $renderer; + protected RendererInterface|null $renderer; protected function setUp(): void {