Passed
Pull Request — master (#34)
by Harry
03:47 queued 01:52
created

FieldParserFixedText::getFontSize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 8
ccs 4
cts 5
cp 0.8
crap 2.032
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
7
class FieldParserFixedText extends AbstractFieldParser implements FieldParserInterface
8
{
9
    /**
10
     * Increase Ciff's 'pitch' value to approximate size in pixels.
11
     *
12
     * @var float
13
     */
14
    const FONT_SIZE_MULTIPLIER = 35;
15
16
    /**
17
     * @var int
18
     */
19
    const DEFAULT_FONT_SIZE = 13;
20
21
    /**
22
     * @return int
23
     */
24 1
    public function getFontSize()
25
    {
26 1
        $size = (float) $this->xmlField->Text->Font->Pitch;
27 1
        if (!$size) {
28
            $size = self::DEFAULT_FONT_SIZE;
29
        }
30
31 1
        return (int) round($size * $this->scale * self::FONT_SIZE_MULTIPLIER);
32
    }
33
34
    /**
35
     * @return string
36
     */
37 1
    public function getFontFace()
38
    {
39 1
        return (string) $this->xmlField->Text->Font->Face;
40
    }
41
42
    /**
43
     * @return int
44
     */
45 2
    public function getOrientation()
46
    {
47 2
        return (int) $this->xmlField->Orientation;
48
    }
49
50
    /**
51
     * @return string
52
     */
53 2
    public function getText()
54
    {
55 2
        $text = '';
56 2
        foreach ($this->xmlField->Data->Object as $object) {
57 2
            if ($object->SrcField) { // @codingStandardsIgnoreLine
58
                // Field is a merge field, fetch text from source field
59 2
                $sourceFieldName = (string) $object->SrcField->attributes()->SrcFieldName; // @codingStandardsIgnoreLine
60 2
                $sourceField = $this->fieldParserRegistry->getParser($sourceFieldName);
61 2
                $fieldText = $sourceField->getText();
62
            } else {
63
                $fieldText = (string) $object->Default; // @codingStandardsIgnoreLine
64
            }
65
66 2
            $text .= $fieldText;
67
        }
68
69 2
        return $text;
70
    }
71
}
72