Completed
Push — refactor-04-parser-tests ( dc4950...bd4663 )
by John
06:06
created

FieldParserFixedText   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 48
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFontSize() 0 4 1
A getFontFace() 0 4 1
A getOrientation() 0 4 1
A getText() 0 18 3
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
     * @return float
11
     */
12 1
    public function getFontSize()
13
    {
14 1
        return (float) $this->xmlField->Text->Font->Pitch;
0 ignored issues
show
Bug introduced by
Accessing Text on the interface Graze\CiffRenderer\Parse...mpleXmlElementInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
15
    }
16
17
    /**
18
     * @return string
19
     */
20 2
    public function getFontFace()
21
    {
22 2
        return (string) $this->xmlField->Text->Font->Face;
0 ignored issues
show
Bug introduced by
Accessing Text on the interface Graze\CiffRenderer\Parse...mpleXmlElementInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
23
    }
24
25
    /**
26
     * @return int
27
     */
28 3
    public function getOrientation()
29
    {
30 3
        return (int) $this->xmlField->Orientation;
0 ignored issues
show
Bug introduced by
Accessing Orientation on the interface Graze\CiffRenderer\Parse...mpleXmlElementInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
31
    }
32
33
    /**
34
     * @return string
35
     */
36 2
    public function getText()
37
    {
38 2
        $text = '';
39 2
        foreach ($this->xmlField->Data->Object as $object) {
0 ignored issues
show
Bug introduced by
Accessing Data on the interface Graze\CiffRenderer\Parse...mpleXmlElementInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
40 2
            if ($object->SrcField) { // @codingStandardsIgnoreLine
41
                // Field is a merge field, fetch text from source field
42 2
                $sourceFieldName = (string) $object->SrcField->attributes()->SrcFieldName; // @codingStandardsIgnoreLine
43 2
                $sourceField = $this->fieldParserRegistry->getParser($sourceFieldName);
44 2
                $fieldText = $sourceField->getText();
45
            } else {
46 2
                $fieldText = (string) $object->Default; // @codingStandardsIgnoreLine
47
            }
48
49 2
            $text .= $fieldText;
50
        }
51
52 2
        return $text;
53
    }
54
}
55