Completed
Push — master ( 674c45...3a5716 )
by John
02:35
created

AbstractFieldParser::getFieldName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
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 \SimpleXMLElement;
8
9
abstract class AbstractFieldParser implements FieldParserInterface
10
{
11
    /**
12
     * @var FieldParserRegistry
13
     */
14
    protected $fieldParserRegistry;
15
16
    /**
17
     * @var SimpleXMLElement
18
     */
19
    protected $xmlHeader;
20
21
    /**
22
     * @var SimpleXMLElement
23
     */
24
    protected $xmlField;
25
26
    /**
27
     * @var float
28
     */
29
    protected $scale;
30
31
    /**
32
     * @param FieldParserRegistry $fieldParserRegistry
33
     * @param SimpleXMLElement $xmlHeader
34
     * @param SimpleXMLElement $xmlField
35
     * @param float $scale
36
     */
37 57
    public function __construct(
38
        FieldParserRegistry $fieldParserRegistry,
39
        SimpleXMLElement $xmlHeader,
40
        SimpleXMLElement $xmlField,
41
        $scale
42
    ) {
43 57
        $this->fieldParserRegistry = $fieldParserRegistry;
44 57
        $this->xmlHeader = $xmlHeader;
45 57
        $this->xmlField = $xmlField;
46 57
        $this->scale = $scale;
47 57
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function getFieldType()
53
    {
54
        return (string) $this->xmlField->FldType;
0 ignored issues
show
Bug Best Practice introduced by
The expression return (string)$this->xmlField->FldType returns the type string which is incompatible with the return type mandated by Graze\CiffRenderer\Parse...terface::getFieldType() of Graze\CiffRenderer\Parser\FieldParser\strint.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
55
    }
56
57
    /**
58
     * @return string
59
     */
60 6
    public function getFieldName()
61
    {
62 6
        return (string) $this->xmlField->attributes()->Name;
63
    }
64
65
    /**
66
     * @return int
67
     */
68 6
    public function getPositionX()
69
    {
70 6
        return (int) ($this->xmlField->X * $this->scale);
71
    }
72
73
    /**
74
     * @return int
75
     */
76 6
    public function getPositionY()
77
    {
78 6
        return (int) ($this->xmlField->Y * $this->scale);
79
    }
80
81
    /**
82
     * @return int
83
     */
84 6
    public function getWidth()
85
    {
86 6
        return (int) ($this->xmlField->W * $this->scale);
87
    }
88
89
    /**
90
     * @return int
91
     */
92 6
    public function getHeight()
93
    {
94 6
        return (int) ($this->xmlField->H * $this->scale);
95
    }
96
97
    /**
98
     * @return bool
99
     */
100 6
    public function isDisplayed()
101
    {
102 6
        return (string) $this->xmlField->Displayed != '0';
103
    }
104
105
    /**
106
     * @param FieldParserRegistry $fieldParserRegistry
107
     * @param SimpleXMLElement $xmlHeader
108
     * @param SimpleXMLElement $xmlField
109
     * @param float $scale
110
     * @return FieldParserInterface
111
     */
112 5
    public static function factory(
113
        FieldParserRegistry $fieldParserRegistry,
114
        SimpleXMLElement $xmlHeader,
115
        SimpleXMLElement $xmlField,
116
        $scale
117
    ) {
118 5
        return new static(
119 5
            $fieldParserRegistry,
120 5
            $xmlHeader,
121 5
            $xmlField,
122
            $scale
123 5
        );
124
    }
125
}
126