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

AbstractFieldParser::getFieldName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Graze\CiffRenderer\Parser\FieldParser;
4
5
use Graze\CiffRenderer\Parser\FieldParser\FieldParserInterface;
6
use Graze\CiffRenderer\Parser\FieldParserRegistry;
7
use Graze\CiffRenderer\SimpleXmlElement\SimpleXmlElementInterface;
8
9
abstract class AbstractFieldParser implements FieldParserInterface
10
{
11
    /**
12
     * @var FieldParserRegistry
13
     */
14
    protected $fieldParserRegistry;
15
16
    /**
17
     * @var SimpleXmlElementInterface
18
     */
19
    protected $xmlField;
20
21
    /**
22
     * @var SimpleXmlElementInterface
23
     */
24
    protected $xmlHeader;
25
26
    /**
27
     * @var float
28
     */
29
    protected $scale;
30
31
    /**
32
     * @param FieldParserRegistry $fieldParserRegistry
33
     * @param SimpleXmlElementInterface $xmlField
34
     * @param SimpleXmlElementInterface $xmlHeader
35
     * @param float $scale
36
     */
37
    public function parse(
38
        FieldParserRegistry $fieldParserRegistry,
39
        SimpleXmlElementInterface $xmlField,
40
        SimpleXmlElementInterface $xmlHeader,
41
        $scale
42
    ) {
43
        $this->fieldParserRegistry = $fieldParserRegistry;
44
        $this->xmlField = $xmlField;
45
        $this->xmlHeader = $xmlHeader;
46
        $this->scale = $scale;
47
        $this->fieldParserRegistry->addParser($this);
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getFieldName()
54
    {
55
        return (string) $this->xmlField->attributes()->Name;
0 ignored issues
show
Bug introduced by
The method attributes() does not exist on Graze\CiffRenderer\Simpl...mpleXmlElementInterface. It seems like you code against a sub-type of Graze\CiffRenderer\Simpl...mpleXmlElementInterface such as Graze\CiffRenderer\Simpl...lement\SimpleXmlElement. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        return (string) $this->xmlField->/** @scrutinizer ignore-call */ attributes()->Name;
Loading history...
56
    }
57
58
    /**
59
     * @return int
60
     */
61
    public function getPositionX()
62
    {
63
        return (int) ($this->xmlField->X * $this->scale);
0 ignored issues
show
Bug introduced by
Accessing X on the interface Graze\CiffRenderer\Simpl...mpleXmlElementInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
64
    }
65
66
    /**
67
     * @return int
68
     */
69
    public function getPositionY()
70
    {
71
        return (int) ($this->xmlField->Y * $this->scale);
0 ignored issues
show
Bug introduced by
Accessing Y on the interface Graze\CiffRenderer\Simpl...mpleXmlElementInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
72
    }
73
74
    /**
75
     * @return int
76
     */
77
    public function getWidth()
78
    {
79
        return (int) ($this->xmlField->W * $this->scale);
0 ignored issues
show
Bug introduced by
Accessing W on the interface Graze\CiffRenderer\Simpl...mpleXmlElementInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
80
    }
81
82
    /**
83
     * @return int
84
     */
85
    public function getHeight()
86
    {
87
        return (int) ($this->xmlField->H * $this->scale);
0 ignored issues
show
Bug introduced by
Accessing H on the interface Graze\CiffRenderer\Simpl...mpleXmlElementInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
88
    }
89
90
    /**
91
     * @return bool
92
     */
93
    public function isDisplayed()
94
    {
95
        return (string) $this->xmlField->Displayed != '0';
0 ignored issues
show
Bug introduced by
Accessing Displayed on the interface Graze\CiffRenderer\Simpl...mpleXmlElementInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
96
    }
97
98
    /**
99
     * @return FieldParserInterface
100
     */
101
    public static function factory()
102
    {
103
        return new static();
104
    }
105
}
106