Completed
Pull Request — master (#19)
by John
05:56 queued 03:42
created

AbstractFieldParser   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 97
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 12 1
A getFieldName() 0 4 1
A getPositionX() 0 4 1
A getPositionY() 0 4 1
A getWidth() 0 4 1
A getHeight() 0 4 1
A isDisplayed() 0 4 1
A factory() 0 4 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
8
abstract class AbstractFieldParser implements FieldParserInterface
9
{
10
    /**
11
     * @var FieldParserRegistry
12
     */
13
    protected $fieldParserRegistry;
14
15
    /**
16
     * @var \SimpleXMLElement
17
     */
18
    protected $xmlField;
19
20
    /**
21
     * @var \SimpleXMLElement
22
     */
23
    protected $xmlHeader;
24
25
    /**
26
     * @var float
27
     */
28
    protected $scale;
29
30
    /**
31
     * @param FieldParserRegistry $fieldParserRegistry
32
     * @param \SimpleXMLElement $xmlField
33
     * @param \SimpleXMLElement $xmlHeader
34
     * @param float $scale
35
     */
36
    public function parse(
37
        FieldParserRegistry $fieldParserRegistry,
38
        \SimpleXMLElement $xmlField,
39
        \SimpleXMLElement $xmlHeader,
40
        $scale
41
    ) {
42
        $this->fieldParserRegistry = $fieldParserRegistry;
43
        $this->xmlField = $xmlField;
44
        $this->xmlHeader = $xmlHeader;
45
        $this->scale = $scale;
46
        $this->fieldParserRegistry->addParser($this);
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function getFieldName()
53
    {
54
        return (string) $this->xmlField->attributes()->Name;
55
    }
56
57
    /**
58
     * @return int
0 ignored issues
show
Documentation introduced by
Should the return type not be double?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
59
     */
60
    public function getPositionX()
61
    {
62
        return (int) $this->xmlField->X * $this->scale;
63
    }
64
65
    /**
66
     * @return int
0 ignored issues
show
Documentation introduced by
Should the return type not be double?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
67
     */
68
    public function getPositionY()
69
    {
70
        return (int) $this->xmlField->Y * $this->scale;
71
    }
72
73
    /**
74
     * @return int
0 ignored issues
show
Documentation introduced by
Should the return type not be double?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
75
     */
76
    public function getWidth()
77
    {
78
        return (int) $this->xmlField->W * $this->scale;
79
    }
80
81
    /**
82
     * @return int
0 ignored issues
show
Documentation introduced by
Should the return type not be double?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
83
     */
84
    public function getHeight()
85
    {
86
        return (int) $this->xmlField->H * $this->scale;
87
    }
88
89
    /**
90
     * @return bool
91
     */
92
    public function isDisplayed()
93
    {
94
        return (string) $this->xmlField->Displayed != '0';
95
    }
96
97
    /**
98
     * @return FieldParserInterface
99
     */
100
    public static function factory()
101
    {
102
        return new static();
103
    }
104
}
105