Completed
Pull Request — master (#50)
by Tim
03:01
created

Plugin::getUtilityClassName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Cli\Configuration\Plugin
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-cli-simple
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Cli\Configuration;
22
23
use JMS\Serializer\Annotation\Type;
24
use JMS\Serializer\Annotation\SerializedName;
25
use TechDivision\Import\ConfigurationInterface;
26
use TechDivision\Import\Configuration\PluginConfigurationInterface;
27
28
/**
29
 * A simple plugin configuration implementation.
30
 *
31
 * @author    Tim Wagner <[email protected]>
32
 * @copyright 2016 TechDivision GmbH <[email protected]>
33
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
34
 * @link      https://github.com/techdivision/import-cli-simple
35
 * @link      http://www.techdivision.com
36
 */
37
class Plugin implements PluginConfigurationInterface
38
{
39
40
    /**
41
     * The main configuration.
42
     *
43
     * @var string
44
     */
45
    protected $configuration;
46
47
    /**
48
     * The subject's class name.
49
     *
50
     * @var string
51
     * @Type("string")
52
     * @SerializedName("class-name")
53
     */
54
    protected $className;
55
56
    /**
57
     * ArrayCollection with the information of the configured subjects.
58
     *
59
     * @var \Doctrine\Common\Collections\ArrayCollection
60
     * @Type("ArrayCollection<TechDivision\Import\Cli\Configuration\Subject>")
61
     */
62
    protected $subjects;
63
64
    /**
65
     * The plugin's processor type to use.
66
     *
67
     * @var string
68
     * @Type("string")
69
     * @SerializedName("processor-factory")
70
     */
71
    protected $processorFactory;
72
73
    /**
74
     * The plugin's utility class with the SQL statements to use.
75
     *
76
     * @var string
77
     * @Type("string")
78
     * @SerializedName("utility-class-name")
79
     */
80
    protected $utilityClassName;
81
82
    /**
83
     * Return's the plugin's processor factory type to use.
84
     *
85
     * @return string The plugin's processor factory type
86
     */
87
    public function getProcessorFactory()
88
    {
89
        return $this->processorFactory;
90
    }
91
92
    /**
93
     * Return's the utility class with the SQL statements to use.
94
     *
95
     * @return string The utility class name
96
     */
97
    public function getUtilityClassName()
98
    {
99
        return $this->utilityClassName;
100
    }
101
102
    /**
103
     * Set's the reference to the configuration instance.
104
     *
105
     * @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance
106
     *
107
     * @return void
108
     */
109
    public function setConfiguration(ConfigurationInterface $configuration)
110
    {
111
        $this->configuration = $configuration;
0 ignored issues
show
Documentation Bug introduced by
It seems like $configuration of type object<TechDivision\Impo...ConfigurationInterface> is incompatible with the declared type string of property $configuration.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
112
    }
113
114
    /**
115
     * Return's the reference to the configuration instance.
116
     *
117
     * @return \TechDivision\Import\ConfigurationInterface The configuration instance
118
     */
119
    public function getConfiguration()
120
    {
121
        return $this->configuration;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->configuration; (string) is incompatible with the return type declared by the interface TechDivision\Import\Conf...rface::getConfiguration of type TechDivision\Import\ConfigurationInterface.

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...
122
    }
123
124
    /**
125
     * Return's the subject's class name.
126
     *
127
     * @return string The subject's class name
128
     */
129
    public function getClassName()
130
    {
131
        return $this->className;
132
    }
133
134
    /**
135
     * Return's the ArrayCollection with the operation's subjects.
136
     *
137
     * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the operation's subjects
138
     */
139
    public function getSubjects()
140
    {
141
        return $this->subjects;
142
    }
143
}
144