Completed
Push — 15.x ( 2d1ea5...d23069 )
by Tim
01:41
created

Operation::getFullName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Configuration\Jms\Configuration\Operation
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-configuration-jms
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Configuration\Jms\Configuration;
22
23
use JMS\Serializer\Annotation\Type;
24
use JMS\Serializer\Annotation\Exclude;
25
use JMS\Serializer\Annotation\PostDeserialize;
26
use Doctrine\Common\Collections\ArrayCollection;
27
use TechDivision\Import\ExecutionContextInterface;
28
use TechDivision\Import\Configuration\OperationConfigurationInterface;
29
use TechDivision\Import\Configuration\ListenerAwareConfigurationInterface;
30
31
/**
32
 * The configuration implementation for the options.
33
 *
34
 * @author    Tim Wagner <[email protected]>
35
 * @copyright 2016 TechDivision GmbH <[email protected]>
36
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
37
 * @link      https://github.com/techdivision/import-configuration-jms
38
 * @link      http://www.techdivision.com
39
 */
40
class Operation implements OperationConfigurationInterface, ListenerAwareConfigurationInterface
41
{
42
43
    /**
44
     * Trait that provides CSV configuration functionality.
45
     *
46
     * @var \TechDivision\Import\Configuration\Jms\Configuration\ListenersTrait
47
     */
48
    use ListenersTrait;
49
50
    /**
51
     * The execution context.
52
     *
53
     * @var \TechDivision\Import\ExecutionContextInterface
54
     */
55
    protected $executionContext;
56
57
    /**
58
     * The operation's name.
59
     *
60
     * @var string
61
     * @Exclude()
62
     */
63
    protected $name;
64
65
    /**
66
     * ArrayCollection with the information of the configured plugins.
67
     *
68
     * @var \Doctrine\Common\Collections\ArrayCollection
69
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Plugin>")
70
     */
71
    protected $plugins;
72
73
    /**
74
     * Initialize the operation with the passed name.
75
     *
76
     * @param string|null $name The operation name
77
     */
78
    public function __construct($name = null)
79
    {
80
        if ($name != null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $name of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
81
            $this->name = $name;
82
        }
83
    }
84
85
    /**
86
     * Lifecycle callback that will be invoked after deserialization.
87
     *
88
     * @return void
89
     * @PostDeserialize
90
     */
91
    public function postDeserialize()
92
    {
93
94
        // create an empty collection if no plugins has been specified
95
        if ($this->plugins === null) {
96
            $this->plugins= new ArrayCollection();
97
        }
98
    }
99
100
    /**
101
     * Query's whether or not the passed operation equals this instance.
102
     *
103
     * @param \TechDivision\Import\Configuration\OperationConfigurationInterface $operation The operation to query
104
     *
105
     * @return boolean TRUE if the operations are equal, else FALSE
106
     */
107
    public function equals(OperationConfigurationInterface $operation)
108
    {
109
        return strcasecmp($this->getName(), $operation->getName()) === 0;
110
    }
111
112
    /**
113
     * Set's the operation's name.
114
     *
115
     * @param string $name The operation's name
116
     *
117
     * @return void
118
     */
119
    public function setName($name)
120
    {
121
        $this->name = $name;
122
    }
123
124
    /**
125
     * Return's the operation's name.
126
     *
127
     * @return string The operation's name
128
     */
129
    public function getName()
130
    {
131
        return $this->name;
132
    }
133
134
    /**
135
     * Return's the ArrayCollection with the operation's plugins.
136
     *
137
     * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the operation's plugins
138
     */
139
    public function getPlugins()
140
    {
141
        return $this->plugins;
142
    }
143
144
    /**
145
     * Set's the execution context configuration for the actualy plugin configuration.
146
     *
147
     * @param \TechDivision\Import\ExecutionContextInterface $executionContext The execution context to use
148
     *
149
     * @return void
150
     */
151
    public function setExecutionContext(ExecutionContextInterface $executionContext)
152
    {
153
        $this->executionContext = $executionContext;
154
    }
155
156
    /**
157
     * Return's the execution context configuration for the actualy plugin configuration.
158
     *
159
     * @return \TechDivision\Import\ExecutionContextInterface The execution context to use
160
     */
161
    public function getExecutionContext()
162
    {
163
        return $this->executionContext;
164
    }
165
166
    /**
167
     * String representation of the operation (the name).
168
     *
169
     * @return string The operation name
170
     */
171
    public function __toString()
172
    {
173
        return $this->getName();
174
    }
175
176
    /**
177
     * Return's the full opration name, which consists of the Magento edition, the entity type code and the operation name.
178
     *
179
     * @param string $separator The separator used to seperate the elements
180
     *
181
     * @return string The full operation name
182
     */
183
    public function getFullName($separator = '/')
184
    {
185
        return implode(
186
            $separator,
187
            array(
188
                $this->getExecutionContext()->getMagentoEdition(),
189
                $this->getExecutionContext()->getEntityTypeCode(),
190
                $this->getName()
191
            )
192
        );
193
    }
194
}
195