Completed
Pull Request — master (#12)
by Tim
01:31
created

Operation::postDeserialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 3
nc 2
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
28
/**
29
 * The configuration implementation for the options.
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-configuration-jms
35
 * @link      http://www.techdivision.com
36
 */
37
class Operation implements OperationConfigurationInterface
38
{
39
40
    /**
41
     * The operation's name.
42
     *
43
     * @var string
44
     * @Type("string")
45
     */
46
    protected $name;
47
48
    /**
49
     * ArrayCollection with the information of the configured plugins.
50
     *
51
     * @var \Doctrine\Common\Collections\ArrayCollection
52
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Plugin>")
53
     */
54
    protected $plugins;
55
56
    /**
57
     * Initialize the operation with the passed name.
58
     *
59
     * @param string|null $name The operation name
60
     */
61
    public function __construct($name = null)
62
    {
63
        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...
64
            $this->name = $name;
65
        }
66
    }
67
68
    /**
69
     * Lifecycle callback that will be invoked after deserialization.
70
     *
71
     * @return void
72
     * @PostDeserialize
73
     */
74
    public function postDeserialize()
75
    {
76
77
        // create an empty collection if no plugins has been specified
78
        if ($this->plugins === null) {
79
            $this->plugins= new ArrayCollection();
80
        }
81
    }
82
83
    /**
84
     * Query's whether or not the passed operation equals this instance.
85
     *
86
     * @param \TechDivision\Import\Configuration\OperationConfigurationInterface $operation The operation to query
87
     *
88
     * @return boolean TRUE if the operations are equal, else FALSE
89
     */
90
    public function equals(OperationConfigurationInterface $operation)
91
    {
92
        return strcasecmp($this->getName(), $operation->getName()) === 0;
93
    }
94
95
    /**
96
     * Return's the operation's name.
97
     *
98
     * @return string The operation's class name
99
     */
100
    public function getName()
101
    {
102
        return $this->name;
103
    }
104
105
    /**
106
     * Return's the ArrayCollection with the operation's plugins.
107
     *
108
     * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the operation's plugins
109
     */
110
    public function getPlugins()
111
    {
112
        return $this->plugins;
113
    }
114
115
    /**
116
     * String representation of the operation (the name).
117
     *
118
     * @return string The operation name
119
     */
120
    public function __toString()
121
    {
122
        return $this->getName();
123
    }
124
}
125