These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
|||||||||||
2 | /** |
|||||||||||
3 | * @package Arastta eCommerce |
|||||||||||
4 | * @copyright 2015-2017 Arastta Association. All rights reserved. |
|||||||||||
5 | * @copyright See CREDITS.txt for credits and other copyright notices. |
|||||||||||
6 | * @license GNU GPL version 3; see LICENSE.txt |
|||||||||||
7 | * @link https://arastta.org |
|||||||||||
8 | */ |
|||||||||||
9 | ||||||||||||
10 | class ControllerBlogCategory extends Controller |
|||||||||||
11 | { |
|||||||||||
12 | private $error = array(); |
|||||||||||
13 | ||||||||||||
14 | View Code Duplication | public function index() |
||||||||||
15 | { |
|||||||||||
16 | $this->load->language('blog/category'); |
|||||||||||
17 | ||||||||||||
18 | $this->document->setTitle($this->language->get('heading_title')); |
|||||||||||
19 | ||||||||||||
20 | $this->load->model('blog/category'); |
|||||||||||
21 | ||||||||||||
22 | $this->getList(); |
|||||||||||
23 | } |
|||||||||||
24 | ||||||||||||
25 | public function add() |
|||||||||||
26 | { |
|||||||||||
27 | $this->load->language('blog/category'); |
|||||||||||
28 | ||||||||||||
29 | $this->document->setTitle($this->language->get('heading_title')); |
|||||||||||
30 | ||||||||||||
31 | $this->load->model('blog/category'); |
|||||||||||
32 | ||||||||||||
33 | if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { |
|||||||||||
34 | $category_id = $this->model_blog_category->addCategory($this->request->post); |
|||||||||||
35 | ||||||||||||
36 | $this->session->data['success'] = $this->language->get('text_success'); |
|||||||||||
37 | ||||||||||||
38 | $url = ''; |
|||||||||||
39 | ||||||||||||
40 | if (isset($this->request->get['filter_name'])) { |
|||||||||||
41 | $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); |
|||||||||||
42 | } |
|||||||||||
43 | ||||||||||||
44 | if (isset($this->request->get['filter_status'])) { |
|||||||||||
45 | $url .= '&filter_status=' . $this->request->get['filter_status']; |
|||||||||||
46 | } |
|||||||||||
47 | ||||||||||||
48 | if (isset($this->request->get['sort'])) { |
|||||||||||
49 | $url .= '&sort=' . $this->request->get['sort']; |
|||||||||||
50 | } |
|||||||||||
51 | ||||||||||||
52 | if (isset($this->request->get['order'])) { |
|||||||||||
53 | $url .= '&order=' . $this->request->get['order']; |
|||||||||||
54 | } |
|||||||||||
55 | ||||||||||||
56 | if (isset($this->request->get['page'])) { |
|||||||||||
57 | $url .= '&page=' . $this->request->get['page']; |
|||||||||||
58 | } |
|||||||||||
59 | ||||||||||||
60 | if (isset($this->request->post['button']) and $this->request->post['button'] == 'save') { |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
61 | $this->response->redirect($this->url->link('blog/category/edit', 'category_id=' . $category_id . '&token=' . $this->session->data['token'] . $url, 'SSL')); |
|||||||||||
62 | } |
|||||||||||
63 | ||||||||||||
64 | if (isset($this->request->post['button']) and $this->request->post['button'] == 'new') { |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
65 | $this->response->redirect($this->url->link('blog/category/add', 'token=' . $this->session->data['token'] . $url, 'SSL')); |
|||||||||||
66 | } |
|||||||||||
67 | ||||||||||||
68 | $this->response->redirect($this->url->link('blog/category', 'token=' . $this->session->data['token'], 'SSL')); |
|||||||||||
69 | } |
|||||||||||
70 | ||||||||||||
71 | $this->getForm(); |
|||||||||||
72 | } |
|||||||||||
73 | ||||||||||||
74 | public function edit() |
|||||||||||
75 | { |
|||||||||||
76 | $this->load->language('blog/category'); |
|||||||||||
77 | ||||||||||||
78 | $this->document->setTitle($this->language->get('heading_title')); |
|||||||||||
79 | ||||||||||||
80 | $this->load->model('blog/category'); |
|||||||||||
81 | ||||||||||||
82 | if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { |
|||||||||||
83 | $this->model_blog_category->editCategory($this->request->get['category_id'], $this->request->post); |
|||||||||||
84 | ||||||||||||
85 | $this->session->data['success'] = $this->language->get('text_success'); |
|||||||||||
86 | ||||||||||||
87 | $url = ''; |
|||||||||||
88 | ||||||||||||
89 | if (isset($this->request->get['filter_name'])) { |
|||||||||||
90 | $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); |
|||||||||||
91 | } |
|||||||||||
92 | ||||||||||||
93 | if (isset($this->request->get['filter_status'])) { |
|||||||||||
94 | $url .= '&filter_status=' . $this->request->get['filter_status']; |
|||||||||||
95 | } |
|||||||||||
96 | ||||||||||||
97 | if (isset($this->request->get['sort'])) { |
|||||||||||
98 | $url .= '&sort=' . $this->request->get['sort']; |
|||||||||||
99 | } |
|||||||||||
100 | ||||||||||||
101 | if (isset($this->request->get['order'])) { |
|||||||||||
102 | $url .= '&order=' . $this->request->get['order']; |
|||||||||||
103 | } |
|||||||||||
104 | ||||||||||||
105 | if (isset($this->request->get['page'])) { |
|||||||||||
106 | $url .= '&page=' . $this->request->get['page']; |
|||||||||||
107 | } |
|||||||||||
108 | ||||||||||||
109 | if (isset($this->request->post['button']) and $this->request->post['button'] == 'save') { |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
110 | $this->response->redirect($this->url->link('blog/category/edit', 'category_id=' . $this->request->get['category_id'] . '&token=' . $this->session->data['token'] . $url, 'SSL')); |
|||||||||||
111 | } |
|||||||||||
112 | ||||||||||||
113 | if (isset($this->request->post['button']) and $this->request->post['button'] == 'new') { |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
114 | $this->response->redirect($this->url->link('blog/category/add', 'token=' . $this->session->data['token'] . $url, 'SSL')); |
|||||||||||
115 | } |
|||||||||||
116 | ||||||||||||
117 | $this->response->redirect($this->url->link('blog/category', 'token=' . $this->session->data['token'], 'SSL')); |
|||||||||||
118 | } |
|||||||||||
119 | ||||||||||||
120 | $this->getForm(); |
|||||||||||
121 | } |
|||||||||||
122 | ||||||||||||
123 | public function delete() |
|||||||||||
124 | { |
|||||||||||
125 | $this->load->language('blog/category'); |
|||||||||||
126 | ||||||||||||
127 | $this->document->setTitle($this->language->get('heading_title')); |
|||||||||||
128 | ||||||||||||
129 | $this->load->model('blog/category'); |
|||||||||||
130 | ||||||||||||
131 | if (isset($this->request->post['selected']) && $this->validateDelete()) { |
|||||||||||
132 | foreach ($this->request->post['selected'] as $category_id) { |
|||||||||||
133 | $this->model_blog_category->deleteCategory($category_id); |
|||||||||||
134 | } |
|||||||||||
135 | ||||||||||||
136 | $this->session->data['success'] = $this->language->get('text_success'); |
|||||||||||
137 | ||||||||||||
138 | $url = ''; |
|||||||||||
139 | ||||||||||||
140 | if (isset($this->request->get['filter_name'])) { |
|||||||||||
141 | $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); |
|||||||||||
142 | } |
|||||||||||
143 | ||||||||||||
144 | if (isset($this->request->get['filter_status'])) { |
|||||||||||
145 | $url .= '&filter_status=' . $this->request->get['filter_status']; |
|||||||||||
146 | } |
|||||||||||
147 | ||||||||||||
148 | if (isset($this->request->get['sort'])) { |
|||||||||||
149 | $url .= '&sort=' . $this->request->get['sort']; |
|||||||||||
150 | } |
|||||||||||
151 | ||||||||||||
152 | if (isset($this->request->get['order'])) { |
|||||||||||
153 | $url .= '&order=' . $this->request->get['order']; |
|||||||||||
154 | } |
|||||||||||
155 | ||||||||||||
156 | if (isset($this->request->get['page'])) { |
|||||||||||
157 | $url .= '&page=' . $this->request->get['page']; |
|||||||||||
158 | } |
|||||||||||
159 | ||||||||||||
160 | $this->response->redirect($this->url->link('blog/category', 'token=' . $this->session->data['token'] . $url, 'SSL')); |
|||||||||||
161 | } |
|||||||||||
162 | ||||||||||||
163 | $this->getList(); |
|||||||||||
164 | } |
|||||||||||
165 | ||||||||||||
166 | View Code Duplication | public function repair() |
||||||||||
167 | { |
|||||||||||
168 | $this->load->language('blog/category'); |
|||||||||||
169 | ||||||||||||
170 | $this->document->setTitle($this->language->get('heading_title')); |
|||||||||||
171 | ||||||||||||
172 | $this->load->model('blog/category'); |
|||||||||||
173 | ||||||||||||
174 | if ($this->validateRepair()) { |
|||||||||||
175 | $this->model_blog_category->repairCategories(); |
|||||||||||
176 | ||||||||||||
177 | $this->session->data['success'] = $this->language->get('text_success'); |
|||||||||||
178 | ||||||||||||
179 | $url = ''; |
|||||||||||
180 | ||||||||||||
181 | if (isset($this->request->get['sort'])) { |
|||||||||||
182 | $url .= '&sort=' . $this->request->get['sort']; |
|||||||||||
183 | } |
|||||||||||
184 | ||||||||||||
185 | if (isset($this->request->get['order'])) { |
|||||||||||
186 | $url .= '&order=' . $this->request->get['order']; |
|||||||||||
187 | } |
|||||||||||
188 | ||||||||||||
189 | if (isset($this->request->get['page'])) { |
|||||||||||
190 | $url .= '&page=' . $this->request->get['page']; |
|||||||||||
191 | } |
|||||||||||
192 | ||||||||||||
193 | $this->response->redirect($this->url->link('blog/category', 'token=' . $this->session->data['token'] . $url, 'SSL')); |
|||||||||||
194 | } |
|||||||||||
195 | ||||||||||||
196 | $this->getList(); |
|||||||||||
197 | } |
|||||||||||
198 | ||||||||||||
199 | protected function getList() |
|||||||||||
200 | { |
|||||||||||
201 | if (isset($this->request->get['filter_name'])) { |
|||||||||||
202 | $filter_name = $this->request->get['filter_name']; |
|||||||||||
203 | } else { |
|||||||||||
204 | $filter_name = null; |
|||||||||||
205 | } |
|||||||||||
206 | ||||||||||||
207 | if (isset($this->request->get['filter_status'])) { |
|||||||||||
208 | $filter_status = $this->request->get['filter_status']; |
|||||||||||
209 | } else { |
|||||||||||
210 | $filter_status = null; |
|||||||||||
211 | } |
|||||||||||
212 | ||||||||||||
213 | if (isset($this->request->get['sort'])) { |
|||||||||||
214 | $sort = $this->request->get['sort']; |
|||||||||||
215 | } else { |
|||||||||||
216 | $sort = 'name'; |
|||||||||||
217 | } |
|||||||||||
218 | ||||||||||||
219 | if (isset($this->request->get['order'])) { |
|||||||||||
220 | $order = $this->request->get['order']; |
|||||||||||
221 | } else { |
|||||||||||
222 | $order = 'ASC'; |
|||||||||||
223 | } |
|||||||||||
224 | ||||||||||||
225 | if (isset($this->request->get['page'])) { |
|||||||||||
226 | $page = $this->request->get['page']; |
|||||||||||
227 | } else { |
|||||||||||
228 | $page = 1; |
|||||||||||
229 | } |
|||||||||||
230 | ||||||||||||
231 | $url = ''; |
|||||||||||
232 | ||||||||||||
233 | if (isset($this->request->get['filter_name'])) { |
|||||||||||
234 | $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); |
|||||||||||
235 | } |
|||||||||||
236 | ||||||||||||
237 | if (isset($this->request->get['filter_status'])) { |
|||||||||||
238 | $url .= '&filter_status=' . $this->request->get['filter_status']; |
|||||||||||
239 | } |
|||||||||||
240 | ||||||||||||
241 | if (isset($this->request->get['sort'])) { |
|||||||||||
242 | $url .= '&sort=' . $this->request->get['sort']; |
|||||||||||
243 | } |
|||||||||||
244 | ||||||||||||
245 | if (isset($this->request->get['order'])) { |
|||||||||||
246 | $url .= '&order=' . $this->request->get['order']; |
|||||||||||
247 | } |
|||||||||||
248 | ||||||||||||
249 | if (isset($this->request->get['page'])) { |
|||||||||||
250 | $url .= '&page=' . $this->request->get['page']; |
|||||||||||
251 | } |
|||||||||||
252 | ||||||||||||
253 | #Get All Language Text |
|||||||||||
254 | $data = $this->language->all(); |
|||||||||||
255 | ||||||||||||
256 | $data['add'] = $this->url->link('blog/category/add', 'token=' . $this->session->data['token'] . $url, 'SSL'); |
|||||||||||
257 | $data['delete'] = $this->url->link('blog/category/delete', 'token=' . $this->session->data['token'] . $url, 'SSL'); |
|||||||||||
258 | $data['repair'] = $this->url->link('blog/category/repair', 'token=' . $this->session->data['token'] . $url, 'SSL'); |
|||||||||||
259 | ||||||||||||
260 | $data['categories'] = array(); |
|||||||||||
261 | ||||||||||||
262 | $filter_data = array( |
|||||||||||
263 | 'filter_name' => $filter_name, |
|||||||||||
264 | 'filter_status' => $filter_status, |
|||||||||||
265 | 'sort' => $sort, |
|||||||||||
266 | 'order' => $order, |
|||||||||||
267 | 'start' => ($page - 1) * $this->config->get('config_limit_admin'), |
|||||||||||
268 | 'limit' => $this->config->get('config_limit_admin') |
|||||||||||
269 | ); |
|||||||||||
270 | ||||||||||||
271 | $category_total = $this->model_blog_category->getTotalCategories($filter_data); |
|||||||||||
272 | ||||||||||||
273 | $results = $this->model_blog_category->getCategories($filter_data); |
|||||||||||
274 | ||||||||||||
275 | View Code Duplication | foreach ($results as $result) { |
||||||||||
276 | $data['categories'][] = array( |
|||||||||||
277 | 'category_id' => $result['category_id'], |
|||||||||||
278 | 'parent_id' => $result['parent_id'], |
|||||||||||
279 | 'name' => $result['name'], |
|||||||||||
280 | 'sort_order' => $result['sort_order'], |
|||||||||||
281 | 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), |
|||||||||||
282 | 'edit' => $this->url->link('blog/category/edit', 'token=' . $this->session->data['token'] . '&category_id=' . $result['category_id'] . $url, 'SSL'), |
|||||||||||
283 | 'delete' => $this->url->link('blog/category/delete', 'token=' . $this->session->data['token'] . '&category_id=' . $result['category_id'] . $url, 'SSL') |
|||||||||||
284 | ); |
|||||||||||
285 | } |
|||||||||||
286 | ||||||||||||
287 | if (isset($this->error['warning'])) { |
|||||||||||
288 | $data['error_warning'] = $this->error['warning']; |
|||||||||||
289 | } else { |
|||||||||||
290 | $data['error_warning'] = ''; |
|||||||||||
291 | } |
|||||||||||
292 | ||||||||||||
293 | View Code Duplication | if (isset($this->session->data['success'])) { |
||||||||||
294 | $data['success'] = $this->session->data['success']; |
|||||||||||
295 | ||||||||||||
296 | unset($this->session->data['success']); |
|||||||||||
297 | } else { |
|||||||||||
298 | $data['success'] = ''; |
|||||||||||
299 | } |
|||||||||||
300 | ||||||||||||
301 | if (isset($this->request->post['selected'])) { |
|||||||||||
302 | $data['selected'] = (array) $this->request->post['selected']; |
|||||||||||
303 | } else { |
|||||||||||
304 | $data['selected'] = array(); |
|||||||||||
305 | } |
|||||||||||
306 | ||||||||||||
307 | $url = ''; |
|||||||||||
308 | ||||||||||||
309 | if (isset($this->request->get['filter_name'])) { |
|||||||||||
310 | $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); |
|||||||||||
311 | } |
|||||||||||
312 | ||||||||||||
313 | if (isset($this->request->get['filter_status'])) { |
|||||||||||
314 | $url .= '&filter_status=' . $this->request->get['filter_status']; |
|||||||||||
315 | } |
|||||||||||
316 | ||||||||||||
317 | if ($order == 'ASC') { |
|||||||||||
318 | $url .= '&order=DESC'; |
|||||||||||
319 | } else { |
|||||||||||
320 | $url .= '&order=ASC'; |
|||||||||||
321 | } |
|||||||||||
322 | ||||||||||||
323 | if (isset($this->request->get['page'])) { |
|||||||||||
324 | $url .= '&page=' . $this->request->get['page']; |
|||||||||||
325 | } |
|||||||||||
326 | ||||||||||||
327 | $data['sort_name'] = $this->url->link('blog/category', 'token=' . $this->session->data['token'] . '&sort=name' . $url, 'SSL'); |
|||||||||||
328 | $data['sort_status'] = $this->url->link('blog/category', 'token=' . $this->session->data['token'] . '&sort=status' . $url, 'SSL'); |
|||||||||||
329 | $data['sort_sort_order'] = $this->url->link('blog/category', 'token=' . $this->session->data['token'] . '&sort=sort_order' . $url, 'SSL'); |
|||||||||||
330 | ||||||||||||
331 | $url = ''; |
|||||||||||
332 | ||||||||||||
333 | if (isset($this->request->get['filter_name'])) { |
|||||||||||
334 | $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); |
|||||||||||
335 | } |
|||||||||||
336 | ||||||||||||
337 | if (isset($this->request->get['filter_status'])) { |
|||||||||||
338 | $url .= '&filter_status=' . $this->request->get['filter_status']; |
|||||||||||
339 | } |
|||||||||||
340 | ||||||||||||
341 | if (isset($this->request->get['sort'])) { |
|||||||||||
342 | $url .= '&sort=' . $this->request->get['sort']; |
|||||||||||
343 | } |
|||||||||||
344 | ||||||||||||
345 | if (isset($this->request->get['order'])) { |
|||||||||||
346 | $url .= '&order=' . $this->request->get['order']; |
|||||||||||
347 | } |
|||||||||||
348 | ||||||||||||
349 | if (isset($this->request->get['sortable'])) { |
|||||||||||
350 | $url .= '&sortable=' . $this->request->get['sortable']; |
|||||||||||
351 | } |
|||||||||||
352 | ||||||||||||
353 | $pagination = new Pagination(); |
|||||||||||
354 | $pagination->total = $category_total; |
|||||||||||
355 | $pagination->page = $page; |
|||||||||||
0 ignored issues
–
show
It seems like
$page can also be of type double . However, the property $page is declared as type integer . Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
![]() |
||||||||||||
356 | $pagination->limit = $this->config->get('config_limit_admin'); |
|||||||||||
357 | $pagination->url = $this->url->link('blog/category', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL'); |
|||||||||||
358 | ||||||||||||
359 | $data['pagination'] = $pagination->render(); |
|||||||||||
360 | ||||||||||||
361 | $data['filter_name'] = $filter_name; |
|||||||||||
362 | $data['filter_status'] = $filter_status; |
|||||||||||
363 | ||||||||||||
364 | $data['token'] = $this->session->data['token']; |
|||||||||||
365 | ||||||||||||
366 | $data['results'] = sprintf($this->language->get('text_pagination'), ($category_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($category_total - $this->config->get('config_limit_admin'))) ? $category_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $category_total, ceil($category_total / $this->config->get('config_limit_admin'))); |
|||||||||||
367 | ||||||||||||
368 | $data['sort'] = $sort; |
|||||||||||
369 | $data['order'] = $order; |
|||||||||||
370 | ||||||||||||
371 | $data['sortable'] = (isset($this->request->get['sortable']) && $this->request->get['sortable'] == 'active') ? true : false; |
|||||||||||
372 | ||||||||||||
373 | $data['header'] = $this->load->controller('common/header'); |
|||||||||||
374 | $data['column_left'] = $this->load->controller('common/column_left'); |
|||||||||||
375 | $data['footer'] = $this->load->controller('common/footer'); |
|||||||||||
376 | ||||||||||||
377 | $this->response->setOutput($this->load->view('blog/category_list.tpl', $data)); |
|||||||||||
378 | } |
|||||||||||
379 | ||||||||||||
380 | protected function getForm() |
|||||||||||
381 | { |
|||||||||||
382 | #Get All Language Text |
|||||||||||
383 | $data = $this->language->all(); |
|||||||||||
384 | ||||||||||||
385 | $data['text_form'] = !isset($this->request->get['category_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); |
|||||||||||
386 | ||||||||||||
387 | if (isset($this->error['warning'])) { |
|||||||||||
388 | $data['error_warning'] = $this->error['warning']; |
|||||||||||
389 | } else { |
|||||||||||
390 | $data['error_warning'] = ''; |
|||||||||||
391 | } |
|||||||||||
392 | ||||||||||||
393 | if (isset($this->error['name'])) { |
|||||||||||
394 | $data['error_name'] = $this->error['name']; |
|||||||||||
395 | } else { |
|||||||||||
396 | $data['error_name'] = array(); |
|||||||||||
397 | } |
|||||||||||
398 | ||||||||||||
399 | View Code Duplication | if (isset($this->error['seo_url'])) { |
||||||||||
400 | $data['error_seo_url'] = $this->error['seo_url']; |
|||||||||||
401 | } else { |
|||||||||||
402 | $data['error_seo_url'] = array(); |
|||||||||||
403 | } |
|||||||||||
404 | ||||||||||||
405 | View Code Duplication | if (isset($this->session->data['success'])) { |
||||||||||
406 | $data['success'] = $this->session->data['success']; |
|||||||||||
407 | ||||||||||||
408 | unset($this->session->data['success']); |
|||||||||||
409 | } else { |
|||||||||||
410 | $data['success'] = ''; |
|||||||||||
411 | } |
|||||||||||
412 | ||||||||||||
413 | if (!isset($this->request->get['category_id'])) { |
|||||||||||
414 | $data['action'] = $this->url->link('blog/category/add', 'token=' . $this->session->data['token'], 'SSL'); |
|||||||||||
415 | } else { |
|||||||||||
416 | $data['action'] = $this->url->link('blog/category/edit', 'token=' . $this->session->data['token'] . '&category_id=' . $this->request->get['category_id']); |
|||||||||||
417 | } |
|||||||||||
418 | ||||||||||||
419 | $data['cancel'] = $this->url->link('blog/category', 'token=' . $this->session->data['token'], 'SSL'); |
|||||||||||
420 | ||||||||||||
421 | $data['token'] = $this->session->data['token']; |
|||||||||||
422 | ||||||||||||
423 | View Code Duplication | if (isset($this->request->get['category_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { |
||||||||||
424 | $category_info = $this->model_blog_category->getCategory($this->request->get['category_id']); |
|||||||||||
425 | } |
|||||||||||
426 | ||||||||||||
427 | $this->load->model('localisation/language'); |
|||||||||||
428 | ||||||||||||
429 | $data['languages'] = $this->model_localisation_language->getLanguages(); |
|||||||||||
430 | ||||||||||||
431 | $categories = $this->model_blog_category->getCategories(); |
|||||||||||
432 | ||||||||||||
433 | if (isset($category_info)) { |
|||||||||||
434 | foreach ($categories as $key => $category) { |
|||||||||||
435 | if ($category['category_id'] == $category_info['category_id']) { |
|||||||||||
436 | unset($categories[$key]); |
|||||||||||
437 | } |
|||||||||||
438 | } |
|||||||||||
439 | } |
|||||||||||
440 | ||||||||||||
441 | $data['categories'] = $categories; |
|||||||||||
442 | ||||||||||||
443 | if (isset($this->request->post['category_description'])) { |
|||||||||||
444 | $data['category_description'] = $this->request->post['category_description']; |
|||||||||||
445 | } elseif (isset($category_info)) { |
|||||||||||
446 | $data['category_description'] = $this->model_blog_category->getCategoryDescriptions($this->request->get['category_id']); |
|||||||||||
447 | } else { |
|||||||||||
448 | $data['category_description'] = array(); |
|||||||||||
449 | } |
|||||||||||
450 | ||||||||||||
451 | if (isset($this->request->post['path'])) { |
|||||||||||
452 | $data['path'] = $this->request->post['path']; |
|||||||||||
453 | } elseif (!empty($category_info)) { |
|||||||||||
454 | $data['path'] = $category_info['path']; |
|||||||||||
455 | } else { |
|||||||||||
456 | $data['path'] = ''; |
|||||||||||
457 | } |
|||||||||||
458 | ||||||||||||
459 | if (isset($this->request->post['parent_id'])) { |
|||||||||||
460 | $data['parent_id'] = $this->request->post['parent_id']; |
|||||||||||
461 | } elseif (isset($category_info)) { |
|||||||||||
462 | $data['parent_id'] = $category_info['parent_id']; |
|||||||||||
463 | } else { |
|||||||||||
464 | $data['parent_id'] = 0; |
|||||||||||
465 | } |
|||||||||||
466 | ||||||||||||
467 | $this->load->model('setting/store'); |
|||||||||||
468 | ||||||||||||
469 | $data['stores'] = $this->model_setting_store->getStores(); |
|||||||||||
470 | ||||||||||||
471 | if (isset($this->request->post['category_store'])) { |
|||||||||||
472 | $data['category_store'] = $this->request->post['category_store']; |
|||||||||||
473 | } elseif (isset($category_info)) { |
|||||||||||
474 | $data['category_store'] = $this->model_blog_category->getCategoryStores($this->request->get['category_id']); |
|||||||||||
475 | } else { |
|||||||||||
476 | $data['category_store'] = array(0); |
|||||||||||
477 | } |
|||||||||||
478 | ||||||||||||
479 | if (isset($this->request->post['seo_url'])) { |
|||||||||||
480 | $data['seo_url'] = $this->request->post['seo_url']; |
|||||||||||
481 | } elseif (!empty($category_info)) { |
|||||||||||
482 | $data['seo_url'] = $category_info['seo_url']; |
|||||||||||
483 | } else { |
|||||||||||
484 | $data['seo_url'] = array(); |
|||||||||||
485 | } |
|||||||||||
486 | ||||||||||||
487 | if (isset($this->request->post['image'])) { |
|||||||||||
488 | $data['image'] = $this->request->post['image']; |
|||||||||||
489 | } elseif (!empty($category_info)) { |
|||||||||||
490 | $data['image'] = $category_info['image']; |
|||||||||||
491 | } else { |
|||||||||||
492 | $data['image'] = ''; |
|||||||||||
493 | } |
|||||||||||
494 | ||||||||||||
495 | $this->load->model('tool/image'); |
|||||||||||
496 | ||||||||||||
497 | if (isset($this->request->post['image']) && is_file(DIR_IMAGE . $this->request->post['image'])) { |
|||||||||||
498 | $data['thumb'] = $this->model_tool_image->resize($this->request->post['image'], 100, 100); |
|||||||||||
499 | } elseif (!empty($category_info) && is_file(DIR_IMAGE . $category_info['image'])) { |
|||||||||||
500 | $data['thumb'] = $this->model_tool_image->resize($category_info['image'], 100, 100); |
|||||||||||
501 | } else { |
|||||||||||
502 | $data['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100); |
|||||||||||
503 | } |
|||||||||||
504 | ||||||||||||
505 | $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100); |
|||||||||||
506 | ||||||||||||
507 | if (isset($this->request->post['top'])) { |
|||||||||||
508 | $data['top'] = $this->request->post['top']; |
|||||||||||
509 | } elseif (!empty($category_info)) { |
|||||||||||
510 | $data['top'] = $category_info['top']; |
|||||||||||
511 | } else { |
|||||||||||
512 | $data['top'] = 0; |
|||||||||||
513 | } |
|||||||||||
514 | ||||||||||||
515 | if (isset($this->request->post['sort_order'])) { |
|||||||||||
516 | $data['sort_order'] = $this->request->post['sort_order']; |
|||||||||||
517 | } elseif (isset($category_info)) { |
|||||||||||
518 | $data['sort_order'] = $category_info['sort_order']; |
|||||||||||
519 | } else { |
|||||||||||
520 | $data['sort_order'] = 0; |
|||||||||||
521 | } |
|||||||||||
522 | ||||||||||||
523 | if (isset($this->request->post['status'])) { |
|||||||||||
524 | $data['status'] = $this->request->post['status']; |
|||||||||||
525 | } elseif (isset($category_info)) { |
|||||||||||
526 | $data['status'] = $category_info['status']; |
|||||||||||
527 | } else { |
|||||||||||
528 | $data['status'] = 1; |
|||||||||||
529 | } |
|||||||||||
530 | ||||||||||||
531 | if (isset($this->request->post['category_layout'])) { |
|||||||||||
532 | $data['category_layout'] = $this->request->post['category_layout']; |
|||||||||||
533 | } elseif (isset($category_info)) { |
|||||||||||
534 | $data['category_layout'] = $this->model_blog_category->getCategoryLayouts($this->request->get['category_id']); |
|||||||||||
535 | } else { |
|||||||||||
536 | $data['category_layout'] = array(); |
|||||||||||
537 | } |
|||||||||||
538 | ||||||||||||
539 | if (isset($this->request->get['category_id'])) { |
|||||||||||
540 | $data['menu_name_override'] = '1'; |
|||||||||||
541 | } |
|||||||||||
542 | ||||||||||||
543 | $data['category_id'] = isset($this->request->get['category_id']) ? $this->request->get['category_id'] : 0; |
|||||||||||
544 | ||||||||||||
545 | // Preview link |
|||||||||||
546 | View Code Duplication | foreach ($data['languages'] as $language) { |
||||||||||
547 | $data['preview'][$language['language_id']] = $this->getSeoLink($data['category_id'], $language['code']); |
|||||||||||
548 | } |
|||||||||||
549 | ||||||||||||
550 | $this->load->model('appearance/layout'); |
|||||||||||
551 | ||||||||||||
552 | $data['layouts'] = $this->model_appearance_layout->getLayouts(); |
|||||||||||
553 | ||||||||||||
554 | $data['header'] = $this->load->controller('common/header'); |
|||||||||||
555 | $data['column_left'] = $this->load->controller('common/column_left'); |
|||||||||||
556 | $data['footer'] = $this->load->controller('common/footer'); |
|||||||||||
557 | ||||||||||||
558 | $this->response->setOutput($this->load->view('blog/category_form.tpl', $data)); |
|||||||||||
559 | } |
|||||||||||
560 | ||||||||||||
561 | protected function validateForm() |
|||||||||||
562 | { |
|||||||||||
563 | if (!$this->user->hasPermission('modify', 'blog/category')) { |
|||||||||||
564 | $this->error['warning'] = $this->language->get('error_permission'); |
|||||||||||
565 | } |
|||||||||||
566 | ||||||||||||
567 | foreach ($this->request->post['category_description'] as $language_id => $value) { |
|||||||||||
568 | if ((strlen(utf8_decode($value['name'])) < 2) || (strlen(utf8_decode($value['name'])) > 255)) { |
|||||||||||
569 | $this->error['name'][$language_id] = $this->language->get('error_name'); |
|||||||||||
570 | } |
|||||||||||
571 | } |
|||||||||||
572 | ||||||||||||
573 | $this->load->model('catalog/url_alias'); |
|||||||||||
574 | ||||||||||||
575 | foreach ($this->request->post['seo_url'] as $language_id => $value) { |
|||||||||||
576 | $url_alias_info = $this->model_catalog_url_alias->getUrlAlias($value, $language_id); |
|||||||||||
577 | ||||||||||||
578 | if ($url_alias_info && isset($this->request->get['category_id']) && $url_alias_info['query'] != 'blog_category_id=' . $this->request->get['category_id']) { |
|||||||||||
579 | $this->error['seo_url'][$language_id] = sprintf($this->language->get('error_seo_url')); |
|||||||||||
580 | } |
|||||||||||
581 | ||||||||||||
582 | if ($url_alias_info && !isset($this->request->get['category_id'])) { |
|||||||||||
583 | $this->error['seo_url'][$language_id] = sprintf($this->language->get('error_seo_url')); |
|||||||||||
584 | } |
|||||||||||
585 | } |
|||||||||||
586 | ||||||||||||
587 | if ($this->error && !isset($this->error['warning'])) { |
|||||||||||
0 ignored issues
–
show
The expression
$this->error of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
||||||||||||
588 | $this->error['warning'] = $this->language->get('error_warning'); |
|||||||||||
589 | } |
|||||||||||
590 | ||||||||||||
591 | if ($this->error && !isset($this->error['warning'])) { |
|||||||||||
0 ignored issues
–
show
The expression
$this->error of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
||||||||||||
592 | $this->error['warning'] = $this->language->get('error_warning'); |
|||||||||||
593 | } |
|||||||||||
594 | ||||||||||||
595 | return !$this->error; |
|||||||||||
596 | } |
|||||||||||
597 | ||||||||||||
598 | protected function validateDelete() |
|||||||||||
599 | { |
|||||||||||
600 | if (!$this->user->hasPermission('modify', 'blog/category')) { |
|||||||||||
601 | $this->error['warning'] = $this->language->get('error_permission'); |
|||||||||||
602 | } |
|||||||||||
603 | ||||||||||||
604 | return !$this->error; |
|||||||||||
605 | } |
|||||||||||
606 | ||||||||||||
607 | protected function validateRepair() |
|||||||||||
608 | { |
|||||||||||
609 | if (!$this->user->hasPermission('modify', 'blog/category')) { |
|||||||||||
610 | $this->error['warning'] = $this->language->get('error_permission'); |
|||||||||||
611 | } |
|||||||||||
612 | ||||||||||||
613 | return !$this->error; |
|||||||||||
614 | } |
|||||||||||
615 | ||||||||||||
616 | View Code Duplication | public function autocomplete() |
||||||||||
617 | { |
|||||||||||
618 | $json = array(); |
|||||||||||
619 | ||||||||||||
620 | if (isset($this->request->get['filter_name'])) { |
|||||||||||
621 | $this->load->model('blog/category'); |
|||||||||||
622 | ||||||||||||
623 | $filter_data = array( |
|||||||||||
624 | 'filter_name' => $this->request->get['filter_name'], |
|||||||||||
625 | 'sort' => 'name', |
|||||||||||
626 | 'order' => 'ASC', |
|||||||||||
627 | 'start' => 0, |
|||||||||||
628 | 'limit' => 5 |
|||||||||||
629 | ); |
|||||||||||
630 | ||||||||||||
631 | $results = $this->model_blog_category->getCategories($filter_data); |
|||||||||||
632 | ||||||||||||
633 | foreach ($results as $result) { |
|||||||||||
634 | $result['index'] = $result['name']; |
|||||||||||
635 | ||||||||||||
636 | if (strpos($result['index'], ' > ')) { |
|||||||||||
637 | $result['index'] = explode(' > ', $result['index']); |
|||||||||||
638 | $result['index'] = end($result['index']); |
|||||||||||
639 | } |
|||||||||||
640 | ||||||||||||
641 | $json[] = array( |
|||||||||||
642 | 'category_id' => $result['category_id'], |
|||||||||||
643 | 'index' => $result['index'], |
|||||||||||
644 | 'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')) |
|||||||||||
645 | ); |
|||||||||||
646 | } |
|||||||||||
647 | } |
|||||||||||
648 | ||||||||||||
649 | $sort_order = array(); |
|||||||||||
650 | ||||||||||||
651 | foreach ($json as $key => $value) { |
|||||||||||
652 | $sort_order[$key] = $value['name']; |
|||||||||||
653 | } |
|||||||||||
654 | ||||||||||||
655 | array_multisort($sort_order, SORT_ASC, $json); |
|||||||||||
656 | ||||||||||||
657 | $this->response->addHeader('Content-Type: application/json'); |
|||||||||||
658 | $this->response->setOutput(json_encode($json)); |
|||||||||||
659 | } |
|||||||||||
660 | ||||||||||||
661 | View Code Duplication | public function quick() |
||||||||||
662 | { |
|||||||||||
663 | $this->load->language('blog/category'); |
|||||||||||
664 | ||||||||||||
665 | $json = array(); |
|||||||||||
666 | ||||||||||||
667 | $this->load->model('blog/category'); |
|||||||||||
668 | $this->load->model('catalog/url_alias'); |
|||||||||||
669 | ||||||||||||
670 | if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateQuick()) { |
|||||||||||
671 | $this->trigger->fire('pre.admin.blog.category.quick', array(&$this->request->post)); |
|||||||||||
672 | ||||||||||||
673 | $this->load->model('localisation/language'); |
|||||||||||
674 | ||||||||||||
675 | $languages = $this->model_localisation_language->getLanguages(); |
|||||||||||
676 | ||||||||||||
677 | if ($this->request->post['name']) { |
|||||||||||
678 | foreach ($languages as $language) { |
|||||||||||
679 | $this->request->post['category_description'][$language['language_id']]['name'] = $this->request->post['name']; |
|||||||||||
680 | $this->request->post['category_description'][$language['language_id']]['description'] = ''; |
|||||||||||
681 | $this->request->post['category_description'][$language['language_id']]['meta_description'] = ''; |
|||||||||||
682 | $this->request->post['category_description'][$language['language_id']]['meta_keyword'] = ''; |
|||||||||||
683 | ||||||||||||
684 | $this->request->post['seo_url'][$language['language_id']] = ''; |
|||||||||||
685 | } |
|||||||||||
686 | } |
|||||||||||
687 | ||||||||||||
688 | $this->request->post['top'] = 1; |
|||||||||||
689 | ||||||||||||
690 | $this->request->post['category_store'][] = 0; |
|||||||||||
691 | ||||||||||||
692 | $this->load->model('setting/store'); |
|||||||||||
693 | ||||||||||||
694 | $stores = $this->model_setting_store->getStores(); |
|||||||||||
695 | ||||||||||||
696 | if ($stores) { |
|||||||||||
697 | foreach ($stores as $store) { |
|||||||||||
698 | $this->request->post['category_store'][] = $store['store_id']; |
|||||||||||
699 | } |
|||||||||||
700 | } |
|||||||||||
701 | ||||||||||||
702 | $category_id = $this->model_blog_category->addCategory($this->request->post); |
|||||||||||
703 | ||||||||||||
704 | $this->trigger->fire('post.admin.blog.category.quick', array($category_id)); |
|||||||||||
705 | ||||||||||||
706 | $json['success'] = $this->language->get('text_success'); |
|||||||||||
707 | $json['category_id'] = $category_id; |
|||||||||||
708 | } |
|||||||||||
709 | ||||||||||||
710 | $this->response->addHeader('Content-Type: application/json'); |
|||||||||||
711 | $this->response->setOutput(json_encode($json)); |
|||||||||||
712 | } |
|||||||||||
713 | ||||||||||||
714 | View Code Duplication | protected function validateQuick() |
||||||||||
715 | { |
|||||||||||
716 | if (!$this->user->hasPermission('modify', 'blog/category')) { |
|||||||||||
717 | $this->error['warning'] = $this->language->get('error_permission'); |
|||||||||||
718 | } |
|||||||||||
719 | ||||||||||||
720 | $this->trigger->fire('post.admin.blog.category.validate.quick', array(&$this->error)); |
|||||||||||
721 | ||||||||||||
722 | return !$this->error; |
|||||||||||
723 | } |
|||||||||||
724 | ||||||||||||
725 | View Code Duplication | public function inline() |
||||||||||
726 | { |
|||||||||||
727 | $json = array(); |
|||||||||||
728 | ||||||||||||
729 | if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateInline()) { |
|||||||||||
730 | $this->load->model('blog/category'); |
|||||||||||
731 | ||||||||||||
732 | if (isset($this->request->post['seo_url'])) { |
|||||||||||
733 | $this->load->model('catalog/url_alias'); |
|||||||||||
734 | ||||||||||||
735 | $this->model_catalog_url_alias->addAlias('blog_category', $this->request->get['category_id'], $this->request->post['seo_url'], $this->request->post['language_id']); |
|||||||||||
736 | ||||||||||||
737 | $json['language_id'] = $this->request->post['language_id']; |
|||||||||||
738 | } else { |
|||||||||||
739 | foreach ($this->request->post as $key => $value) { |
|||||||||||
740 | $this->model_blog_category->updateCategory($this->request->get['category_id'], $key, $value); |
|||||||||||
741 | } |
|||||||||||
742 | } |
|||||||||||
743 | } |
|||||||||||
744 | ||||||||||||
745 | $this->response->addHeader('Content-Type: application/json'); |
|||||||||||
746 | $this->response->setOutput(json_encode($json)); |
|||||||||||
747 | } |
|||||||||||
748 | ||||||||||||
749 | View Code Duplication | protected function validateInline() |
||||||||||
750 | { |
|||||||||||
751 | if (!$this->user->hasPermission('modify', 'blog/category')) { |
|||||||||||
752 | $this->error['warning'] = $this->language->get('error_permission'); |
|||||||||||
753 | } |
|||||||||||
754 | ||||||||||||
755 | if (!isset($this->request->post['name']) && !isset($this->request->post['status']) && !isset($this->request->post['seo_url'])) { |
|||||||||||
756 | $this->error['warning'] = $this->language->get('error_inline_field'); |
|||||||||||
757 | } |
|||||||||||
758 | ||||||||||||
759 | return !$this->error; |
|||||||||||
760 | } |
|||||||||||
761 | ||||||||||||
762 | View Code Duplication | public function getSeoLink($category_id, $language_code) |
||||||||||
763 | { |
|||||||||||
764 | $old_session_code = isset($this->session->data['language']) ? $this->session->data['language'] : ''; |
|||||||||||
765 | $old_config_code = $this->config->get('config_language'); |
|||||||||||
766 | ||||||||||||
767 | $this->session->data['language'] = $language_code; |
|||||||||||
768 | $this->config->set('config_language', $language_code); |
|||||||||||
769 | ||||||||||||
770 | $url = $this->config->get('config_url'); |
|||||||||||
771 | ||||||||||||
772 | if (empty($url)) { |
|||||||||||
773 | $url = HTTP_SERVER; |
|||||||||||
774 | ||||||||||||
775 | $admin_folder = str_replace(DIR_ROOT, '', DIR_ADMIN); |
|||||||||||
776 | ||||||||||||
777 | $url = str_replace($admin_folder, '', $url); |
|||||||||||
778 | } |
|||||||||||
779 | ||||||||||||
780 | $route = new Route($this->registry); |
|||||||||||
781 | ||||||||||||
782 | $url .= ltrim($route->rewrite('index.php?route=blog/category&path=' . $category_id), '/'); |
|||||||||||
783 | ||||||||||||
784 | if (!empty($old_session_code)) { |
|||||||||||
785 | $this->session->data['language'] = $old_session_code; |
|||||||||||
786 | } |
|||||||||||
787 | ||||||||||||
788 | $this->config->set('config_language', $old_config_code); |
|||||||||||
789 | ||||||||||||
790 | return $url; |
|||||||||||
791 | } |
|||||||||||
792 | } |
|||||||||||
793 |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.