FieldRendererFactory   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 86.36%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 54
ccs 19
cts 22
cp 0.8636
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A factory() 0 4 1
A __construct() 0 3 1
A getFieldRenderer() 0 26 5
1
<?php
2
3
namespace Graze\CiffRenderer\Renderer\FieldRenderer;
4
5
use Graze\CiffRenderer\Parser\FieldParser\FieldParserInterface;
6
use Graze\CiffRenderer\Parser\FieldType;
7
use Graze\CiffRenderer\Renderer\FieldRenderer\GraphicPrimitive\GraphicPrimitiveFactory;
8
9
class FieldRendererFactory
10
{
11
    /**
12
     * @var GraphicPrimitiveFactory
13
     */
14
    private $graphicPrimitiveFactory;
15
16
    /**
17
     * @param GraphicPrimitiveFactory $graphicPrimitiveFactory
18
     */
19 8
    public function __construct(GraphicPrimitiveFactory $graphicPrimitiveFactory)
20
    {
21 8
        $this->graphicPrimitiveFactory = $graphicPrimitiveFactory;
22 8
    }
23
24
    /**
25
     * @param FieldParserInterface $parser
26
     * @return FieldRendererInterface
27
     */
28 8
    public function getFieldRenderer(FieldParserInterface $parser)
29
    {
30 8
        $fieldType = $parser->getFieldType();
31
        switch ($fieldType) {
32 8
            case FieldType::FIELD_BARCODE:
33 1
                $renderer = FieldRendererBarcode::class;
34 1
                break;
35
36 7
            case FieldType::FIELD_STATIC_GRAPHIC:
37 1
                $renderer = FieldRendererStaticGraphic::class;
38 1
                break;
39
40 6
            case FieldType::FIELD_GRAPHIC_PRIMITIVE:
41 1
                return $this->graphicPrimitiveFactory->getFieldRenderer($parser->getShape());
42
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
43
44 5
            case FieldType::FIELD_COMPLEX_TEXT:
45 1
                $renderer = FieldRendererComplexText::class;
46 1
                break;
47
48
            default:
49 4
                $renderer = FieldRendererFixedText::class;
50 4
                break;
51
        }
52
53 7
        return $renderer::factory();
54
    }
55
56
    /**
57
     * @return FieldRendererFactory
58
     */
59
    public static function factory()
60
    {
61
        return new static(
62
            new GraphicPrimitiveFactory()
63
        );
64
    }
65
}
66