Completed
Push — master ( fa94c3...68ea33 )
by Tim
02:44
created

Plugin   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 126
ccs 0
cts 28
cp 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getProcessorFactory() 0 4 1
A getUtilityClassName() 0 4 1
A setConfiguration() 0 4 1
A getConfiguration() 0 4 1
A getClassName() 0 4 1
A getSubjects() 0 4 1
A getSwiftMailer() 0 4 1
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
     * The swift mailer configuration to use.
84
     *
85
     * @var \TechDivision\Import\Cli\Configuration\SwiftMailer
86
     * @Type("TechDivision\Import\Cli\Configuration\SwiftMailer")
87
     * @SerializedName("swift-mailer")
88
     */
89
    protected $swiftMailer;
90
91
    /**
92
     * Return's the plugin's processor factory type to use.
93
     *
94
     * @return string The plugin's processor factory type
95
     */
96
    public function getProcessorFactory()
97
    {
98
        return $this->processorFactory;
99
    }
100
101
    /**
102
     * Return's the utility class with the SQL statements to use.
103
     *
104
     * @return string The utility class name
105
     */
106
    public function getUtilityClassName()
107
    {
108
        return $this->utilityClassName;
109
    }
110
111
    /**
112
     * Set's the reference to the configuration instance.
113
     *
114
     * @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance
115
     *
116
     * @return void
117
     */
118
    public function setConfiguration(ConfigurationInterface $configuration)
119
    {
120
        $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...
121
    }
122
123
    /**
124
     * Return's the reference to the configuration instance.
125
     *
126
     * @return \TechDivision\Import\ConfigurationInterface The configuration instance
127
     */
128
    public function getConfiguration()
129
    {
130
        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...
131
    }
132
133
    /**
134
     * Return's the subject's class name.
135
     *
136
     * @return string The subject's class name
137
     */
138
    public function getClassName()
139
    {
140
        return $this->className;
141
    }
142
143
    /**
144
     * Return's the ArrayCollection with the operation's subjects.
145
     *
146
     * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the operation's subjects
147
     */
148
    public function getSubjects()
149
    {
150
        return $this->subjects;
151
    }
152
153
    /**
154
     * Return's the swift mailer configuration to use.
155
     *
156
     * @return TechDivision\Import\Cli\Configuration\SwiftMailer The swift mailer configuration to use
157
     */
158
    public function getSwiftMailer()
159
    {
160
        return $this->swiftMailer;
161
    }
162
}
163