diff --git a/composer.json b/composer.json index 5c16ea5f..32b5817e 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,8 @@ "php": "^7.1", "symfony/framework-bundle": "^2.8 || ^3.3 || ^4.0", "symfony/validator": "^2.8 || ^3.3 || ^4.0", - "knplabs/knp-menu-bundle": "^2.2.0", - "knplabs/knp-menu": "^2.0.0" + "knplabs/knp-menu-bundle": "^2.2 || ^3.0", + "knplabs/knp-menu": "^2.0 || ^3.0" }, "require-dev": { "symfony/monolog-bundle": "~3.1", diff --git a/src/Extension/ContentExtension.php b/src/Extension/ContentExtension.php index ebae85cf..a0ce00b4 100644 --- a/src/Extension/ContentExtension.php +++ b/src/Extension/ContentExtension.php @@ -45,7 +45,7 @@ public function __construct(UrlGeneratorInterface $contentRouter) * * @return array */ - public function buildOptions(array $options) + public function buildOptions(array $options): array { $options = array_merge([ 'content' => null, @@ -86,7 +86,7 @@ public function buildOptions(array $options) * @param ItemInterface $item * @param array $options */ - public function buildItem(ItemInterface $item, array $options) + public function buildItem(ItemInterface $item, array $options): void { } diff --git a/src/Loader/VotingNodeLoader.php b/src/Loader/VotingNodeLoader.php index b5fcb67c..f49c8762 100644 --- a/src/Loader/VotingNodeLoader.php +++ b/src/Loader/VotingNodeLoader.php @@ -12,6 +12,7 @@ namespace Symfony\Cmf\Bundle\MenuBundle\Loader; use Knp\Menu\FactoryInterface; +use Knp\Menu\ItemInterface; use Knp\Menu\Loader\NodeLoader; use Knp\Menu\NodeInterface; use Symfony\Cmf\Bundle\MenuBundle\Doctrine\Phpcr\Menu; @@ -40,7 +41,7 @@ public function __construct(FactoryInterface $factory, EventDispatcherInterface $this->dispatcher = $dispatcher; } - public function load($data) + public function load($data): ItemInterface { if (!$this->supports($data)) { throw new \InvalidArgumentException(sprintf( @@ -52,21 +53,13 @@ public function load($data) $this->dispatcher->dispatch(Events::CREATE_ITEM_FROM_NODE, $event); if ($event->isSkipNode()) { - if ($data instanceof Menu) { - // create an empty menu root to avoid the knp menu from failing. - return $this->menuFactory->createItem(''); - } - - return; + // create an empty menu root to avoid the knp menu from failing. + return $this->menuFactory->createItem(''); } $item = $event->getItem() ?: $this->menuFactory->createItem($data->getName(), $data->getOptions()); - if (empty($item)) { - return; - } - - if ($event->isSkipChildren()) { + if (empty($item) || $event->isSkipChildren()) { return $item; } diff --git a/src/Model/MenuNode.php b/src/Model/MenuNode.php index 8ccf2dfd..3b6ff064 100644 --- a/src/Model/MenuNode.php +++ b/src/Model/MenuNode.php @@ -145,7 +145,7 @@ public function setContent($content) /** * {@inheritdoc} */ - public function getOptions() + public function getOptions(): array { $options = parent::getOptions(); diff --git a/src/Model/MenuNodeBase.php b/src/Model/MenuNodeBase.php index c308d870..69386768 100644 --- a/src/Model/MenuNodeBase.php +++ b/src/Model/MenuNodeBase.php @@ -172,7 +172,7 @@ public function setId($id) /** * {@inheritdoc} */ - public function getName() + public function getName(): string { return $this->name; } @@ -349,7 +349,7 @@ public function setChildrenAttributes(array $attributes) * * @return NodeInterface[] */ - public function getChildren() + public function getChildren(): \Traversable { $children = []; foreach ($this->children as $child) { @@ -359,7 +359,7 @@ public function getChildren() $children[] = $child; } - return $children; + return new \ArrayIterator($children); } /** @@ -573,7 +573,7 @@ public function isDisplayable() /** * {@inheritdoc} */ - public function getOptions() + public function getOptions(): array { return [ 'uri' => $this->getUri(), diff --git a/src/Provider/PhpcrMenuProvider.php b/src/Provider/PhpcrMenuProvider.php index e9990566..7ca8cb91 100644 --- a/src/Provider/PhpcrMenuProvider.php +++ b/src/Provider/PhpcrMenuProvider.php @@ -140,7 +140,7 @@ public function getPrefetch() * * @throws \InvalidArgumentException if the menu can not be found */ - public function get($name, array $options = []) + public function get(string $name, array $options = []): ItemInterface { $menu = $this->find($name, true); @@ -164,7 +164,7 @@ public function get($name, array $options = []) * * @return bool Whether a menu with this name can be loaded by this provider */ - public function has($name, array $options = []) + public function has(string $name, array $options = []): bool { return $this->find($name, false) instanceof NodeInterface; } diff --git a/src/QuietFactory.php b/src/QuietFactory.php index a37b6ed2..d9659d33 100644 --- a/src/QuietFactory.php +++ b/src/QuietFactory.php @@ -13,6 +13,7 @@ use Knp\Menu\Factory\ExtensionInterface; use Knp\Menu\FactoryInterface; +use Knp\Menu\ItemInterface; use LogicException; use Psr\Log\LoggerInterface; use Symfony\Component\Routing\Exception\RouteNotFoundException; @@ -54,7 +55,7 @@ public function __construct(FactoryInterface $innerFactory, LoggerInterface $log /** * {@inheritdoc} */ - public function createItem($name, array $options = []) + public function createItem(string $name, array $options = []): ItemInterface { try { return $this->innerFactory->createItem($name, $options); @@ -67,7 +68,7 @@ public function createItem($name, array $options = []) } if (!$this->allowEmptyItems) { - return; + return $this->innerFactory->createItem(''); } // remove route and content options diff --git a/src/Voter/UriPrefixVoter.php b/src/Voter/UriPrefixVoter.php index e1716aaf..1852191a 100644 --- a/src/Voter/UriPrefixVoter.php +++ b/src/Voter/UriPrefixVoter.php @@ -68,11 +68,11 @@ public function setRequest(Request $request = null) /** * {@inheritdoc} */ - public function matchItem(ItemInterface $item) + public function matchItem(ItemInterface $item): ?bool { $request = $this->getRequest(); if (!$request) { - return; + return false; } $content = $item->getExtra('content'); @@ -84,6 +84,8 @@ public function matchItem(ItemInterface $item) return true; } } + + return null; } private function getRequest()