BusinessEntity::isDisable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Victoire\Bundle\BusinessEntityBundle\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
8
/**
9
 * The business Entity.
10
 *
11
 * @ORM\Entity(repositoryClass="Victoire\Bundle\BusinessEntityBundle\Entity\BusinessEntityRepository")
12
 * @ORM\Table("vic_business_entity")
13
 * @ORM\InheritanceType("SINGLE_TABLE")
14
 * @ORM\DiscriminatorColumn(name="type", type="string")
15
 */
16
abstract class BusinessEntity
0 ignored issues
show
introduced by
Abstract class name is not prefixed with "Abstract"
Loading history...
17
{
18
    /**
19
     * @var int
20
     *
21
     * @ORM\Column(name="id", type="integer")
22
     * @ORM\Id
23
     * @ORM\GeneratedValue(strategy="AUTO")
24
     */
25
    protected $id;
26
27
    /**
28
     * @var string
29
     *
30
     * @ORM\Column(name="name", type="string", length=255)
31
     */
32
    protected $name;
33
34
    /**
35
     * @var BusinessProperty[]
36
     *
37
     * @ORM\OneToMany(targetEntity="Victoire\Bundle\BusinessEntityBundle\Entity\BusinessProperty", mappedBy="businessEntity", cascade={"persist", "remove"})
38
     */
39
    protected $businessProperties;
40
41
    /**
42
     * @var array
43
     *
44
     * @ORM\Column(name="availableWidgets", type="text")
45
     */
46
    protected $availableWidgets;
47
48
    protected $disable = false;
49
50
    public function __construct()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
51
    {
52
        $this->businessProperties = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type array<integer,object<Vic...tity\BusinessProperty>> of property $businessProperties.

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...
53
    }
54
55
    /**
56
     * Get the id.
57
     *
58
     * @return int The id
59
     */
60
    public function getId()
61
    {
62
        return $this->id;
63
    }
64
65
    /**
66
     * Get the name.
67
     *
68
     * @return string The name
69
     */
70
    public function getName()
71
    {
72
        return $this->name;
73
    }
74
75
    /**
76
     * Set the name.
77
     *
78
     * @param string $name
79
     */
80
    public function setName($name)
81
    {
82
        $this->name = $name;
83
    }
84
85
    /**
86
     * Add a business property.
87
     *
88
     * @param BusinessProperty $businessProperty
89
     */
90
    public function addBusinessProperty(BusinessProperty $businessProperty)
91
    {
92
        $this->businessProperties->add($businessProperty);
93
    }
94
95
    /**
96
     * Get the business properties.
97
     *
98
     * @return BusinessProperty[] The business properties
99
     */
100
    public function getBusinessProperties()
101
    {
102
        return $this->businessProperties;
103
    }
104
105
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$name" missing
Loading history...
106
     * Get a business property by name.
107
     *
108
     * @return BusinessProperty|null The business property
109
     */
110
    public function getBusinessPropertyByName($name)
111
    {
112
        foreach ($this->businessProperties as $businessProperty) {
113
            if ($businessProperty->getName() == $name) {
114
                return $businessProperty;
115
            }
116
        }
117
    }
118
119
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$businessProperties" missing
Loading history...
120
     * Get the business properties.
121
     *
122
     * @return array The business properties
123
     */
124
    public function setBusinessProperties($businessProperties)
125
    {
126
        return $this->businessProperties = $businessProperties;
127
    }
128
129
    /**
130
     * Get the business properties by type.
131
     *
132
     * @param string $type
133
     *
134
     * @return ArrayCollection The businnes properties
135
     */
136
    public function getBusinessPropertiesByType($type)
137
    {
138
        if (!is_array($type)) {
139
            $type = [$type];
140
        }
141
        $bp = new ArrayCollection();
142
        foreach ($this->getBusinessProperties() as $property) {
143
            if (count(array_diff($type, $property->getTypes())) == 0) {
144
                $bp->add($property);
145
            }
146
        }
147
148
        return $bp;
149
    }
150
151
    /**
152
     * Get the business properties names by type.
153
     *
154
     *
155
     * @return ArrayCollection The businnes properties
156
     */
157
    public function getBusinessParameters()
158
    {
159
        $bp = new ArrayCollection();
160
        /** @var BusinessProperty $property */
161
        foreach ($this->getBusinessProperties() as $property) {
162
            if ($property->hasType('businessParameter')) {
163
                $bp->add($property);
164
            }
165
        }
166
167
        return $bp;
168
    }
169
170
    /**
171
     * Get the business identifiers.
172
     *
173
     *
174
     * @return ArrayCollection The businnes properties
175
     */
176
    public function getBusinessIdentifiers()
177
    {
178
        $bp = new ArrayCollection();
179
        /** @var BusinessProperty $property */
180
        foreach ($this->getBusinessProperties() as $property) {
181
            if ($property->hasType('businessIdentifier')) {
182
                $bp->add($property);
183
            }
184
        }
185
        if ($bp->count() < 1) {
186
            throw new \Exception(sprintf('The businessEntity %s must have at lease one businessIdentifier property', $this->name));
187
        }
188
189
        return $bp;
190
    }
191
192
    /**
193
     * @return array
194
     */
195
    public function getAvailableWidgets()
196
    {
197
        return unserialize($this->availableWidgets);
198
    }
199
200
    /**
201
     * @param array $availableWidgets
202
     */
203
    public function setAvailableWidgets($availableWidgets)
204
    {
205
        $this->availableWidgets = serialize($availableWidgets);
0 ignored issues
show
Documentation Bug introduced by
It seems like serialize($availableWidgets) of type string is incompatible with the declared type array of property $availableWidgets.

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...
206
    }
207
208
    /**
209
     * @return bool
210
     */
211
    public function isDisable()
212
    {
213
        return $this->disable;
214
    }
215
216
    /**
217
     * @param bool $disable
218
     */
219
    public function setDisable($disable)
220
    {
221
        $this->disable = $disable;
222
    }
223
224
    public function __toString()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
225
    {
226
        return $this->name;
227
    }
228
}
229