We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Method getFirstItem() uses results of method getItems()
getFirstItem()
getItems()
$items = $this->getItems(...$types);
and if all ok, then get element with index 0
return $items[0];
Here is the link to this line in code
But method getItems() uses function array_filter(), which preserves the array's keys. So, for example, if we have
array_filter()
ItemList $items [ 0 => type 'Breadcrumb' 1 => type 'Breadcrumb' 2 => type 'Product' ]
then after $items->getItems('Product') it will become
$items->getItems('Product')
ItemList $items [ 2 => type 'Product' ]
and $items[0] will return null.
$items[0]
I suggest to use
public function getFirstItem(...$types) { $items = array_values($this->getItems(...$types));
or
public function getItems(...$types) { ... return array_values($this->items);
The text was updated successfully, but these errors were encountered:
It seems that getItems() used as well in method getItemByTypeAndIndex(), where index is valuable. So we can do like this:
getItemByTypeAndIndex()
public function getFirstItem(...$types) { $items = array_slice($this->getItems(...$types), 0, 1);
Sorry, something went wrong.
jkphl
No branches or pull requests
Method
getFirstItem()
uses results of methodgetItems()
and if all ok, then get element with index 0
Here is the link to this line in code
But method
getItems()
uses functionarray_filter()
, which preserves the array's keys. So, for example, if we havethen after
$items->getItems('Product')
it will becomeand
$items[0]
will return null.I suggest to use
or
The text was updated successfully, but these errors were encountered: