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.
This check compares the return type specified in the @return annotation of a function
or method doc comment with the types returned by the function and raises an issue if they
mismatch.
Loading history...
26
*/
27
protected function instantiateRenderer(ParserInterface $parser)
28
{
29
return new FixedTextRenderer();
30
}
31
32
/**
33
* @param RendererInterface $renderer
34
* @param ParserInterface $parser
35
*
36
* @return RendererInterface
37
*
38
* @throws RuntimeException
39
*/
40
4
public function buildRenderer(RendererInterface $renderer, ParserInterface $parser)
Both the $myVar assignment in line 1 and the $higher assignment in line 2
are dead. The first because $myVar is never used and the second because
$higher is always overwritten for every possible time line.
Loading history...
43
44
4
$fontResolver = $this->getFontResolver();
45
4
if (!$fontResolver) {
46
throw new RuntimeException('Font resolver not set');
It seems like you code against a concrete implementation and not the interface Graze\CiffRenderer\Field...derer\RendererInterface as the method setFontResolver() does only exist in the following implementations of said interface: Graze\CiffRenderer\Field\Renderer\BarcodeRenderer, Graze\CiffRenderer\Field...derer\FixedTextRenderer.
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.