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 | /** |
||
4 | * Evgeny Muravjev Typograph, http://mdash.ru |
||
5 | * Version: 3.4 Gold Master |
||
6 | * Release Date: September 20, 2014 |
||
7 | * Authors: Evgeny Muravjev & Alexander Drutsa |
||
8 | */ |
||
9 | |||
10 | namespace Fenrizbes\TypographBundle\EMT; |
||
11 | |||
12 | /** |
||
13 | * Основной класс типографа Евгения Муравьёва |
||
14 | * реализует основные методы запуска и рабыоты типографа |
||
15 | * |
||
16 | */ |
||
17 | class EMTBase |
||
18 | { |
||
19 | private $_text = ""; |
||
20 | private $inited = false; |
||
21 | |||
22 | /** |
||
23 | * Список Трэтов, которые надо применить к типогрфированию |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $trets = array() ; |
||
28 | protected $trets_index = array() ; |
||
29 | protected $tret_objects = array() ; |
||
30 | |||
31 | public $ok = false; |
||
32 | public $debug_enabled = false; |
||
33 | public $logging = false; |
||
34 | public $logs = array(); |
||
35 | public $errors = array(); |
||
36 | public $debug_info = array(); |
||
37 | |||
38 | private $use_layout = false; |
||
39 | private $class_layout_prefix = false; |
||
40 | private $use_layout_set = false; |
||
41 | public $disable_notg_replace = false; |
||
42 | public $remove_notg = false; |
||
43 | |||
44 | public $settings = array(); |
||
45 | |||
46 | protected function log($str, $data = null) |
||
47 | { |
||
48 | if(!$this->logging) return; |
||
49 | $this->logs[] = array('class' => '', 'info' => $str, 'data' => $data); |
||
50 | } |
||
51 | |||
52 | protected function tret_log($tret, $str, $data = null) |
||
53 | { |
||
54 | $this->logs[] = array('class' => $tret, 'info' => $str, 'data' => $data); |
||
55 | } |
||
56 | |||
57 | protected function error($info, $data = null) |
||
58 | { |
||
59 | $this->errors[] = array('class' => '', 'info' => $info, 'data' => $data); |
||
60 | $this->log("ERROR $info", $data ); |
||
61 | } |
||
62 | |||
63 | protected function tret_error($tret, $info, $data = null) |
||
64 | { |
||
65 | $this->errors[] = array('class' => $tret, 'info' => $info, 'data' => $data); |
||
66 | } |
||
67 | |||
68 | protected function debug($class, $place, &$after_text, $after_text_raw = "") |
||
69 | { |
||
70 | if(!$this->debug_enabled) return; |
||
71 | $this->debug_info[] = array( |
||
72 | 'tret' => $class == $this ? false: true, |
||
73 | 'class' => is_object($class)? get_class($class) : $class, |
||
74 | 'place' => $place, |
||
75 | 'text' => $after_text, |
||
76 | 'text_raw' => $after_text_raw, |
||
77 | ); |
||
78 | } |
||
79 | |||
80 | |||
81 | |||
82 | protected $_safe_blocks = array(); |
||
83 | |||
84 | |||
85 | /** |
||
86 | * Включить режим отладки, чтобы посмотреть последовательность вызовов |
||
87 | * третов и правил после |
||
88 | * |
||
89 | */ |
||
90 | public function debug_on() |
||
91 | { |
||
92 | $this->debug_enabled = true; |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Включить режим отладки, чтобы посмотреть последовательность вызовов |
||
97 | * третов и правил после |
||
98 | * |
||
99 | */ |
||
100 | public function log_on() |
||
101 | { |
||
102 | $this->logging = true; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Добавление защищенного блока |
||
107 | * |
||
108 | * <code> |
||
109 | * Jare_Typograph_Tool::addCustomBlocks('<span>', '</span>'); |
||
110 | * Jare_Typograph_Tool::addCustomBlocks('\<nobr\>', '\<\/span\>', true); |
||
111 | * </code> |
||
112 | * |
||
113 | * @param string $id идентификатор |
||
114 | * @param string $open начало блока |
||
115 | * @param string $close конец защищенного блока |
||
116 | * @param string $tag тэг |
||
117 | * @return void |
||
118 | */ |
||
119 | private function _add_safe_block($id, $open, $close, $tag) |
||
120 | { |
||
121 | $this->_safe_blocks[] = array( |
||
122 | 'id' => $id, |
||
123 | 'tag' => $tag, |
||
124 | 'open' => $open, |
||
125 | 'close' => $close, |
||
126 | ); |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * Список защищенных блоков |
||
131 | * |
||
132 | * @return array |
||
133 | */ |
||
134 | public function get_all_safe_blocks() |
||
135 | { |
||
136 | return $this->_safe_blocks; |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * Удаленного блока по его номеру ключа |
||
141 | * |
||
142 | * @param string $id идентифиактор защищённого блока |
||
143 | * @return void |
||
144 | */ |
||
145 | public function remove_safe_block($id) |
||
146 | { |
||
147 | foreach($this->_safe_blocks as $k => $block) { |
||
148 | if($block['id']==$id) unset($this->_safe_blocks[$k]); |
||
149 | } |
||
150 | } |
||
151 | |||
152 | |||
153 | /** |
||
154 | * Добавление защищенного блока |
||
155 | * |
||
156 | * @param string $tag тэг, который должен быть защищён |
||
157 | * @return void |
||
158 | */ |
||
159 | public function add_safe_tag($tag) |
||
160 | { |
||
161 | $open = preg_quote("<", '/'). $tag."[^>]*?" . preg_quote(">", '/'); |
||
162 | $close = preg_quote("</$tag>", '/'); |
||
163 | $this->_add_safe_block($tag, $open, $close, $tag); |
||
164 | return true; |
||
165 | } |
||
166 | |||
167 | |||
168 | /** |
||
169 | * Добавление защищенного блока |
||
170 | * |
||
171 | * @param string $open начало блока |
||
172 | * @param string $close конец защищенного блока |
||
173 | * @param bool $quoted специальные символы в начале и конце блока экранированы |
||
174 | * @return void |
||
175 | */ |
||
176 | public function add_safe_block($id, $open, $close, $quoted = false) |
||
177 | { |
||
178 | $open = trim($open); |
||
179 | $close = trim($close); |
||
180 | |||
181 | if (empty($open) || empty($close)) |
||
182 | { |
||
183 | return false; |
||
184 | } |
||
185 | |||
186 | if (false === $quoted) |
||
187 | { |
||
188 | $open = preg_quote($open, '/'); |
||
189 | $close = preg_quote($close, '/'); |
||
190 | } |
||
191 | |||
192 | $this->_add_safe_block($id, $open, $close, ""); |
||
193 | return true; |
||
194 | } |
||
195 | |||
196 | |||
197 | /** |
||
198 | * Сохранение содержимого защищенных блоков |
||
199 | * |
||
200 | * @param string $text |
||
201 | * @param bool $safe если true, то содержимое блоков будет сохранено, иначе - раскодировано. |
||
0 ignored issues
–
show
|
|||
202 | * @return string |
||
203 | */ |
||
204 | public function safe_blocks($text, $way, $show = true) |
||
0 ignored issues
–
show
|
|||
205 | { |
||
206 | if (count($this->_safe_blocks)) |
||
207 | { |
||
208 | $safeType = true === $way ? "\Fenrizbes\TypographBundle\EMT\EMTLib::encrypt_tag(\$m[2])" : "stripslashes(\Fenrizbes\TypographBundle\EMT\EMTLib::decrypt_tag(\$m[2]))"; |
||
209 | $safeblocks = true === $way ? $this->_safe_blocks : array_reverse($this->_safe_blocks); |
||
210 | foreach ($safeblocks as $block) |
||
211 | { |
||
212 | $text = preg_replace_callback("/({$block['open']})(.+?)({$block['close']})/s", create_function('$m','return $m[1].'.$safeType . '.$m[3];') , $text); |
||
0 ignored issues
–
show
The use of
create_function is highly discouraged, better use a closure.
// Instead of
$function = create_function('$a, $b', 'return $a + $b');
// Better use
$function = function($a, $b) { return $a + $b; }
![]() |
|||
213 | } |
||
214 | } |
||
215 | |||
216 | return $text; |
||
217 | } |
||
218 | |||
219 | |||
220 | /** |
||
221 | * Декодирование блоков, которые были скрыты в момент типографирования |
||
222 | * |
||
223 | * @param string $text |
||
224 | * @return string |
||
225 | */ |
||
226 | public function decode_internal_blocks($text) |
||
227 | { |
||
228 | return EMTLib::decode_internal_blocks($text); |
||
229 | } |
||
230 | |||
231 | |||
232 | private function create_object($tret) |
||
233 | { |
||
234 | // если класса нету, попытаемся его прогрузить, например, если стандартный |
||
235 | if(!class_exists($tret)) |
||
236 | { |
||
237 | if(preg_match("/^EMTTret([a-zA-Z0-9_]+)$/",$tret, $m)) |
||
238 | { |
||
239 | $tname = $m[1]; |
||
240 | $fname = str_replace("_"," ",$tname); |
||
241 | $fname = ucwords($fname); |
||
242 | $fname = str_replace(" ",".",$fname); |
||
0 ignored issues
–
show
$fname is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
243 | //if(file_exists("EMT.Tret.".$fname.".php")) |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
73% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
244 | { |
||
245 | } |
||
246 | } |
||
247 | } |
||
248 | if(!class_exists($tret)) |
||
249 | { |
||
250 | $this->error("Класс $tret не найден. Пожалуйста, подргузите нужный файл."); |
||
251 | return null; |
||
252 | } |
||
253 | |||
254 | $obj = new $tret(); |
||
255 | $obj->EMT = $this; |
||
256 | $obj->logging = $this->logging; |
||
257 | return $obj; |
||
258 | } |
||
259 | |||
260 | private function get_short_tret($tretname) |
||
261 | { |
||
262 | if(preg_match("/^EMTTret([a-zA-Z0-9_]+)$/",$tretname, $m)) |
||
263 | { |
||
264 | return $m[1]; |
||
265 | } |
||
266 | return $tretname; |
||
267 | } |
||
268 | |||
269 | private function _init() |
||
270 | { |
||
271 | foreach($this->trets as $tret) |
||
272 | { |
||
273 | if(isset($this->tret_objects[$tret])) continue; |
||
274 | $obj = $this->create_object($tret); |
||
275 | if($obj == null) continue; |
||
276 | $this->tret_objects[$tret] = $obj; |
||
277 | } |
||
278 | |||
279 | if(!$this->inited) |
||
280 | { |
||
281 | $this->add_safe_tag('pre'); |
||
282 | $this->add_safe_tag('script'); |
||
283 | $this->add_safe_tag('style'); |
||
284 | $this->add_safe_tag('notg'); |
||
285 | $this->add_safe_block('span-notg', '<span class="_notg_start"></span>', '<span class="_notg_end"></span>'); |
||
286 | } |
||
287 | $this->inited = true; |
||
288 | } |
||
289 | |||
290 | |||
291 | |||
292 | |||
293 | |||
294 | /** |
||
295 | * Инициализация класса, используется чтобы задать список третов или |
||
296 | * спсиок защищённых блоков, которые можно использовать. |
||
297 | * Такде здесь можно отменить защищённые блоки по умлочнаию |
||
298 | * |
||
299 | */ |
||
300 | public function init() |
||
301 | { |
||
302 | |||
303 | } |
||
304 | |||
305 | /** |
||
306 | * Добавить Трэт, |
||
307 | * |
||
308 | * @param mixed $class - имя класса трета, или сам объект |
||
309 | * @param string $altname - альтернативное имя, если хотим например иметь два одинаоковых терта в обработке |
||
310 | * @return unknown |
||
311 | */ |
||
312 | public function add_tret($class, $altname = false) |
||
313 | { |
||
314 | if(is_object($class)) |
||
315 | { |
||
316 | if(!is_a($class, "EMTTret")) |
||
317 | { |
||
318 | $this->error("You are adding Tret that doesn't inherit base class EMTTret", get_class($class)); |
||
319 | return false; |
||
320 | } |
||
321 | |||
322 | $class->EMT = $this; |
||
323 | $class->logging = $this->logging; |
||
324 | $this->tret_objects[($altname ? $altname : get_class($class))] = $class; |
||
325 | $this->trets[] = ($altname ? $altname : get_class($class)); |
||
326 | return true; |
||
327 | } |
||
328 | if(is_string($class)) |
||
329 | { |
||
330 | $obj = $this->create_object($class); |
||
331 | if($obj === null) |
||
332 | return false; |
||
333 | $this->tret_objects[($altname ? $altname : $class)] = $obj; |
||
334 | $this->trets[] = ($altname ? $altname : $class); |
||
335 | return true; |
||
336 | } |
||
337 | $this->error("Чтобы добавить трэт необходимо передать имя или объект"); |
||
338 | return false; |
||
339 | } |
||
340 | |||
341 | /** |
||
342 | * Получаем ТРЕТ по идентивикатору, т.е. заванию класса |
||
343 | * |
||
344 | * @param unknown_type $name |
||
345 | */ |
||
346 | public function get_tret($name) |
||
347 | { |
||
348 | if(isset($this->tret_objects[$name])) return $this->tret_objects[$name]; |
||
349 | foreach($this->trets as $tret) |
||
350 | { |
||
351 | if($tret == $name) |
||
352 | { |
||
353 | $this->_init(); |
||
354 | return $this->tret_objects[$name]; |
||
355 | } |
||
356 | if($this->get_short_tret($tret) == $name) |
||
357 | { |
||
358 | $this->_init(); |
||
359 | return $this->tret_objects[$tret]; |
||
360 | } |
||
361 | } |
||
362 | $this->error("Трэт с идентификатором $name не найден"); |
||
363 | return false; |
||
364 | } |
||
365 | |||
366 | /** |
||
367 | * Задаём текст для применения типографа |
||
368 | * |
||
369 | * @param string $text |
||
370 | */ |
||
371 | public function set_text($text) |
||
372 | { |
||
373 | $this->_text = $text; |
||
374 | } |
||
375 | |||
376 | |||
377 | |||
378 | /** |
||
379 | * Запустить типограф на выполнение |
||
380 | * |
||
381 | */ |
||
382 | public function apply($trets = null) |
||
383 | { |
||
384 | $this->ok = false; |
||
385 | |||
386 | $this->init(); |
||
387 | $this->_init(); |
||
388 | |||
389 | $atrets = $this->trets; |
||
390 | if(is_string($trets)) $atrets = array($trets); |
||
391 | elseif(is_array($trets)) $atrets = $trets; |
||
392 | |||
393 | $this->debug($this, 'init', $this->_text); |
||
394 | |||
395 | $this->_text = $this->safe_blocks($this->_text, true); |
||
396 | $this->debug($this, 'safe_blocks', $this->_text); |
||
397 | |||
398 | $this->_text = EMTLib::safe_tag_chars($this->_text, true); |
||
399 | $this->debug($this, 'safe_tag_chars', $this->_text); |
||
400 | |||
401 | $this->_text = EMTLib::clear_special_chars($this->_text); |
||
0 ignored issues
–
show
It seems like
\Fenrizbes\TypographBund...ial_chars($this->_text) can also be of type false . However, the property $_text is declared as type string . 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;
}
![]() |
|||
402 | $this->debug($this, 'clear_special_chars', $this->_text); |
||
403 | |||
404 | foreach ($atrets as $tret) |
||
405 | { |
||
406 | // если установлен режим разметки тэгов то выставим его |
||
407 | if($this->use_layout_set) |
||
408 | $this->tret_objects[$tret]->set_tag_layout_ifnotset($this->use_layout); |
||
409 | |||
410 | if($this->class_layout_prefix) |
||
411 | $this->tret_objects[$tret]->set_class_layout_prefix($this->class_layout_prefix); |
||
412 | |||
413 | // влючаем, если нужно |
||
414 | if($this->debug_enabled) $this->tret_objects[$tret]->debug_on(); |
||
415 | if($this->logging) $this->tret_objects[$tret]->logging = true; |
||
416 | |||
417 | // применяем трэт |
||
418 | //$this->tret_objects[$tret]->set_text(&$this->_text); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
80% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
419 | $this->tret_objects[$tret]->set_text($this->_text); |
||
420 | $this->tret_objects[$tret]->apply(); |
||
421 | |||
422 | // соберём ошибки если таковые есть |
||
423 | if(count($this->tret_objects[$tret]->errors)>0) |
||
424 | foreach($this->tret_objects[$tret]->errors as $err ) |
||
425 | $this->tret_error($tret, $err['info'], $err['data']); |
||
426 | |||
427 | // логгирование |
||
428 | if($this->logging) |
||
429 | if(count($this->tret_objects[$tret]->logs)>0) |
||
430 | foreach($this->tret_objects[$tret]->logs as $log ) |
||
431 | $this->tret_log($tret, $log['info'], $log['data']); |
||
432 | |||
433 | // отладка |
||
434 | if($this->debug_enabled) |
||
435 | foreach($this->tret_objects[$tret]->debug_info as $di) |
||
436 | { |
||
437 | $unsafetext = $di['text']; |
||
438 | $unsafetext = EMTLib::safe_tag_chars($unsafetext, false); |
||
439 | $unsafetext = $this->safe_blocks($unsafetext, false); |
||
440 | $this->debug($tret, $di['place'], $unsafetext, $di['text']); |
||
441 | } |
||
442 | |||
443 | |||
444 | } |
||
445 | |||
446 | |||
447 | $this->_text = $this->decode_internal_blocks($this->_text); |
||
448 | $this->debug($this, 'decode_internal_blocks', $this->_text); |
||
449 | |||
450 | if($this->is_on('dounicode')) |
||
451 | { |
||
452 | EMTLib::convert_html_entities_to_unicode($this->_text); |
||
453 | } |
||
454 | |||
455 | $this->_text = EMTLib::safe_tag_chars($this->_text, false); |
||
456 | $this->debug($this, 'unsafe_tag_chars', $this->_text); |
||
457 | |||
458 | $this->_text = $this->safe_blocks($this->_text, false); |
||
459 | $this->debug($this, 'unsafe_blocks', $this->_text); |
||
460 | |||
461 | if(!$this->disable_notg_replace) |
||
462 | { |
||
463 | $repl = array('<span class="_notg_start"></span>', '<span class="_notg_end"></span>'); |
||
464 | if($this->remove_notg) $repl = ""; |
||
465 | $this->_text = str_replace( array('<notg>','</notg>'), $repl , $this->_text); |
||
466 | } |
||
467 | $this->_text = trim($this->_text); |
||
468 | $this->ok = (count($this->errors)==0); |
||
469 | return $this->_text; |
||
470 | } |
||
471 | |||
472 | /** |
||
473 | * Получить содержимое <style></style> при использовании классов |
||
474 | * |
||
475 | * @param bool $list false - вернуть в виде строки для style или как массив |
||
476 | * @param bool $compact не выводить пустые классы |
||
477 | * @return string|array |
||
478 | */ |
||
479 | public function get_style($list = false, $compact = false) |
||
480 | { |
||
481 | $this->_init(); |
||
482 | |||
483 | $res = array(); |
||
484 | foreach ($this->trets as $tret) |
||
485 | { |
||
486 | $arr =$this->tret_objects[$tret]->classes; |
||
487 | if(!is_array($arr)) continue; |
||
488 | foreach($arr as $classname => $str) |
||
489 | { |
||
490 | if(($compact) && (!$str)) continue; |
||
491 | $clsname = ($this->class_layout_prefix ? $this->class_layout_prefix : "" ).(isset($this->tret_objects[$tret]->class_names[$classname]) ? $this->tret_objects[$tret]->class_names[$classname] :$classname); |
||
492 | $res[$clsname] = $str; |
||
493 | } |
||
494 | } |
||
495 | if($list) return $res; |
||
496 | $str = ""; |
||
497 | foreach($res as $k => $v) |
||
498 | { |
||
499 | $str .= ".$k { $v }\n"; |
||
500 | } |
||
501 | return $str; |
||
502 | } |
||
503 | |||
504 | |||
505 | |||
506 | |||
507 | |||
508 | /** |
||
509 | * Установить режим разметки, |
||
510 | * EMTLib::LAYOUT_STYLE - с помощью стилей |
||
511 | * EMTLib::LAYOUT_CLASS - с помощью классов |
||
512 | * EMTLib::LAYOUT_STYLE|EMTLib::LAYOUT_CLASS - оба метода |
||
513 | * |
||
514 | * @param int $layout |
||
515 | */ |
||
516 | public function set_tag_layout($layout = EMTLib::LAYOUT_STYLE) |
||
517 | { |
||
518 | $this->use_layout = $layout; |
||
0 ignored issues
–
show
The property
$use_layout was declared of type boolean , but $layout is of type integer . Maybe add a type cast?
This check looks for assignments to scalar types that may be of the wrong type. To ensure the code behaves as expected, it may be a good idea to add an explicit type cast. $answer = 42;
$correct = false;
$correct = (bool) $answer;
![]() |
|||
519 | $this->use_layout_set = true; |
||
520 | } |
||
521 | |||
522 | /** |
||
523 | * Установить префикс для классов |
||
524 | * |
||
525 | * @param string|bool $prefix если true то префикс 'emt_', иначе то, что передали |
||
526 | */ |
||
527 | public function set_class_layout_prefix($prefix ) |
||
528 | { |
||
529 | $this->class_layout_prefix = $prefix === true ? "emt_" : $prefix; |
||
0 ignored issues
–
show
It seems like
$prefix === true ? 'emt_' : $prefix can also be of type string . However, the property $class_layout_prefix is declared as type boolean . 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;
}
![]() |
|||
530 | } |
||
531 | |||
532 | /** |
||
533 | * Включить/отключить правила, согласно карте |
||
534 | * Формат карты: |
||
535 | * 'Название трэта 1' => array ( 'правило1', 'правило2' , ... ) |
||
536 | * 'Название трэта 2' => array ( 'правило1', 'правило2' , ... ) |
||
537 | * |
||
538 | * @param array $map |
||
539 | * @param boolean $disable если ложно, то $map соотвествует тем правилам, которые надо включить |
||
540 | * иначе это список правил, которые надо выключить |
||
541 | * @param boolean $strict строго, т.е. те которые не в списку будут тоже обработаны |
||
542 | */ |
||
543 | public function set_enable_map($map, $disable = false, $strict = true) |
||
544 | { |
||
545 | if(!is_array($map)) return; |
||
546 | $trets = array(); |
||
547 | foreach($map as $tret => $list) |
||
548 | { |
||
549 | $tretx = $this->get_tret($tret); |
||
0 ignored issues
–
show
$tret is of type integer|string , but the function expects a object<Fenrizbes\Typogra...undle\EMT\unknown_type> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
550 | if(!$tretx) |
||
551 | { |
||
552 | $this->log("Трэт $tret не найден при применении карты включаемых правил"); |
||
553 | continue; |
||
554 | } |
||
555 | $trets[] = $tretx; |
||
556 | |||
557 | if($list === true) // все |
||
558 | { |
||
559 | $tretx->activate(array(), !$disable , true); |
||
560 | } elseif(is_string($list)) { |
||
561 | $tretx->activate(array($list), $disable , $strict); |
||
562 | } elseif(is_array($list)) { |
||
563 | $tretx->activate($list, $disable , $strict); |
||
564 | } |
||
565 | } |
||
566 | if($strict) |
||
567 | { |
||
568 | foreach($this->trets as $tret) |
||
569 | { |
||
570 | if(in_array($this->tret_objects[$tret], $trets)) continue; |
||
571 | $this->tret_objects[$tret]->activate(array(), $disable , true); |
||
572 | } |
||
573 | } |
||
574 | |||
575 | } |
||
576 | |||
577 | |||
578 | /** |
||
579 | * Установлена ли настройка |
||
580 | * |
||
581 | * @param string $key |
||
582 | */ |
||
583 | public function is_on($key) |
||
584 | { |
||
585 | if(!isset($this->settings[$key])) return false; |
||
586 | $kk = $this->settings[$key]; |
||
587 | return ((strtolower($kk)=="on") || ($kk === "1") || ($kk === true) || ($kk === 1)); |
||
588 | } |
||
589 | |||
590 | |||
591 | /** |
||
592 | * Установить настройку |
||
593 | * |
||
594 | * @param mixed $selector |
||
595 | * @param string $setting |
||
0 ignored issues
–
show
There is no parameter named
$setting . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
|||
596 | * @param mixed $value |
||
597 | */ |
||
598 | protected function doset($selector, $key, $value) |
||
599 | { |
||
600 | $tret_pattern = false; |
||
601 | $rule_pattern = false; |
||
602 | //if(($selector === false) || ($selector === null) || ($selector === false) || ($selector === "*")) $type = 0; |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
54% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
603 | if(is_string($selector)) |
||
604 | { |
||
605 | if(strpos($selector,".")===false) |
||
606 | { |
||
607 | $tret_pattern = $selector; |
||
608 | } else { |
||
609 | $pa = explode(".", $selector); |
||
610 | $tret_pattern = $pa[0]; |
||
611 | array_shift($pa); |
||
612 | $rule_pattern = implode(".", $pa); |
||
613 | } |
||
614 | } |
||
615 | EMTLib::_process_selector_pattern($tret_pattern); |
||
616 | EMTLib::_process_selector_pattern($rule_pattern); |
||
617 | if($selector == "*") $this->settings[$key] = $value; |
||
618 | |||
619 | foreach ($this->trets as $tret) |
||
620 | { |
||
621 | $t1 = $this->get_short_tret($tret); |
||
622 | if(!EMTLib::_test_pattern($tret_pattern, $t1)) if(!EMTLib::_test_pattern($tret_pattern, $tret)) continue; |
||
623 | $tret_obj = $this->get_tret($tret); |
||
624 | if($key == "active") |
||
625 | { |
||
626 | foreach($tret_obj->rules as $rulename => $v) |
||
627 | { |
||
628 | if(!EMTLib::_test_pattern($rule_pattern, $rulename)) continue; |
||
629 | View Code Duplication | if((strtolower($value) === "on") || ($value===1) || ($value === true) || ($value=="1")) $tret_obj->enable_rule($rulename); |
|
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. ![]() |
|||
630 | View Code Duplication | if((strtolower($value) === "off") || ($value===0) || ($value === false) || ($value=="0")) $tret_obj->disable_rule($rulename); |
|
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. ![]() |
|||
631 | } |
||
632 | } else { |
||
633 | if($rule_pattern===false) |
||
634 | { |
||
635 | $tret_obj->set($key, $value); |
||
636 | } else { |
||
637 | foreach($tret_obj->rules as $rulename => $v) |
||
638 | { |
||
639 | if(!EMTLib::_test_pattern($rule_pattern, $rulename)) continue; |
||
640 | $tret_obj->set_rule($rulename, $key, $value); |
||
641 | } |
||
642 | } |
||
643 | } |
||
644 | } |
||
645 | } |
||
646 | |||
647 | |||
648 | /** |
||
649 | * Установить настройки для тертов и правил |
||
650 | * 1. если селектор является массивом, то тогда утсановка правил будет выполнена для каждого |
||
651 | * элемента этого массива, как отдельного селектора. |
||
652 | * 2. Если $key не является массивом, то эта настрока будет проставлена согласно селектору |
||
653 | * 3. Если $key массив - то будет задана группа настроек |
||
654 | * - если $value массив , то настройки определяются по ключам из массива $key, а значения из $value |
||
655 | * - иначе, $key содержит ключ-значение как массив |
||
656 | * |
||
657 | * @param mixed $selector |
||
658 | * @param mixed $key |
||
659 | * @param mixed $value |
||
660 | */ |
||
661 | public function set($selector, $key , $value = false) |
||
662 | { |
||
663 | if(is_array($selector)) |
||
664 | { |
||
665 | foreach($selector as $val) $this->set($val, $key, $value); |
||
666 | return; |
||
667 | } |
||
668 | if(is_array($key)) |
||
669 | { |
||
670 | foreach($key as $x => $y) |
||
671 | { |
||
672 | if(is_array($value)) |
||
673 | { |
||
674 | $kk = $y; |
||
675 | $vv = $value[$x]; |
||
676 | } else { |
||
677 | $kk = $x; |
||
678 | $vv = $y; |
||
679 | } |
||
680 | $this->set($selector, $kk, $vv); |
||
681 | } |
||
682 | } |
||
683 | $this->doset($selector, $key, $value); |
||
684 | } |
||
685 | |||
686 | |||
687 | /** |
||
688 | * Возвращает список текущих третов, которые установлены |
||
689 | * |
||
690 | */ |
||
691 | public function get_trets_list() |
||
692 | { |
||
693 | return $this->trets; |
||
694 | } |
||
695 | |||
696 | /** |
||
697 | * Установка одной метанастройки |
||
698 | * |
||
699 | * @param string $name |
||
700 | * @param mixed $value |
||
701 | */ |
||
702 | public function do_setup($name, $value) |
||
703 | { |
||
704 | |||
705 | } |
||
706 | |||
707 | |||
708 | /** |
||
709 | * Установить настройки |
||
710 | * |
||
711 | * @param array $setupmap |
||
712 | */ |
||
713 | public function setup($setupmap) |
||
714 | { |
||
715 | if(!is_array($setupmap)) return; |
||
716 | |||
717 | if(isset($setupmap['map']) || isset($setupmap['maps'])) |
||
718 | { |
||
719 | if(isset($setupmap['map'])) |
||
720 | { |
||
721 | $ret['map'] = $test['params']['map']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$ret was never initialized. Although not strictly required by PHP, it is generally a good practice to add $ret = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
722 | $ret['disable'] = $test['params']['map_disable']; |
||
723 | $ret['strict'] = $test['params']['map_strict']; |
||
724 | $test['params']['maps'] = array($ret); |
||
725 | unset($setupmap['map']); |
||
726 | unset($setupmap['map_disable']); |
||
727 | unset($setupmap['map_strict']); |
||
728 | } |
||
729 | if(is_array($setupmap['maps'])) |
||
730 | { |
||
731 | foreach($setupmap['maps'] as $map) |
||
732 | { |
||
733 | $this->set_enable_map |
||
734 | ($map['map'], |
||
735 | isset($map['disable']) ? $map['disable'] : false, |
||
736 | isset($map['strict']) ? $map['strict'] : false |
||
737 | ); |
||
738 | } |
||
739 | } |
||
740 | unset($setupmap['maps']); |
||
741 | } |
||
742 | |||
743 | |||
744 | foreach($setupmap as $k => $v) $this->do_setup($k , $v); |
||
745 | } |
||
746 | |||
747 | |||
748 | |||
749 | |||
750 | } |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.