Completed
Pull Request — master (#19)
by John
09:10 queued 04:43
created

ParserDocument::getScale()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Graze\CiffRenderer\Parser;
4
5
use Graze\CiffRenderer\Parser\FieldSorter;
6
use Graze\CiffRenderer\Parser\FieldParser\FieldParserFactory;
7
use \SimpleXMLElement;
8
9
class ParserDocument
10
{
11
    /**
12
     * @var FieldSorter
13
     */
14
    private $fieldSorter;
15
16
    /**
17
     * @var FieldParserFactory
18
     */
19
    private $fieldParserFactory;
20
21
    /**
22
     * @var FieldParserRegistry
23
     */
24
    private $fieldParserRegistry;
25
26
    /**
27
     * @param FieldSorter $fieldSorter
28
     * @param FieldParserFactory $fieldParserFactory
29
     * @param FieldParserRegistry $fieldParserRegistry
30
     */
31
    public function __construct(
32
        FieldSorter $fieldSorter,
33
        FieldParserFactory $fieldParserFactory,
34
        FieldParserRegistry $fieldParserRegistry
35
    ) {
36
        $this->fieldSorter = $fieldSorter;
37
        $this->fieldParserFactory = $fieldParserFactory;
38
        $this->fieldParserRegistry = $fieldParserRegistry;
39
    }
40
41
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$xml" missing
Loading history...
42
     * @return ParserInterface[]
43
     */
44
    public function getFieldParsers(SimpleXMLElement $xml)
45
    {
46
        $subImage = (array) $xml->SubImage;
0 ignored issues
show
Coding Style introduced by
The variable $SubImage should be in camel caps format.
Loading history...
47
        $fields = $this->fieldSorter->sort($subImage['Field']);
48
        $parsers = [];
49
        foreach ($fields as $field) {
50
            $parser = $this->fieldParserFactory->getFieldParser($field);
51
            $parser->parse($this->fieldParserRegistry, $field, $xml->Header, $this->getScale($xml));
0 ignored issues
show
Coding Style introduced by
The variable $Header should be in camel caps format.
Loading history...
52
            $parsers[] = $parser;
53
        }
54
55
        return $parsers;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $parsers returns an array which contains values of type Graze\CiffRenderer\Parse...er\FieldParserInterface which are incompatible with the documented value type Graze\CiffRenderer\Parser\ParserInterface.
Loading history...
56
    }
57
58
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$xml" missing
Loading history...
59
     * @return float
60
     */
61
    public function getWidth(SimpleXMLElement $xml)
62
    {
63
        return (float) $xml->SubImage->SubHeader->ImageWidth * $this->getScale($xml);
0 ignored issues
show
Coding Style introduced by
The variable $SubImage should be in camel caps format.
Loading history...
64
    }
65
66
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$xml" missing
Loading history...
67
     * @return float
68
     */
69
    public function getHeight(SimpleXMLElement $xml)
70
    {
71
        return (float) $xml->SubImage->SubHeader->ImageHeight * $this->getScale($xml);
0 ignored issues
show
Coding Style introduced by
The variable $SubImage should be in camel caps format.
Loading history...
72
    }
73
74
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$xml" missing
Loading history...
75
     * @return float
76
     */
77
    public function getScale(SimpleXMLElement $xml)
78
    {
79
        return (float) $xml->SubImage->SubHeader->XRes;
0 ignored issues
show
Coding Style introduced by
The variable $SubImage should be in camel caps format.
Loading history...
80
    }
81
82
    /**
83
     * @return ParserDocument
84
     */
85
    public static function factory()
86
    {
87
        return new static(
88
            new FieldSorter(),
89
            new FieldParserFactory(),
90
            new FieldParserRegistry()
91
        );
92
    }
93
}
94