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 Anax\Events; |
||
4 | |||
5 | /** |
||
6 | * A controller for Events. |
||
7 | * |
||
8 | */ |
||
9 | class EventController implements \Anax\DI\IInjectionAware |
||
10 | { |
||
11 | use \Anax\DI\TInjectable; |
||
12 | |||
13 | |||
14 | /** |
||
15 | * View the calendar. |
||
16 | * |
||
17 | * @return void |
||
18 | */ |
||
19 | public function initialize() |
||
20 | { |
||
21 | $this->events = new \Anax\Events\Event(); |
||
0 ignored issues
–
show
|
|||
22 | $this->events->setDI($this->di); |
||
0 ignored issues
–
show
It seems like
$this->di can also be of type array or null ; however, Anax\DI\TInjectable::setDI() does only seem to accept object , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
23 | } |
||
24 | |||
25 | /** |
||
26 | * Initialize the controller. |
||
27 | * |
||
28 | * @return void |
||
29 | */ |
||
30 | |||
31 | public function viewAction(){ |
||
0 ignored issues
–
show
viewAction uses the super-global variable $_GET which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
32 | |||
33 | $this->initialize(); |
||
34 | $calendar = new \Anax\Calendar\CCalendar(); |
||
35 | $calendar->getValues(); |
||
36 | $calendar->generateCalenderData(); |
||
37 | $month = $calendar->getMonthNumber(); |
||
38 | $year = $calendar->getYear(); |
||
39 | |||
40 | $date = $this->dispatcher->getParam('date'); |
||
0 ignored issues
–
show
The property
dispatcher does not exist on object<Anax\Events\EventController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
41 | $_GET = array(); |
||
42 | $currentDate = $year ."-". $month ."-". sprintf('%02s',$date); |
||
43 | |||
44 | |||
45 | $events = $this->events->findEventsOfDay($currentDate); |
||
46 | $eventCount = $this->events->getEventCountPerDayOfMonth($month); |
||
47 | |||
48 | $form = new \Mos\HTMLForm\CForm(); |
||
49 | |||
50 | $form = $form->create([], [ |
||
51 | 'title' => [ |
||
52 | 'type' => 'text', |
||
53 | 'label' => 'Title', |
||
54 | 'required' => true, |
||
55 | 'validation' => ['not_empty'], |
||
56 | ], |
||
57 | 'time' => [ |
||
58 | 'type' => 'date', |
||
59 | 'label' => 'Date for event', |
||
60 | 'required' => true, |
||
61 | 'validation' => ['not_empty'], |
||
62 | ], |
||
63 | 'content' => [ |
||
64 | 'type' => 'textarea', |
||
65 | 'label' => 'Content', |
||
66 | 'required' => true, |
||
67 | 'validation' => ['not_empty'], |
||
68 | ], |
||
69 | 'submit' => [ |
||
70 | 'type' => 'submit', |
||
71 | 'callback' => function($form) { |
||
72 | $form->saveInSession = true; |
||
73 | return true; |
||
74 | } |
||
75 | ], |
||
76 | ]); |
||
77 | |||
78 | // Check the status of the form |
||
79 | $status = $form->check(); |
||
80 | |||
81 | View Code Duplication | if ($status === true) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
82 | |||
83 | $this->dispatcher->forward([ |
||
0 ignored issues
–
show
The property
dispatcher does not exist on object<Anax\Events\EventController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
84 | 'controller' => 'event', |
||
85 | 'action' => 'add', |
||
86 | ]); |
||
87 | |||
88 | } else if ($status === false) { |
||
89 | |||
90 | var_dump('Check method returned false'); |
||
0 ignored issues
–
show
|
|||
91 | die; |
||
0 ignored issues
–
show
The method
viewAction() contains an exit expression.
An exit expression should only be used in rare cases. For example, if you write a short command line script. In most cases however, using an ![]() |
|||
92 | } |
||
93 | |||
94 | $this->views->add('calendar/calendar', [ |
||
0 ignored issues
–
show
The property
views does not exist on object<Anax\Events\EventController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
95 | 'content' => $calendar->printResponsiveCalendar($eventCount), |
||
96 | 'form' => $form->getHTML(), |
||
97 | 'events' => $events, |
||
98 | ]); |
||
99 | |||
100 | } |
||
101 | |||
102 | public function addAction(){ |
||
103 | |||
104 | $now = gmdate('Y-m-d H:i:s'); |
||
105 | |||
106 | $calendar = new \Anax\Calendar\CCalendar(); |
||
107 | $calendar->getValues(); |
||
108 | $calendar->generateCalenderData(); |
||
109 | $month = $calendar->getMonth(); |
||
110 | $year = $calendar->getYear(); |
||
111 | $day = $this->request->getPost('time'); |
||
0 ignored issues
–
show
The property
request does not exist on object<Anax\Events\EventController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
112 | |||
113 | $this->events->save([ |
||
114 | 'id' => $this->request->getPost('id'), |
||
0 ignored issues
–
show
The property
request does not exist on object<Anax\Events\EventController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
115 | 'title' => $this->request->getPost('title'), |
||
0 ignored issues
–
show
The property
request does not exist on object<Anax\Events\EventController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
116 | 'showdate' => $this->request->getPost('time'), |
||
0 ignored issues
–
show
The property
request does not exist on object<Anax\Events\EventController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
117 | 'content' => $this->request->getPost('content'), |
||
0 ignored issues
–
show
The property
request does not exist on object<Anax\Events\EventController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
118 | 'created' => $now, |
||
119 | ]); |
||
120 | $redirect = "calendar?month=$month&year=$year&date=$day"; |
||
121 | $url = $this->url->create($redirect); |
||
0 ignored issues
–
show
The property
url does not exist on object<Anax\Events\EventController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
122 | $this->response->redirect($url); |
||
0 ignored issues
–
show
The property
response does not exist on object<Anax\Events\EventController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
123 | |||
124 | } |
||
125 | |||
126 | public function findEventsAction() |
||
127 | { |
||
128 | |||
129 | $this->initialize(); |
||
130 | |||
131 | $reslut = $this->events->findEventsOfDay(); |
||
132 | |||
133 | $this->views->add('calendar/calendar', [ |
||
0 ignored issues
–
show
The property
views does not exist on object<Anax\Events\EventController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
134 | 'events' => $reslut, |
||
135 | ]); |
||
136 | |||
137 | $url = $this->url->create('calendar'); |
||
0 ignored issues
–
show
The property
url does not exist on object<Anax\Events\EventController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
138 | $this->response->redirect($url); |
||
0 ignored issues
–
show
The property
response does not exist on object<Anax\Events\EventController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
139 | |||
140 | |||
141 | } |
||
142 | public function deleteAction($id = null) |
||
143 | { |
||
144 | $this->initialize(); |
||
145 | |||
146 | if (!isset($id)) { |
||
147 | die("Missing id"); |
||
0 ignored issues
–
show
The method
deleteAction() contains an exit expression.
An exit expression should only be used in rare cases. For example, if you write a short command line script. In most cases however, using an ![]() |
|||
148 | } |
||
149 | |||
150 | $this->events->delete($id); |
||
151 | |||
152 | $url = $this->url->create('calendar'); |
||
0 ignored issues
–
show
The property
url does not exist on object<Anax\Events\EventController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
153 | $this->response->redirect($url); |
||
0 ignored issues
–
show
The property
response does not exist on object<Anax\Events\EventController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
154 | } |
||
155 | |||
156 | |||
157 | public function idAction($id = null) |
||
158 | { |
||
159 | $this->initialize(); |
||
160 | |||
161 | $event = $this->events->find($id); |
||
162 | |||
163 | $form = new \Mos\HTMLForm\CForm(); |
||
164 | |||
165 | $form = $form->create([], [ |
||
166 | 'id' => [ |
||
167 | 'type' => 'hidden', |
||
168 | 'required' => true, |
||
169 | 'validation' => ['not_empty'], |
||
170 | 'value' => $id |
||
171 | ], |
||
172 | 'title' => [ |
||
173 | 'class' => 'form-control', |
||
174 | 'type' => 'text', |
||
175 | 'label' => 'Title', |
||
176 | 'value' => $event->title, |
||
177 | 'required' => true, |
||
178 | 'validation' => ['not_empty'], |
||
179 | ], |
||
180 | 'time' => [ |
||
181 | 'class' => 'form-control', |
||
182 | 'type' => 'date', |
||
183 | 'label' => 'Date for event', |
||
184 | 'value' => $event->showdate, |
||
185 | 'required' => true, |
||
186 | 'validation' => ['not_empty'], |
||
187 | ], |
||
188 | 'content' => [ |
||
189 | 'class' => 'form-control', |
||
190 | 'type' => 'textarea', |
||
191 | 'label' => 'Content', |
||
192 | 'value' => $event->content, |
||
193 | 'required' => true, |
||
194 | 'validation' => ['not_empty'], |
||
195 | ], |
||
196 | 'submit' => [ |
||
197 | 'class' => 'btn btn-default', |
||
198 | 'type' => 'submit', |
||
199 | 'value' => 'Update', |
||
200 | 'callback' => function($form) { |
||
201 | $form->saveInSession = true; |
||
202 | return true; |
||
203 | } |
||
204 | ], |
||
205 | ]); |
||
206 | |||
207 | // Check the status of the form |
||
208 | $status = $form->check(); |
||
209 | |||
210 | if ($status === true) { |
||
211 | |||
212 | $this->dispatcher->forward([ |
||
0 ignored issues
–
show
The property
dispatcher does not exist on object<Anax\Events\EventController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
213 | 'controller' => 'event', |
||
214 | 'action' => 'add', |
||
215 | 'params' => ['id' => $id], |
||
216 | ]); |
||
217 | |||
218 | } else if ($status === false) { |
||
219 | |||
220 | var_dump('Check method returned false'); |
||
0 ignored issues
–
show
|
|||
221 | die; |
||
0 ignored issues
–
show
The method
idAction() contains an exit expression.
An exit expression should only be used in rare cases. For example, if you write a short command line script. In most cases however, using an ![]() |
|||
222 | } |
||
223 | |||
224 | $this->theme->setTitle("View event with id"); |
||
0 ignored issues
–
show
The property
theme does not exist on object<Anax\Events\EventController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
225 | $this->views->add('calendar/view', [ |
||
0 ignored issues
–
show
The property
views does not exist on object<Anax\Events\EventController> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
226 | 'event' => $event, |
||
227 | 'form' => $form->getHTML() |
||
228 | ]); |
||
229 | } |
||
230 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: