Completed
Push — master ( fd3130...674c45 )
by John
03:39
created

FieldParserFixedText   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 86.36%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 63
rs 10
c 0
b 0
f 0
ccs 19
cts 22
cp 0.8636
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getOrientation() 0 3 1
A getFontFace() 0 3 1
A getText() 0 17 3
A getFontSize() 0 8 2
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 = 4.2;
15
16
    /**
17
     * @var int
18
     */
19
    const DEFAULT_FONT_SIZE = 13;
20
21
    /**
22
     * @return float
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 $size * 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();
0 ignored issues
show
Bug introduced by
The method getText() does not exist on Graze\CiffRenderer\Parse...er\FieldParserInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Graze\CiffRenderer\Parse...dParserGraphicPrimitive or Graze\CiffRenderer\Parse...ser\AbstractFieldParser or Graze\CiffRenderer\Parse...ieldParserStaticGraphic or Graze\CiffRenderer\Parse...dParserGraphicPrimitive or Graze\CiffRenderer\Parse...ieldParserStaticGraphic. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

61
                /** @scrutinizer ignore-call */ 
62
                $fieldText = $sourceField->getText();
Loading history...
62 2
            } else {
63
                $fieldText = (string) $object->Default; // @codingStandardsIgnoreLine
64
            }
65
66 2
            $text .= $fieldText;
67 2
        }
68
69 2
        return $text;
70
    }
71
}
72