Completed
Push — master ( fd3130...674c45 )
by John
03:39
created

AbstractFieldParser::getWidth()   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 $xmlField;
20
21
    /**
22
     * @var SimpleXMLElement
23
     */
24
    protected $xmlHeader;
25
26
    /**
27
     * @var float
28
     */
29
    protected $scale;
30
31
    /**
32
     * @param FieldParserRegistry $fieldParserRegistry
33
     * @param SimpleXMLElement $xmlField
34
     * @param SimpleXMLElement $xmlHeader
35
     * @param float $scale
36
     */
37 49
    public function parse(
38
        FieldParserRegistry $fieldParserRegistry,
39
        SimpleXMLElement $xmlField,
40
        SimpleXMLElement $xmlHeader,
41
        $scale
42
    ) {
43 49
        $this->fieldParserRegistry = $fieldParserRegistry;
44 49
        $this->xmlField = $xmlField;
45 49
        $this->xmlHeader = $xmlHeader;
46 49
        $this->scale = $scale;
47 49
        $this->fieldParserRegistry->addParser($this);
48 49
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getFieldType()
54
    {
55
        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...
56
    }
57
58
    /**
59
     * @return string
60
     */
61 6
    public function getFieldName()
62
    {
63 6
        return (string) $this->xmlField->attributes()->Name;
64
    }
65
66
    /**
67
     * @return int
68
     */
69 6
    public function getPositionX()
70
    {
71 6
        return (int) ($this->xmlField->X * $this->scale);
72
    }
73
74
    /**
75
     * @return int
76
     */
77 6
    public function getPositionY()
78
    {
79 6
        return (int) ($this->xmlField->Y * $this->scale);
80
    }
81
82
    /**
83
     * @return int
84
     */
85 6
    public function getWidth()
86
    {
87 6
        return (int) ($this->xmlField->W * $this->scale);
88
    }
89
90
    /**
91
     * @return int
92
     */
93 6
    public function getHeight()
94
    {
95 6
        return (int) ($this->xmlField->H * $this->scale);
96
    }
97
98
    /**
99
     * @return bool
100
     */
101 6
    public function isDisplayed()
102
    {
103 6
        return (string) $this->xmlField->Displayed != '0';
104
    }
105
106
    /**
107
     * @return FieldParserInterface
108
     */
109 5
    public static function factory()
110
    {
111 5
        return new static();
112
    }
113
}
114