Completed
Push — 15.x ( a8a0e5...d73106 )
by Tim
01:34
created

Operation::getExecutionContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\PostDeserialize;
25
use Doctrine\Common\Collections\ArrayCollection;
26
use TechDivision\Import\Configuration\OperationConfigurationInterface;
27
use TechDivision\Import\Configuration\ListenerAwareConfigurationInterface;
28
use TechDivision\Import\Configuration\ExecutionContextConfigurationInterface;
29
30
/**
31
 * The configuration implementation for the options.
32
 *
33
 * @author    Tim Wagner <[email protected]>
34
 * @copyright 2016 TechDivision GmbH <[email protected]>
35
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
36
 * @link      https://github.com/techdivision/import-configuration-jms
37
 * @link      http://www.techdivision.com
38
 */
39
class Operation implements OperationConfigurationInterface, ListenerAwareConfigurationInterface
40
{
41
42
    /**
43
     * Trait that provides CSV configuration functionality.
44
     *
45
     * @var \TechDivision\Import\Configuration\Jms\Configuration\ListenersTrait
46
     */
47
    use ListenersTrait;
48
49
    /**
50
     * The execution context.
51
     *
52
     * @var \TechDivision\Import\Configuration\ExecutionContextConfigurationInterface
53
     */
54
    protected $executionContext;
55
56
    /**
57
     * The operation's name.
58
     *
59
     * @var string
60
     * @Type("string")
61
     */
62
    protected $name;
63
64
    /**
65
     * ArrayCollection with the information of the configured plugins.
66
     *
67
     * @var \Doctrine\Common\Collections\ArrayCollection
68
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Plugin>")
69
     */
70
    protected $plugins;
71
72
    /**
73
     * Initialize the operation with the passed name.
74
     *
75
     * @param string|null $name The operation name
76
     */
77
    public function __construct($name = null)
78
    {
79
        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...
80
            $this->name = $name;
81
        }
82
    }
83
84
    /**
85
     * Lifecycle callback that will be invoked after deserialization.
86
     *
87
     * @return void
88
     * @PostDeserialize
89
     */
90
    public function postDeserialize()
91
    {
92
93
        // create an empty collection if no plugins has been specified
94
        if ($this->plugins === null) {
95
            $this->plugins= new ArrayCollection();
96
        }
97
    }
98
99
    /**
100
     * Query's whether or not the passed operation equals this instance.
101
     *
102
     * @param \TechDivision\Import\Configuration\OperationConfigurationInterface $operation The operation to query
103
     *
104
     * @return boolean TRUE if the operations are equal, else FALSE
105
     */
106
    public function equals(OperationConfigurationInterface $operation)
107
    {
108
        return strcasecmp($this->getName(), $operation->getName()) === 0;
109
    }
110
111
    /**
112
     * Return's the operation's name.
113
     *
114
     * @return string The operation's class name
115
     */
116
    public function getName()
117
    {
118
        return $this->name;
119
    }
120
121
    /**
122
     * Return's the ArrayCollection with the operation's plugins.
123
     *
124
     * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the operation's plugins
125
     */
126
    public function getPlugins()
127
    {
128
        return $this->plugins;
129
    }
130
131
    /**
132
     * Set's the execution context configuration for the actualy plugin configuration.
133
     *
134
     * @param \TechDivision\Import\Configuration\ExecutionContextConfigurationInterface $executionContext The execution context to use
135
     *
136
     * @return void
137
     */
138
    public function setExecutionContext(ExecutionContextConfigurationInterface $executionContext)
139
    {
140
        $this->executionContext = $executionContext;
141
    }
142
143
    /**
144
     * Return's the execution context configuration for the actualy plugin configuration.
145
     *
146
     * @return \TechDivision\Import\Configuration\ExecutionContextConfigurationInterface The execution context to use
147
     */
148
    public function getExecutionContext()
149
    {
150
        return $this->executionContext;
151
    }
152
153
    /**
154
     * String representation of the operation (the name).
155
     *
156
     * @return string The operation name
157
     */
158
    public function __toString()
159
    {
160
        return $this->getName();
161
    }
162
}
163