Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
"php": "^8.1"
},
"conflict": {
"twig/twig": "<1.42.3 || >=2,<2.9"
"symfony/http-foundation": "<5.4",
"twig/twig": "<2.16"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this aligns the conflict rule with our Twig dev requirement.

},
"require-dev": {
"phpstan/phpstan": "^1.10",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^9.6",
"psr/container": "^1.0 || ^2.0",
"symfony/http-foundation": "^5.4 || ^6.0 || ^7.0",
Expand Down
38 changes: 2 additions & 36 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,42 +1,8 @@
parameters:
ignoreErrors:
-
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpFoundation\\\\RequestStack\\:\\:getMasterRequest\\(\\)\\.$#"
count: 1
path: src/Knp/Menu/Matcher/Voter/RouteVoter.php

-
message: "#^Strict comparison using \\=\\=\\= between false and array\\<string, Knp\\\\Menu\\\\ItemInterface\\> will always evaluate to false\\.$#"
count: 1
path: src/Knp/Menu/MenuItem.php

-
message: "#^Parameter \\#2 \\$path of method Knp\\\\Menu\\\\Twig\\\\Helper\\:\\:get\\(\\) expects array\\<int, string\\>, array\\<Knp\\\\Menu\\\\ItemInterface\\|string\\> given\\.$#"
message: '#^Parameter \#2 \$path of method Knp\\Menu\\Twig\\Helper\:\:get\(\) expects array\<int, string\>, array\<Knp\\Menu\\ItemInterface\|string\> given\.$#'
identifier: argument.type
count: 1
path: src/Knp/Menu/Twig/Helper.php

-
message: "#^Method Knp\\\\Menu\\\\Util\\\\MenuManipulator\\:\\:getBreadcrumbsArray\\(\\) should return array\\<int, array\\{label\\: string, uri\\: string\\|null, item\\: Knp\\\\Menu\\\\ItemInterface\\|null\\}\\> but returns array\\<int, array\\{label\\: string, uri\\: string\\|null, item\\: Knp\\\\Menu\\\\ItemInterface\\|null\\}\\|array\\{label\\: string, url\\: string\\|null, item\\: Knp\\\\Menu\\\\ItemInterface\\|null\\}\\>\\.$#"
count: 1
path: src/Knp/Menu/Util/MenuManipulator.php

-
message: "#^Method Knp\\\\Menu\\\\Twig\\\\MenuExtension\\:\\:getBreadcrumbsArray\\(\\) has parameter \\$subItem with no value type specified in iterable type array\\.$#"
count: 1
path: src/Knp/Menu/Twig/MenuExtension.php

-
message: "#^PHPDoc tag @param for parameter \\$subItem with type array\\<int\\|string, array\\<string, Knp\\\\Menu\\\\ItemInterface\\|string\\|null\\>\\|float\\|int\\|Knp\\\\Menu\\\\ItemInterface\\|string\\|null\\>\\|string\\|Traversable\\<mixed, array\\<string, Knp\\\\Menu\\\\ItemInterface\\|string\\|null\\>\\|float\\|int\\|Knp\\\\Menu\\\\ItemInterface\\|string\\|null\\> is not subtype of native type array\\|string\\|null\\.$#"
count: 1
path: src/Knp/Menu/Twig/MenuExtension.php

-
message: "#^Method Knp\\\\Menu\\\\Twig\\\\MenuRuntimeExtension\\:\\:getBreadcrumbsArray\\(\\) has parameter \\$subItem with no value type specified in iterable type array\\.$#"
count: 1
path: src/Knp/Menu/Twig/MenuRuntimeExtension.php

-
message: "#^PHPDoc tag @param for parameter \\$subItem with type array\\<int\\|string, array\\<string, Knp\\\\Menu\\\\ItemInterface\\|string\\|null\\>\\|float\\|int\\|Knp\\\\Menu\\\\ItemInterface\\|string\\|null\\>\\|string\\|Traversable\\<mixed, array\\<string, Knp\\\\Menu\\\\ItemInterface\\|string\\|null\\>\\|float\\|int\\|Knp\\\\Menu\\\\ItemInterface\\|string\\|null\\> is not subtype of native type array\\|string\\|null\\.$#"
count: 1
path: src/Knp/Menu/Twig/MenuRuntimeExtension.php

1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
parameters:
level: 8
treatPhpDocTypesAsCertain: false
paths:
- src
includes:
Expand Down
6 changes: 5 additions & 1 deletion src/Knp/Menu/Iterator/CurrentItemFilterIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

namespace Knp\Menu\Iterator;

use Knp\Menu\ItemInterface;
use Knp\Menu\Matcher\MatcherInterface;

/**
* Filter iterator keeping only current items
*
* @template TKey
* @template-extends \FilterIterator<TKey, ItemInterface, \Iterator<TKey, ItemInterface>>
*/
class CurrentItemFilterIterator extends \FilterIterator
{
/**
* @param \Iterator<string|int, \Knp\Menu\ItemInterface> $iterator
* @param \Iterator<TKey, ItemInterface> $iterator
*/
public function __construct(\Iterator $iterator, private MatcherInterface $matcher)
{
Expand Down
12 changes: 8 additions & 4 deletions src/Knp/Menu/Iterator/RecursiveItemIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

namespace Knp\Menu\Iterator;

use Knp\Menu\ItemInterface;

/**
* Recursive iterator iterating on an item
*
* @extends \IteratorIterator<string, \Knp\Menu\ItemInterface, \Traversable<string, \Knp\Menu\ItemInterface>>
* @template TKey
*
* @extends \IteratorIterator<TKey, ItemInterface, \Traversable<TKey, ItemInterface>>
*
* @implements \RecursiveIterator<string, \Knp\Menu\ItemInterface>>
* @implements \RecursiveIterator<TKey, ItemInterface>
*/
class RecursiveItemIterator extends \IteratorIterator implements \RecursiveIterator
{
/**
* @param \Traversable<string, \Knp\Menu\ItemInterface> $iterator
* @param \Traversable<TKey, ItemInterface> $iterator
*/
final public function __construct(\Traversable $iterator)
{
Expand All @@ -25,7 +29,7 @@ public function hasChildren(): bool
}

/**
* @return RecursiveItemIterator
* @return RecursiveItemIterator<TKey>
*/
#[\ReturnTypeWillChange]
public function getChildren()
Expand Down
6 changes: 1 addition & 5 deletions src/Knp/Menu/Matcher/Voter/RouteVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ public function __construct(private RequestStack $requestStack)

public function matchItem(ItemInterface $item): ?bool
{
if (\method_exists($this->requestStack, 'getMainRequest')) {
$request = $this->requestStack->getMainRequest(); // symfony 5.3+
} else {
$request = $this->requestStack->getMasterRequest();
}
$request = $this->requestStack->getMainRequest();

if (null === $request) {
return null;
Expand Down
4 changes: 1 addition & 3 deletions src/Knp/Menu/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ public function setName(string $name): ItemInterface
$offset = \array_search($oldName, $names);
$names[$offset] = $name;

if (false === $children = \array_combine($names, $items)) {
throw new \InvalidArgumentException('Number of elements is not matching.');
}
$children = \array_combine($names, $items);

$parent->setChildren($children);
}
Expand Down
10 changes: 3 additions & 7 deletions src/Knp/Menu/Twig/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ public function get($menu, array $path = [], array $options = []): ItemInterface

$menuName = $menu;
$menu = $this->menuProvider->get($menuName, $options);

if (!$menu instanceof ItemInterface) {
throw new \LogicException(\sprintf('The menu "%s" exists, but is not a valid menu item object. Check where you created the menu to be sure it returns an ItemInterface object.', $menuName));
}
}

foreach ($path as $child) {
Expand Down Expand Up @@ -82,20 +78,20 @@ public function render($menu, array $options = [], ?string $renderer = null): st
*
* Each element in the array will be an array with 3 keys:
* - `label` containing the label of the item
* - `url` containing the url of the item (may be `null`)
* - `uri` containing the url of the item (may be `null`)
* - `item` containing the original item (may be `null` for the extra items)
*
* The subItem can be one of the following forms
* * 'subItem'
* * ItemInterface object
* * ['subItem' => '@homepage']
* * ['subItem1', 'subItem2']
* * [['label' => 'subItem1', 'url' => '@homepage'], ['label' => 'subItem2']]
* * [['label' => 'subItem1', 'uri' => '@homepage'], ['label' => 'subItem2']]
*
* @param mixed $menu
* @param mixed $subItem A string or array to append onto the end of the array
*
* @phpstan-param string|ItemInterface|array<int|string, string|int|float|null|array{label: string, url: string|null, item: ItemInterface|null}|ItemInterface>|\Traversable<string|int|float|null|array{label: string, url: string|null, item: ItemInterface|null}|ItemInterface> $subItem
* @phpstan-param string|ItemInterface|array<int|string, string|int|float|null|array{label: string, uri: string|null, item: ItemInterface|null}|ItemInterface>|\Traversable<string|int|float|null|array{label: string, uri: string|null, item: ItemInterface|null}|ItemInterface> $subItem
*
* @return array<int, array<string, mixed>>
*
Expand Down
3 changes: 1 addition & 2 deletions src/Knp/Menu/Twig/MenuExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ public function render(array|ItemInterface|string $menu, array $options = [], ?s

/**
* @param string|ItemInterface|array<ItemInterface|string> $menu
* @param string|array<string|null>|null $subItem
*
* @phpstan-param string|ItemInterface|array<int|string, string|int|float|null|array{label: string, url: string|null, item: ItemInterface|null}|ItemInterface>|\Traversable<string|int|float|null|array{label: string, url: string|null, item: ItemInterface|null}|ItemInterface> $subItem
* @phpstan-param string|array<int|string, string|int|float|null|array{label: string, uri: string|null, item: ItemInterface|null}|ItemInterface> $subItem
*
* @return array<int, array<string, mixed>>
* @phpstan-return list<array{label: string, uri: string|null, item: ItemInterface|null}>
Expand Down
3 changes: 1 addition & 2 deletions src/Knp/Menu/Twig/MenuRuntimeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ public function render(array|ItemInterface|string $menu, array $options = [], ?s
* Returns an array ready to be used for breadcrumbs.
*
* @param string|ItemInterface|array<ItemInterface|string> $menu
* @param string|array<string|null>|null $subItem
*
* @phpstan-param string|ItemInterface|array<int|string, string|int|float|null|array{label: string, url: string|null, item: ItemInterface|null}|ItemInterface>|\Traversable<string|int|float|null|array{label: string, url: string|null, item: ItemInterface|null}|ItemInterface> $subItem
* @phpstan-param string|array<int|string, string|int|float|null|array{label: string, uri: string|null, item: ItemInterface|null}|ItemInterface> $subItem
*
* @return array<int, array<string, mixed>>
* @phpstan-return list<array{label: string, uri: string|null, item: ItemInterface|null}>
Expand Down
10 changes: 5 additions & 5 deletions src/Knp/Menu/Util/MenuManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public function moveToLastPosition(ItemInterface $item): void
* Note: when using a child as limit, it will not be included in the returned menu.
* the slice is done before this menu.
*
* @param mixed $offset name of child, child object, or numeric offset
* @param string|int|ItemInterface $length name of child, child object, or numeric length
* @param mixed $offset name of child, child object, or numeric offset
* @param string|int|ItemInterface|null $length name of child, child object, or numeric length
*/
public function slice(ItemInterface $item, $offset, $length = null): ItemInterface
{
Expand Down Expand Up @@ -196,7 +196,7 @@ public function toArray(ItemInterface $item, ?int $depth = null): array
*
* Each element in the array will be an array with 3 keys:
* - `label` containing the label of the item
* - `url` containing the url of the item (may be `null`)
* - `uri` containing the url of the item (may be `null`)
* - `item` containing the original item (may be `null` for the extra items)
*
* The subItem can be one of the following forms
Expand All @@ -206,9 +206,9 @@ public function toArray(ItemInterface $item, ?int $depth = null): array
* * ['subItem1', 'subItem2']
* * [['label' => 'subItem1', 'url' => '@homepage'], ['label' => 'subItem2']]
*
* @param string|ItemInterface|array<int|string, mixed>|\Traversable<mixed> $subItem A string or array to append onto the end of the array
* @param string|ItemInterface|array<int|string, mixed>|\Traversable<mixed>|null $subItem A string or array to append onto the end of the array
*
* @phpstan-param string|ItemInterface|array<int|string, string|int|float|null|array{label: string, url: string|null, item: ItemInterface|null}|ItemInterface>|\Traversable<string|int|float|null|array{label: string, url: string|null, item: ItemInterface|null}|ItemInterface> $subItem
* @phpstan-param string|ItemInterface|array<int|string, string|int|float|null|array{label: string, uri: string|null, item: ItemInterface|null}|ItemInterface>|\Traversable<string|int|float|null|array{label: string, uri: string|null, item: ItemInterface|null}|ItemInterface>|null $subItem
*
* @return array<int, array<string, mixed>>
* @phpstan-return list<array{label: string, uri: string|null, item: ItemInterface|null}>
Expand Down
Loading