You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// stub
class SomeClass
{
}
// class with bug
/**
* annotation must be exists:
* @method SomeClass[]|SomeParentCollection getSorted()
*/
class SomeParentCollection implements Iterator
{
/** @var SomeClass[] */
protected $collection;
public function findByName(string $name): ?SomeClass
{
foreach ($this->collection as $item) {
if ((string)$item === $name) {
return $item;
}
}
return null;
}
// must be exists!
public function existsByKey(string $name): bool
{
return $this->findByName($name) !== null;
}
public function getSorted(callable $comparator): self
{
$sortedCollection = $this->collection;
usort($sortedCollection, $comparator);
$filtered = array_values($sortedCollection);
return new static(...$filtered);
}
public function rewind(): void
{
reset($this->collection);
}
public function current()
{
return current($this->collection);
}
/**
* @return bool|float|int|string|null
*/
public function key()
{
return key($this->collection);
}
/**
* @return mixed|void
*/
public function next()
{
return next($this->collection);
}
public function valid(): bool
{
return isset($this->collection[key($this->collection)]);
}
}
I debug this code.
Loop begins in \PHPStan\Reflection\Annotations\AnnotationsMethodsClassReflectionExtension::findClassReflectionWithMethod
The problem begins from existsByKey, phpstan goes to findByName, then try get info about current() method, checks phpdoc and get infinity loop while triyng to parse "@method SomeClass[]|SomeParentCollection getSorted()".
Phpstan successfully parse SomeClass[], but fails on next step SomeParentCollection.
Requirements for bug:
annotation with 2 return type "@method SomeClass[]|SomeParentCollection getSorted()"
method that calls another method with foreach.
I tried to remove one of this requirement, all works fine.
I tried it on phpstan.org and I got "An error occured. Please try again later."
Expected output
Result exists.
Did PHPStan help you today? Did it make you happy in any way?
Sure. I make own rules and it helps to provide code standards in our team. Great product!
The text was updated successfully, but these errors were encountered:
Please test it by installing dev-master: composer require --dev phpstan/phpstan:dev-master. If you have Composer 2.1.0 or later, it will be much faster! Otherwise you need to add --prefer-dist to that too.
Bug report
Code snippet that reproduces the problem
I debug this code.
Loop begins in \PHPStan\Reflection\Annotations\AnnotationsMethodsClassReflectionExtension::findClassReflectionWithMethod
The problem begins from
existsByKey
, phpstan goes to findByName, then try get info about current() method, checks phpdoc and get infinity loop while triyng to parse "@method SomeClass[]|SomeParentCollection getSorted()".Phpstan successfully parse SomeClass[], but fails on next step SomeParentCollection.
Requirements for bug:
foreach
.I tried to remove one of this requirement, all works fine.
I tried it on phpstan.org and I got "An error occured. Please try again later."
Expected output
Result exists.
Did PHPStan help you today? Did it make you happy in any way?
Sure. I make own rules and it helps to provide code standards in our team. Great product!
The text was updated successfully, but these errors were encountered: