Passed
Push — master ( 0a5d2b...01a422 )
by Burhan
02:24
created

FieldParserComplexText::getTextAlignment()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.1406

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 8
ccs 3
cts 4
cp 0.75
crap 3.1406
rs 10
1
<?php
2
3
namespace Graze\CiffRenderer\Parser\FieldParser;
4
5
class FieldParserComplexText extends AbstractFieldParser implements FieldParserInterface
6
{
7
    /**
8
     * Increase Ciff's 'pitch' value to approximate size in pixels.
9
     *
10
     * @var float
11
     */
12
    const FONT_SIZE_MULTIPLIER = 35;
13
14
    /**
15
     * @var int
16
     */
17
    const DEFAULT_FONT_SIZE = 13;
18
19
    /**
20
     * @var string
21
     */
22
    const ALIGN_LEFT = 'left';
23
24
    /**
25
     * @var string
26
     */
27
    const ALIGN_CENTRE = 'center';
28
29
    /**
30
     * @var string
31
     */
32
    const ALIGN_RIGHT = 'right';
33
34
    /**
35
     * @return int
36
     */
37 1
    public function getFontSize()
38
    {
39 1
        $size = (float) $this->xmlField->Text->Font->Pitch;
40 1
        if (!$size) {
41
            $size = self::DEFAULT_FONT_SIZE;
42
        }
43
44 1
        return (int) round($size * $this->scale * self::FONT_SIZE_MULTIPLIER);
45
    }
46
47
    /**
48
     * @return string
49
     */
50 1
    public function getFontFace()
51
    {
52 1
        return (string) $this->xmlField->Text->Font->Face;
53
    }
54
55
    /**
56
     * @return int
57
     */
58 1
    public function getOrientation()
59
    {
60 1
        return (int) $this->xmlField->Orientation;
61
    }
62
63
    /**
64
     * @return string
65
     */
66 1
    public function getText()
67
    {
68 1
        $text = '';
69 1
        foreach ($this->xmlField->Data->Object as $object) {
70 1
            if ($object->SrcField) { // @codingStandardsIgnoreLine
71
                // Field is a merge field, fetch text from source field
72 1
                $sourceFieldName = (string) $object->SrcField->attributes()->SrcFieldName; // @codingStandardsIgnoreLine
73 1
                $sourceField = $this->fieldParserRegistry->getParser($sourceFieldName);
74 1
                $fieldText = $sourceField->getText();
75
            } else {
76
                $fieldText = (string) $object->Default; // @codingStandardsIgnoreLine
77
            }
78
79 1
            $text .= $fieldText;
80
        }
81
82 1
        return $text;
83
    }
84
85
    /**
86
     * @return string
87
     */
88 1
    public function getTextAlignment()
89
    {
90 1
        if ($this->xmlField->Text->Block && $this->xmlField->Text->Block->BlkJustify) {
91 1
            return strtolower((string) $this->xmlField->Text->Block->BlkJustify);
92
        }
93
94
        // default to left align
95
        return self::ALIGN_LEFT;
96
    }
97
}
98