This class seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate
the same code in three or more different places, we strongly encourage you to
look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
7
{
8
public $field = "taxno";
9
10
24
public function __construct(\Traversable $iterator, $field = null)
It seems like you code against a concrete implementation and not the interface Traversable as the method getIterator() does only exist in the following implementations of said interface: ArrayAccessible, ArrayObject, Doctrine\Common\Collections\AbstractLazyCollection, Doctrine\Common\Collections\ArrayCollection, GuzzleHttp\Cookie\CookieJar, GuzzleHttp\Cookie\FileCookieJar, GuzzleHttp\Cookie\SessionCookieJar, PHPUnit\Framework\DataProviderTestSuite, PHPUnit\Framework\TestSuite, PharIo\Manifest\AuthorCollection, PharIo\Manifest\BundledComponentCollection, PharIo\Manifest\RequirementCollection, PhpCsFixer\Finder, SebastianBergmann\CodeCoverage\Node\Directory, Symfony\Component\Config\Resource\GlobResource, Symfony\Component\Console\Helper\HelperSet, Symfony\Component\Console\Helper\TableRows, Symfony\Component\Consol...lper\AutocompleteValues, Symfony\Component\EventDispatcher\GenericEvent, Symfony\Component\Finder\Finder, Symfony\Component\Finder\Iterator\SortableIterator, Symfony\Component\Finder...\ClassThatInheritFinder, Symfony\Component\Process\InputStream, Symfony\Component\Process\PhpProcess, Symfony\Component\Process\Process, TestIteratorAggregate, TestIteratorAggregate2, WrapperIteratorAggregate, phpDocumentor\Reflection\Types\Compound.
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.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.