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

ParserVarRtc   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0
ccs 19
cts 19
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getProperties() 0 21 1
A getEntity() 0 4 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\EntityVarRtc;
18
19
class ParserVarRtc 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
            'name',
28 2
            'format',
29 2
            'offsetType',
30 2
            'offsetValue',
31 2
            'offset2Type',
32 2
            'offset2Value',
33 2
            'truncateDay',
34 2
            'updatePolicy',
35 2
            'updateDay',
36 2
            'updateHour',
37 2
            'updateMinutte',
38 2
            'language',
39 2
            'variableOffset',
40 2
            'dataSource',
41 2
            'cPadding',
42
            'length'
43 2
        ];
44
    }
45
46
    /**
47
     * @return EntityVarRtc
48
     */
49 2
    protected function getEntity()
50
    {
51 2
        return new EntityVarRtc();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return new \Graze\Unicon...\Entity\EntityVarRtc(); (Graze\UnicontrollerClien...ity\Entity\EntityVarRtc) 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...
52
    }
53
}
54