Passed
Push — support-right-aligned-text-OPS... ( bdcf8a )
by John
04:16 queued 20s
created

FieldParserFixedText::getText()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.0052

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 3
nop 0
dl 0
loc 17
rs 9.9332
c 0
b 0
f 0
ccs 11
cts 12
cp 0.9167
crap 3.0052
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
     * @var string
23
     */
24
    const ALIGN_LEFT = 'left';
25
26
    /**
27
     * @var string
28
     */
29
    const ALIGN_CENTRE = 'center';
30
31
    /**
32
     * @var string
33
     */
34
    const ALIGN_RIGHT = 'right';
35
36
    /**
37
     * @return int
38
     */
39 1
    public function getFontSize()
40
    {
41 1
        $size = (float) $this->xmlField->Text->Font->Pitch;
42 1
        if (!$size) {
43
            $size = self::DEFAULT_FONT_SIZE;
44
        }
45
46 1
        return (int) round($size * $this->scale * self::FONT_SIZE_MULTIPLIER);
47
    }
48
49
    /**
50
     * @return string
51
     */
52 1
    public function getFontFace()
53
    {
54 1
        return (string) $this->xmlField->Text->Font->Face;
55
    }
56
57
    /**
58
     * @return int
59
     */
60 2
    public function getOrientation()
61
    {
62 2
        return (int) $this->xmlField->Orientation;
63
    }
64
65
    /**
66
     * @return string
67
     */
68 2
    public function getText()
69
    {
70 2
        $text = '';
71 2
        foreach ($this->xmlField->Data->Object as $object) {
72 2
            if ($object->SrcField) { // @codingStandardsIgnoreLine
73
                // Field is a merge field, fetch text from source field
74 2
                $sourceFieldName = (string) $object->SrcField->attributes()->SrcFieldName; // @codingStandardsIgnoreLine
75 2
                $sourceField = $this->fieldParserRegistry->getParser($sourceFieldName);
76 2
                $fieldText = $sourceField->getText();
77 2
            } else {
78
                $fieldText = (string) $object->Default; // @codingStandardsIgnoreLine
79
            }
80
81 2
            $text .= $fieldText;
82 2
        }
83
84 2
        return $text;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getTextAlignment()
91
    {
92
        if ($this->xmlField->Text->Block && $this->xmlField->Text->Block->BlkJustify) {
93
            return strtolower((string) $this->xmlField->Text->Block->BlkJustify);
94
        }
95
96
        // default to left align
97
        return FieldParserFixedText::ALIGN_LEFT;
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
98
    }
99
}
100