Completed
Push — master ( 411d94...8fae9a )
by John
02:59
created

ParserBarcodeItem::getProperties()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 8.8571
c 0
b 0
f 0
ccs 26
cts 26
cp 1
cc 1
eloc 27
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of graze/unicontroller-client.
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/unicontroller-client/blob/master/LICENSE.md
11
 * @link https://github.com/graze/unicontroller-client
12
 */
13
namespace Graze\UnicontrollerClient\Parser\Parser;
14
15
use Graze\UnicontrollerClient\Parser\Parser\AbstractParser;
16
use Graze\UnicontrollerClient\Parser\Parser\ParserInterface;
17
use Graze\UnicontrollerClient\Entity\Entity\EntityBarcodeItem;
18
19
class ParserBarcodeItem extends AbstractParser implements ParserInterface
20
{
21
    /**
22
     * @return []
0 ignored issues
show
Documentation introduced by
The doc-type [] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
23
     */
24 2
    protected function getProperties()
25
    {
26
        return [
27 2
            'anchorPoint',
28 2
            'xPos',
29 2
            'yPos',
30 2
            'height',
31 2
            'orion',
32 2
            'description',
33 2
            'narrow',
34 2
            'inverted',
35 2
            'barcodeType',
36 2
            'data',
37 2
            'humanReadable',
38 2
            'ratio',
39 2
            'frame',
40 2
            'showDropDowns',
41 2
            'fontName',
42 2
            'pointSize',
43 2
            'bold',
44 2
            'italic',
45 2
            'subType',
46 2
            'preferredFormat',
47 2
            'processTilde',
48 2
            'separatorHeight',
49 2
            'segmentWidth',
50 2
            'useHibc',
51
            'phantomField'
52 2
        ];
53
    }
54
55
    /**
56
     * @return EntityBarcodeItem
57
     */
58 2
    protected function getEntity()
59
    {
60 2
        return new EntityBarcodeItem();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return new \Graze\Unicon...ty\EntityBarcodeItem(); (Graze\UnicontrollerClien...ntity\EntityBarcodeItem) is incompatible with the return type declared by the abstract method Graze\UnicontrollerClien...stractParser::getEntity of type Graze\UnicontrollerClien...\Entity\EntityInterface.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
61
    }
62
}
63