Completed
Push — refactor-04-parser-tests ( 553ee6...bce951 )
by John
03:05 queued 47s
created

FieldParserFactory::getFieldParser()   B

Complexity

Conditions 9
Paths 9

Size

Total Lines 35
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 0
Metric Value
cc 9
eloc 25
nc 9
nop 1
dl 0
loc 35
ccs 0
cts 28
cp 0
crap 90
rs 8.0555
c 0
b 0
f 0
1
<?php
2
3
namespace Graze\CiffRenderer\Parser;
4
5
use Graze\CiffRenderer\SimpleXmlElement\SimpleXmlElementInterface;
6
use Graze\CiffRenderer\Parser\FieldType;
7
use Graze\CiffRenderer\Parser\FieldParser\FieldParserFixedText;
8
use Graze\CiffRenderer\Parser\FieldParser\FieldParserBarcode;
9
use Graze\CiffRenderer\Parser\FieldParser\FieldParserDate;
10
use Graze\CiffRenderer\Parser\FieldParser\FieldParserDateOffset;
11
use Graze\CiffRenderer\Parser\FieldParser\FieldParserStaticGraphic;
12
use Graze\CiffRenderer\Parser\FieldParser\FieldParserGraphicPrimitive;
13
use Graze\CiffRenderer\Exception\UnsupportedFieldTypeException;
14
15
class FieldParserFactory
16
{
17
    /**
18
     * @param SimpleXmlElementInterface $xml
19
     * @return FieldParserInterface
0 ignored issues
show
Bug introduced by
The type Graze\CiffRenderer\Parser\FieldParserInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
     */
21
    public function getFieldParser(SimpleXmlElementInterface $xml)
22
    {
23
        $fieldType = (string) $xml->FldType; // @codingStandardsIgnoreLine
0 ignored issues
show
Bug introduced by
Accessing FldType on the interface Graze\CiffRenderer\Simpl...mpleXmlElementInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
24
        switch ($fieldType) {
25
            case FieldType::FIELD_FIXED_TEXT:
26
            case FieldType::FIELD_COMPLEX_TEXT:
27
            case FieldType::FIELD_MERGE_FIELD:
28
                $className = FieldParserFixedText::class;
29
                break;
30
31
            case FieldType::FIELD_BARCODE:
32
                $className = FieldParserBarcode::class;
33
                break;
34
35
            case FieldType::FIELD_DATE:
36
                $className = FieldParserDate::class;
37
                break;
38
39
            case FieldType::FIELD_OFFSET_DATE:
40
                $className = FieldParserDateOffset::class;
41
                break;
42
43
            case FieldType::FIELD_STATIC_GRAPHIC:
44
                $className = FieldParserStaticGraphic::class;
45
                break;
46
47
            case FieldType::FIELD_GRAPHIC_PRIMITIVE:
48
                $className = FieldParserGraphicPrimitive::class;
49
                break;
50
51
            default:
52
                throw new UnsupportedFieldTypeException($fieldType);
53
        }
54
55
        return $className::factory();
56
    }
57
}
58