Log1x/navi

Docblocks indicate `Navi->items` should be array but can be null

Closed this issue · 0 comments

Hi, thanks for the package!

Noticed a very minor issue. The docblocks for Log1x\Navi\Navi->items indicate that the property should be an array, and instantiates it as an array.

When you build a menu (new Navi())->build('menu_name'), if that menu doesn't have items, the builder function returns void instead and items is set to null. See line 66 below:

navi/src/MenuBuilder.php

Lines 56 to 73 in 555653b

/**
* Build a filtered array of objects containing the navigation menu items.
*
* @param array $menu
* @return array
*/
public function build($menu)
{
$this->menu = $this->filter((array) $menu);
if (empty($this->menu)) {
return;
}
return $this->tree(
$this->map($this->menu)
);
}

I could see two approaches:

  • Updating the docblocks for Navi->items (and related functions like Navi->toArray() and MenuBuilder->build()) to indicate that the value can be null, or:
  • Updating MenuBuilder->build() line 66 to return [] instead of return

The latter option seems to make more sense to me but is potentially a breaking change if anyone is using strict comparison for null checking, e.g. Navi->toArray() === null or Navi->getItems() === null

Happy to submit a PR if there's a preferred approach.