Completed
Push — master ( 4984e7...9ad690 )
by John
03:58
created

StaticGraphicBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 85.71%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 40
loc 40
rs 10
c 2
b 0
f 0
ccs 6
cts 7
cp 0.8571

3 Methods

Rating   Name   Duplication   Size   Complexity  
A buildRenderer() 13 13 2
A instantiateParser() 4 4 1
A instantiateRenderer() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Graze\CiffRenderer\Field\Builder;
4
5
use Graze\CiffRenderer\Field\Parser\StaticGraphicParser;
6
use Graze\CiffRenderer\Field\Renderer\StaticGraphicRenderer;
7
use Graze\CiffRenderer\Field\Parser\ParserInterface;
8
use Graze\CiffRenderer\Field\Renderer\RendererInterface;
9
use Graze\CiffRenderer\Exception\RuntimeException;
10
11 View Code Duplication
class StaticGraphicBuilder extends AbstractBuilder
0 ignored issues
show
Duplication introduced by
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...
12
{
13
    /**
14
     * @return StaticGraphicParser
15
     */
16
    protected function instantiateParser()
17
    {
18
        return new StaticGraphicParser($xmlField);
0 ignored issues
show
Bug introduced by
The variable $xmlField does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Unused Code introduced by
The call to StaticGraphicParser::__construct() has too many arguments starting with $xmlField.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
19
    }
20
21
    /**
22
     * @param ParserInterface $parser
23
     *
24
     * @return StaticGraphicRenderer
25
     */
26
    protected function instantiateRenderer(ParserInterface $parser)
27
    {
28
        return new StaticGraphicRenderer();
29
    }
30
31
    /**
32
     * @param RendererInterface $renderer
33
     * @param ParserInterface $parser
34
     *
35
     * @return StaticGraphicRenderer
36
     */
37 1
    public function buildRenderer(RendererInterface $renderer, ParserInterface $parser)
38
    {
39 1
        $renderer = parent::buildRenderer($renderer, $parser);
40
41 1
        $graphicResolver = $this->getGraphicResolver();
42 1
        if (!$graphicResolver) {
43
            throw new RuntimeException('Graphic resolver not set');
44
        }
45
46 1
        $renderer->setGraphicResolver($graphicResolver);
47
48 1
        return $renderer;
49
    }
50
}
51