It seems like you code against a concrete implementation and not the interface Traversable as the method current() does only exist in the following implementations of said interface: AppendIterator, ArrayIterator, CachingIterator, CallbackFilterIterator, DirectoryIterator, Doctrine\Common\Collections\AbstractLazyCollection, Doctrine\Common\Collections\ArrayCollection, EmptyIterator, File_Iterator, FilesystemIterator, FilterIterator, Generator, GlobIterator, Guzzle\Iterator\AppendIterator, Guzzle\Iterator\ChunkedIterator, Guzzle\Iterator\FilterIterator, Guzzle\Iterator\MapIterator, Guzzle\Iterator\MethodProxyIterator, Guzzle\Service\Resource\ResourceIterator, Guzzle\Tests\Service\Moc...del\MockCommandIterator, HttpMessage, HttpRequestPool, Imagick, ImagickPixelIterator, InfiniteIterator, Issue523, IteratorIterator, LimitIterator, MongoCommandCursor, MongoCursor, MongoGridFSCursor, MultipleIterator, NoRewindIterator, PHPUnit_Runner_Filter_GroupFilterIterator, PHPUnit_Runner_Filter_Group_Exclude, PHPUnit_Runner_Filter_Group_Include, PHPUnit_Runner_Filter_Test, PHPUnit_Util_TestSuiteIterator, PHP_Token_Stream, ParentIterator, Phar, PharData, Psi\Component\Grid\Row, Psi\Component\Grid\Table, RecursiveArrayIterator, RecursiveCachingIterator, RecursiveCallbackFilterIterator, RecursiveDirectoryIterator, RecursiveFilterIterator, RecursiveIteratorIterator, RecursiveRegexIterator, RecursiveTreeIterator, RegexIterator, SQLiteResult, SebastianBergmann\CodeCoverage\Node\Iterator, SimpleXMLIterator, SplDoublyLinkedList, SplFileObject, SplFixedArray, SplHeap, SplMaxHeap, SplMinHeap, SplObjectStorage, SplPriorityQueue, SplQueue, SplStack, SplTempFileObject, Symfony\Component\Form\E...r\ViolationPathIterator, Symfony\Component\Form\FormErrorIterator, Symfony\Component\Form\U...nheritDataAwareIterator, Symfony\Component\Form\Util\OrderedHashMapIterator, Symfony\Component\Proper...ss\PropertyPathIterator, TestIterator, TestIterator2, Zend\Stdlib\FastPriorityQueue, Zend\Stdlib\PriorityList, Zend\Stdlib\SplPriorityQueue, Zend\Stdlib\SplQueue, Zend\Stdlib\SplStack.
Let’s take a look at an example:
interfaceUser{/** @return string */publicfunctiongetPassword();}classMyUserimplementsUser{publicfunctiongetPassword(){// return something}publicfunctiongetDisplayName(){// return some name.}}classAuthSystem{publicfunctionauthenticate(User$user){$this->logger->info(sprintf('Authenticating %s.',$user->getDisplayName()));// do something.}}
In the above example, the authenticate() method works fine as long as you just pass
instances of MyUser. However, if you now also want to pass a different implementation
of User which does not have a getDisplayName() method, the code will break.
classAuthSystem{publicfunctionauthenticate(User$user){if($userinstanceofMyUser){$this->logger->info(/** ... */);}// or alternativelyif(!$userinstanceofMyUser){thrownew\LogicException('$user must be an instance of MyUser, '.'other instances are not supported.');}}}
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
It seems like you code against a concrete implementation and not the interface Traversable as the method next() does only exist in the following implementations of said interface: AppendIterator, ArrayIterator, CachingIterator, CallbackFilterIterator, DirectoryIterator, Doctrine\Common\Collections\AbstractLazyCollection, Doctrine\Common\Collections\ArrayCollection, EmptyIterator, File_Iterator, FilesystemIterator, FilterIterator, Generator, GlobIterator, Guzzle\Iterator\AppendIterator, Guzzle\Iterator\ChunkedIterator, Guzzle\Iterator\FilterIterator, Guzzle\Iterator\MapIterator, Guzzle\Iterator\MethodProxyIterator, Guzzle\Service\Resource\ResourceIterator, Guzzle\Tests\Service\Moc...del\MockCommandIterator, HttpMessage, HttpRequestPool, Imagick, ImagickPixelIterator, InfiniteIterator, Issue523, IteratorIterator, LimitIterator, MongoCommandCursor, MongoCursor, MongoGridFSCursor, MultipleIterator, NoRewindIterator, PHPUnit_Runner_Filter_GroupFilterIterator, PHPUnit_Runner_Filter_Group_Exclude, PHPUnit_Runner_Filter_Group_Include, PHPUnit_Runner_Filter_Test, PHPUnit_Util_TestSuiteIterator, PHP_Token_Stream, ParentIterator, Phar, PharData, Psi\Component\Grid\Row, Psi\Component\Grid\Table, RecursiveArrayIterator, RecursiveCachingIterator, RecursiveCallbackFilterIterator, RecursiveDirectoryIterator, RecursiveFilterIterator, RecursiveIteratorIterator, RecursiveRegexIterator, RecursiveTreeIterator, RegexIterator, SQLiteResult, SebastianBergmann\CodeCoverage\Node\Iterator, SimpleXMLIterator, SplDoublyLinkedList, SplFileObject, SplFixedArray, SplHeap, SplMaxHeap, SplMinHeap, SplObjectStorage, SplPriorityQueue, SplQueue, SplStack, SplTempFileObject, Symfony\Component\Form\E...r\ViolationPathIterator, Symfony\Component\Form\FormErrorIterator, Symfony\Component\Form\U...nheritDataAwareIterator, Symfony\Component\Form\Util\OrderedHashMapIterator, Symfony\Component\Proper...ss\PropertyPathIterator, TestIterator, TestIterator2, Zend\Stdlib\FastPriorityQueue, Zend\Stdlib\PriorityList, Zend\Stdlib\SplPriorityQueue, Zend\Stdlib\SplQueue, Zend\Stdlib\SplStack.
Let’s take a look at an example:
interfaceUser{/** @return string */publicfunctiongetPassword();}classMyUserimplementsUser{publicfunctiongetPassword(){// return something}publicfunctiongetDisplayName(){// return some name.}}classAuthSystem{publicfunctionauthenticate(User$user){$this->logger->info(sprintf('Authenticating %s.',$user->getDisplayName()));// do something.}}
In the above example, the authenticate() method works fine as long as you just pass
instances of MyUser. However, if you now also want to pass a different implementation
of User which does not have a getDisplayName() method, the code will break.
classAuthSystem{publicfunctionauthenticate(User$user){if($userinstanceofMyUser){$this->logger->info(/** ... */);}// or alternativelyif(!$userinstanceofMyUser){thrownew\LogicException('$user must be an instance of MyUser, '.'other instances are not supported.');}}}
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
It seems like you code against a concrete implementation and not the interface Traversable as the method key() does only exist in the following implementations of said interface: AppendIterator, ArrayIterator, CachingIterator, CallbackFilterIterator, DirectoryIterator, Doctrine\Common\Collections\AbstractLazyCollection, Doctrine\Common\Collections\ArrayCollection, EmptyIterator, File_Iterator, FilesystemIterator, FilterIterator, Generator, GlobIterator, Guzzle\Iterator\AppendIterator, Guzzle\Iterator\ChunkedIterator, Guzzle\Iterator\FilterIterator, Guzzle\Iterator\MapIterator, Guzzle\Iterator\MethodProxyIterator, Guzzle\Service\Resource\ResourceIterator, Guzzle\Tests\Service\Moc...del\MockCommandIterator, HttpMessage, HttpRequestPool, Imagick, ImagickPixelIterator, InfiniteIterator, Issue523, IteratorIterator, LimitIterator, MongoCommandCursor, MongoCursor, MongoGridFSCursor, MultipleIterator, NoRewindIterator, PHPUnit_Runner_Filter_GroupFilterIterator, PHPUnit_Runner_Filter_Group_Exclude, PHPUnit_Runner_Filter_Group_Include, PHPUnit_Runner_Filter_Test, PHPUnit_Util_TestSuiteIterator, PHP_Token_Stream, ParentIterator, Phar, PharData, Psi\Component\Grid\Row, Psi\Component\Grid\Table, RecursiveArrayIterator, RecursiveCachingIterator, RecursiveCallbackFilterIterator, RecursiveDirectoryIterator, RecursiveFilterIterator, RecursiveIteratorIterator, RecursiveRegexIterator, RecursiveTreeIterator, RegexIterator, SQLiteResult, SebastianBergmann\CodeCoverage\Node\Iterator, SimpleXMLIterator, SplDoublyLinkedList, SplFileObject, SplFixedArray, SplHeap, SplMaxHeap, SplMinHeap, SplObjectStorage, SplPriorityQueue, SplQueue, SplStack, SplTempFileObject, Symfony\Component\Form\E...r\ViolationPathIterator, Symfony\Component\Form\FormErrorIterator, Symfony\Component\Form\U...nheritDataAwareIterator, Symfony\Component\Form\Util\OrderedHashMapIterator, Symfony\Component\Proper...ss\PropertyPathIterator, TestIterator, TestIterator2, Zend\Stdlib\FastPriorityQueue, Zend\Stdlib\PriorityList, Zend\Stdlib\SplPriorityQueue, Zend\Stdlib\SplQueue, Zend\Stdlib\SplStack.
Let’s take a look at an example:
interfaceUser{/** @return string */publicfunctiongetPassword();}classMyUserimplementsUser{publicfunctiongetPassword(){// return something}publicfunctiongetDisplayName(){// return some name.}}classAuthSystem{publicfunctionauthenticate(User$user){$this->logger->info(sprintf('Authenticating %s.',$user->getDisplayName()));// do something.}}
In the above example, the authenticate() method works fine as long as you just pass
instances of MyUser. However, if you now also want to pass a different implementation
of User which does not have a getDisplayName() method, the code will break.
classAuthSystem{publicfunctionauthenticate(User$user){if($userinstanceofMyUser){$this->logger->info(/** ... */);}// or alternativelyif(!$userinstanceofMyUser){thrownew\LogicException('$user must be an instance of MyUser, '.'other instances are not supported.');}}}
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
It seems like you code against a concrete implementation and not the interface Traversable as the method first() does only exist in the following implementations of said interface: Doctrine\Common\Collections\AbstractLazyCollection, Doctrine\Common\Collections\ArrayCollection.
Let’s take a look at an example:
interfaceUser{/** @return string */publicfunctiongetPassword();}classMyUserimplementsUser{publicfunctiongetPassword(){// return something}publicfunctiongetDisplayName(){// return some name.}}classAuthSystem{publicfunctionauthenticate(User$user){$this->logger->info(sprintf('Authenticating %s.',$user->getDisplayName()));// do something.}}
In the above example, the authenticate() method works fine as long as you just pass
instances of MyUser. However, if you now also want to pass a different implementation
of User which does not have a getDisplayName() method, the code will break.
classAuthSystem{publicfunctionauthenticate(User$user){if($userinstanceofMyUser){$this->logger->info(/** ... */);}// or alternativelyif(!$userinstanceofMyUser){thrownew\LogicException('$user must be an instance of MyUser, '.'other instances are not supported.');}}}
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
It seems like you code against a concrete implementation and not the interface Traversable as the method current() does only exist in the following implementations of said interface: AppendIterator, ArrayIterator, CachingIterator, CallbackFilterIterator, DirectoryIterator, Doctrine\Common\Collections\AbstractLazyCollection, Doctrine\Common\Collections\ArrayCollection, EmptyIterator, File_Iterator, FilesystemIterator, FilterIterator, Generator, GlobIterator, Guzzle\Iterator\AppendIterator, Guzzle\Iterator\ChunkedIterator, Guzzle\Iterator\FilterIterator, Guzzle\Iterator\MapIterator, Guzzle\Iterator\MethodProxyIterator, Guzzle\Service\Resource\ResourceIterator, Guzzle\Tests\Service\Moc...del\MockCommandIterator, HttpMessage, HttpRequestPool, Imagick, ImagickPixelIterator, InfiniteIterator, Issue523, IteratorIterator, LimitIterator, MongoCommandCursor, MongoCursor, MongoGridFSCursor, MultipleIterator, NoRewindIterator, PHPUnit_Runner_Filter_GroupFilterIterator, PHPUnit_Runner_Filter_Group_Exclude, PHPUnit_Runner_Filter_Group_Include, PHPUnit_Runner_Filter_Test, PHPUnit_Util_TestSuiteIterator, PHP_Token_Stream, ParentIterator, Phar, PharData, Psi\Component\Grid\Row, Psi\Component\Grid\Table, RecursiveArrayIterator, RecursiveCachingIterator, RecursiveCallbackFilterIterator, RecursiveDirectoryIterator, RecursiveFilterIterator, RecursiveIteratorIterator, RecursiveRegexIterator, RecursiveTreeIterator, RegexIterator, SQLiteResult, SebastianBergmann\CodeCoverage\Node\Iterator, SimpleXMLIterator, SplDoublyLinkedList, SplFileObject, SplFixedArray, SplHeap, SplMaxHeap, SplMinHeap, SplObjectStorage, SplPriorityQueue, SplQueue, SplStack, SplTempFileObject, Symfony\Component\Form\E...r\ViolationPathIterator, Symfony\Component\Form\FormErrorIterator, Symfony\Component\Form\U...nheritDataAwareIterator, Symfony\Component\Form\Util\OrderedHashMapIterator, Symfony\Component\Proper...ss\PropertyPathIterator, TestIterator, TestIterator2, Zend\Stdlib\FastPriorityQueue, Zend\Stdlib\PriorityList, Zend\Stdlib\SplPriorityQueue, Zend\Stdlib\SplQueue, Zend\Stdlib\SplStack.
Let’s take a look at an example:
interfaceUser{/** @return string */publicfunctiongetPassword();}classMyUserimplementsUser{publicfunctiongetPassword(){// return something}publicfunctiongetDisplayName(){// return some name.}}classAuthSystem{publicfunctionauthenticate(User$user){$this->logger->info(sprintf('Authenticating %s.',$user->getDisplayName()));// do something.}}
In the above example, the authenticate() method works fine as long as you just pass
instances of MyUser. However, if you now also want to pass a different implementation
of User which does not have a getDisplayName() method, the code will break.
classAuthSystem{publicfunctionauthenticate(User$user){if($userinstanceofMyUser){$this->logger->info(/** ... */);}// or alternativelyif(!$userinstanceofMyUser){thrownew\LogicException('$user must be an instance of MyUser, '.'other instances are not supported.');}}}
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: