This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Alpixel\Bundle\MenuBundle\Entity; |
||
4 | |||
5 | use Alpixel\Bundle\MenuBundle\Model\ItemInterface; |
||
6 | use Alpixel\Bundle\MenuBundle\Model\MenuInterface; |
||
7 | use Doctrine\Common\Collections\ArrayCollection; |
||
8 | use Doctrine\ORM\Mapping as ORM; |
||
9 | |||
10 | /** |
||
11 | * @ORM\Table(name="alpixel_menu") |
||
12 | * @ORM\Entity(repositoryClass="Alpixel\Bundle\MenuBundle\Entity\Repository\MenuRepository") |
||
13 | */ |
||
14 | class Menu implements MenuInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var int |
||
18 | * |
||
19 | * @ORM\Column(name="menu_id", type="integer", nullable=false) |
||
20 | * @ORM\Id |
||
21 | * @ORM\GeneratedValue(strategy="IDENTITY") |
||
22 | */ |
||
23 | protected $id; |
||
24 | |||
25 | /** |
||
26 | * @ORM\OneToMany(targetEntity="Alpixel\Bundle\MenuBundle\Entity\Item", mappedBy="menu", fetch="EAGER") |
||
27 | * @ORM\OrderBy({"position": "ASC"}) |
||
28 | */ |
||
29 | protected $items; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | * |
||
34 | * @ORM\Column(name="machine_name", type="string", length=255, nullable=false) |
||
35 | */ |
||
36 | protected $machineName; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | * |
||
41 | * @ORM\Column(name="name", type="string", length=255, nullable=false) |
||
42 | */ |
||
43 | protected $name; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | * |
||
48 | * @ORM\Column(name="locale", type="string", length=10, nullable=false) |
||
49 | */ |
||
50 | protected $locale; |
||
51 | |||
52 | public function __construct() |
||
53 | { |
||
54 | $this->items = new ArrayCollection(); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Get string defined. |
||
59 | * |
||
60 | * @return string |
||
61 | */ |
||
62 | public function __toString() |
||
63 | { |
||
64 | return $this->machineName; |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Get Id. |
||
69 | * |
||
70 | * @return int |
||
71 | */ |
||
72 | public function getId() |
||
73 | { |
||
74 | return $this->id; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Get the machineName the key for querying a menu. |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | public function getMachineName() |
||
83 | { |
||
84 | return $this->machineName; |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Set the machineName the key for querying a menu. |
||
89 | * |
||
90 | * @param string |
||
91 | * |
||
92 | * @return self |
||
93 | */ |
||
94 | public function setMachineName($machineName) |
||
95 | { |
||
96 | $this->machineName = $machineName; |
||
97 | |||
98 | return $this; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Get the name the value displayed to the administrator. |
||
103 | * |
||
104 | * @return self |
||
105 | */ |
||
106 | public function getName() |
||
107 | { |
||
108 | return $this->name; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Set the name the value displayed to the administrator. |
||
113 | * |
||
114 | * @return self |
||
115 | */ |
||
116 | public function setName($name) |
||
117 | { |
||
118 | $this->name = $name; |
||
119 | |||
120 | return $this; |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * Get the items. |
||
125 | * |
||
126 | * @return ArrayCollection of Item object |
||
127 | */ |
||
128 | public function getItems() |
||
129 | { |
||
130 | return $this->items; |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * Remove Item obejct from ArrayCollection items. |
||
135 | * |
||
136 | * @param ItemInterface $item |
||
137 | * |
||
138 | * @return self |
||
139 | */ |
||
140 | public function removeItem(ItemInterface $item) |
||
141 | { |
||
142 | if ($this->items->contains($item) === true) { |
||
143 | $this->items->removeElement($item); |
||
144 | } |
||
145 | |||
146 | return $this; |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * Add Items in items ArrayCollection. |
||
151 | * |
||
152 | * @param ArrayCollection of Item object $items |
||
153 | * |
||
154 | * @return self |
||
155 | */ |
||
156 | public function addItems(ArrayCollection $items) |
||
157 | { |
||
158 | foreach ($items as $item) { |
||
159 | if ($this->items->contains($item) === false) { |
||
160 | $this->setItem($item); |
||
161 | } |
||
162 | } |
||
163 | |||
164 | return $this; |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * Set items for the menu. |
||
169 | * |
||
170 | * @deprecated |
||
171 | * |
||
172 | * @param null\ItemInterface $item |
||
173 | * |
||
174 | * @return Item |
||
175 | */ |
||
176 | public function setItem(ItemInterface $item) |
||
177 | { |
||
178 | return $this->addItem($item); |
||
0 ignored issues
–
show
|
|||
179 | } |
||
180 | |||
181 | /** |
||
182 | * Set items for the menu. |
||
183 | * |
||
184 | * @param null\ItemInterface $item |
||
185 | * |
||
186 | * @return Item |
||
187 | */ |
||
188 | public function addItem(ItemInterface $item) |
||
189 | { |
||
190 | $item->setMenu($this); |
||
191 | $this->items->add($item); |
||
192 | |||
193 | return $this; |
||
194 | } |
||
195 | |||
196 | /** |
||
197 | * Get the locale language. |
||
198 | * |
||
199 | * @return string |
||
200 | */ |
||
201 | public function getLocale() |
||
202 | { |
||
203 | return $this->locale; |
||
204 | } |
||
205 | |||
206 | /** |
||
207 | * Set the locale language. |
||
208 | * |
||
209 | * @return self |
||
210 | */ |
||
211 | public function setLocale($locale) |
||
212 | { |
||
213 | $this->locale = $locale; |
||
214 | |||
215 | return $this; |
||
216 | } |
||
217 | } |
||
218 |
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:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.