@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function addManyToMap(array $elements) |
100 | 100 | { |
101 | - foreach($elements as $name => $element){ |
|
101 | + foreach ($elements as $name => $element) { |
|
102 | 102 | $this->addOneToMap($name, $element); |
103 | 103 | } |
104 | 104 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | |
231 | 231 | $element->addAttributes($this->escapeAttributes($attributes)); |
232 | 232 | |
233 | - foreach($children as $child){ |
|
233 | + foreach ($children as $child) { |
|
234 | 234 | $element->addChild($this->escape($child)); |
235 | 235 | } |
236 | 236 | |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | |
247 | 247 | $attributes = $htmlElement->escapeAttributes($attributes); |
248 | 248 | |
249 | - foreach($children as $key => $child){ |
|
249 | + foreach ($children as $key => $child) { |
|
250 | 250 | $children[$key] = $htmlElement->escape($child); |
251 | 251 | } |
252 | 252 | |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | */ |
269 | 269 | static public function __callStatic($type, $arguments) |
270 | 270 | { |
271 | - switch(count($arguments)){ |
|
271 | + switch (count($arguments)) { |
|
272 | 272 | case 0: |
273 | 273 | return self::create($type); |
274 | 274 | break; |
@@ -296,17 +296,17 @@ discard block |
||
296 | 296 | */ |
297 | 297 | public function escape(ElementInterface $element) |
298 | 298 | { |
299 | - if($this->escapeHtml && !in_array($element->getType(), $this->specialEscapingTypes)){ |
|
299 | + if ($this->escapeHtml && !in_array($element->getType(), $this->specialEscapingTypes)) { |
|
300 | 300 | $element->setText($this->escaper->escapeHtml($element->getText())); |
301 | 301 | } |
302 | 302 | |
303 | 303 | $element->setAttributes($this->escapeAttributes($element->getAttributes())); |
304 | 304 | |
305 | - if($this->escapeJs && 'script' == $element->getType()){ |
|
305 | + if ($this->escapeJs && 'script' == $element->getType()) { |
|
306 | 306 | $element->setText($this->escaper->escapeJs($element->getText())); |
307 | 307 | } |
308 | 308 | |
309 | - if($this->escapeCss && 'style' == $element->getType()){ |
|
309 | + if ($this->escapeCss && 'style' == $element->getType()) { |
|
310 | 310 | $element->setText($this->escaper->escapeCss($element->getText())); |
311 | 311 | } |
312 | 312 | |
@@ -318,14 +318,14 @@ discard block |
||
318 | 318 | */ |
319 | 319 | public function escapeAttributes(array $attributes) |
320 | 320 | { |
321 | - if($this->escapeHtmlAttr || $this->escapeUrl){ |
|
322 | - foreach($attributes as $attr => $value){ |
|
323 | - if('href' == $attr){ |
|
324 | - if($this->escapeUrl){ |
|
321 | + if ($this->escapeHtmlAttr || $this->escapeUrl) { |
|
322 | + foreach ($attributes as $attr => $value) { |
|
323 | + if ('href' == $attr) { |
|
324 | + if ($this->escapeUrl) { |
|
325 | 325 | $value = $this->escaper->escapeUrl($value); |
326 | 326 | } |
327 | 327 | } else { |
328 | - if($this->escapeHtmlAttr){ |
|
328 | + if ($this->escapeHtmlAttr) { |
|
329 | 329 | $value = $this->escaper->escapeHtmlAttr($value); |
330 | 330 | } |
331 | 331 | } |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | |
358 | 358 | $instance = new $class($type, $text, $attributes); |
359 | 359 | |
360 | - if(!$instance instanceof ElementInterface){ |
|
360 | + if (!$instance instanceof ElementInterface) { |
|
361 | 361 | throw new InvalidElementException(sprintf( |
362 | 362 | 'The element "%s" does not implement the %s', |
363 | 363 | get_class($instance), |
@@ -366,13 +366,13 @@ discard block |
||
366 | 366 | } |
367 | 367 | |
368 | 368 | $children = array(); |
369 | - foreach((array) $element['children'] as $child){ |
|
369 | + foreach ((array) $element['children'] as $child) { |
|
370 | 370 | $children[] = $this->getInstance($child, $parameters); |
371 | 371 | } |
372 | 372 | |
373 | 373 | $instance->setChildren($children); |
374 | 374 | |
375 | - if(null !== $element['parent']){ |
|
375 | + if (null !== $element['parent']) { |
|
376 | 376 | $parent = $this->getInstance($element['parent'], $parameters); |
377 | 377 | |
378 | 378 | $parent->addChild($instance); |
@@ -394,38 +394,38 @@ discard block |
||
394 | 394 | { |
395 | 395 | $getCurrent = true; |
396 | 396 | |
397 | - if(is_array($name)){ |
|
397 | + if (is_array($name)) { |
|
398 | 398 | $current = $name; |
399 | 399 | $name = $current['name']; |
400 | 400 | |
401 | 401 | $getCurrent = false; |
402 | 402 | } |
403 | 403 | |
404 | - if($this->alreadyResolved($name)){ |
|
404 | + if ($this->alreadyResolved($name)) { |
|
405 | 405 | return $this->resolved[$name]; |
406 | 406 | } |
407 | 407 | |
408 | - if($getCurrent && !$this->exists($name)){ |
|
408 | + if ($getCurrent && !$this->exists($name)) { |
|
409 | 409 | throw new UndefinedElementException(sprintf('The element with name "%s" does not exist.', $name)); |
410 | 410 | } |
411 | 411 | |
412 | - if($mainCall){ |
|
412 | + if ($mainCall) { |
|
413 | 413 | $this->validBranch($name); |
414 | 414 | } |
415 | 415 | |
416 | - if($getCurrent){ |
|
416 | + if ($getCurrent) { |
|
417 | 417 | $current = $this->getCurrentElement($name); |
418 | 418 | } |
419 | 419 | |
420 | - foreach($this->defaults as $default => $value){ |
|
421 | - if(!isset($current[$default])){ |
|
420 | + foreach ($this->defaults as $default => $value) { |
|
421 | + if (!isset($current[$default])) { |
|
422 | 422 | $current[$default] = $value; |
423 | 423 | } |
424 | 424 | } |
425 | 425 | |
426 | 426 | $current = $this->replaceParameters($current, $parameters); |
427 | 427 | |
428 | - foreach((array) $current['extends'] as $extend){ |
|
428 | + foreach ((array) $current['extends'] as $extend) { |
|
429 | 429 | $extend = $this->resolveElement($extend, $parameters); |
430 | 430 | $current = $this->extendElement($extend, $current); |
431 | 431 | } |
@@ -462,8 +462,8 @@ discard block |
||
462 | 462 | { |
463 | 463 | $getCurrent = true; |
464 | 464 | |
465 | - if(is_array($name)){ |
|
466 | - if(!isset($name['name'])){ |
|
465 | + if (is_array($name)) { |
|
466 | + if (!isset($name['name'])) { |
|
467 | 467 | throw new InvalidElementException(sprintf( |
468 | 468 | 'Elements defined dynamically in parent or children must define a name.' |
469 | 469 | )); |
@@ -479,22 +479,22 @@ discard block |
||
479 | 479 | |
480 | 480 | $circular[] = $name; |
481 | 481 | |
482 | - if($getCurrent){ |
|
482 | + if ($getCurrent) { |
|
483 | 483 | $current = $this->getCurrentElement($name); |
484 | 484 | } |
485 | 485 | |
486 | - if(isset($current['class']) && !class_exists($current['class'])){ |
|
486 | + if (isset($current['class']) && !class_exists($current['class'])) { |
|
487 | 487 | throw new InvalidElementException(sprintf( |
488 | 488 | 'The element "%s" define a class which doesn\'t exist.', |
489 | 489 | $name |
490 | 490 | )); |
491 | 491 | } |
492 | 492 | |
493 | - foreach($this->checks as $check){ |
|
494 | - if(isset($current[$check])){ |
|
493 | + foreach ($this->checks as $check) { |
|
494 | + if (isset($current[$check])) { |
|
495 | 495 | $currentCheck = (array) $current[$check]; |
496 | 496 | |
497 | - if(in_array($name, $currentCheck)){ |
|
497 | + if (in_array($name, $currentCheck)) { |
|
498 | 498 | throw new InvalidElementException(sprintf( |
499 | 499 | 'Element "%s" cannot define himself as %s.', |
500 | 500 | $name, |
@@ -502,8 +502,8 @@ discard block |
||
502 | 502 | )); |
503 | 503 | } |
504 | 504 | |
505 | - foreach($currentCheck as $cc){ |
|
506 | - if(!is_array($cc) && !$this->exists($cc)){ |
|
505 | + foreach ($currentCheck as $cc) { |
|
506 | + if (!is_array($cc) && !$this->exists($cc)) { |
|
507 | 507 | throw new UndefinedElementException(sprintf( |
508 | 508 | 'The element "%s" defines a %s "%s" wich doesn\'t exist.', |
509 | 509 | $name, |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | )); |
513 | 513 | } |
514 | 514 | |
515 | - if(!is_array($cc) && in_array($cc, $circular)){ |
|
515 | + if (!is_array($cc) && in_array($cc, $circular)) { |
|
516 | 516 | $circular[] = $cc; |
517 | 517 | |
518 | 518 | throw new InvalidElementException(sprintf( |
@@ -569,12 +569,12 @@ discard block |
||
569 | 569 | */ |
570 | 570 | private function extendAttributes(array $from, array $to) |
571 | 571 | { |
572 | - foreach($from as $key => $value){ |
|
573 | - if(in_array($key, $this->mergeableAttributes) && isset($to[$key])){ |
|
572 | + foreach ($from as $key => $value) { |
|
573 | + if (in_array($key, $this->mergeableAttributes) && isset($to[$key])) { |
|
574 | 574 | $to[$key] = array_merge((array) $to[$key], (array) $value); |
575 | - } elseif(!isset($to[$key])){ |
|
575 | + } elseif (!isset($to[$key])) { |
|
576 | 576 | $to[$key] = $value; |
577 | - } elseif(is_array($value)){ |
|
577 | + } elseif (is_array($value)) { |
|
578 | 578 | $to[$key] = $this->extendAttributes($value, $to[$key]); |
579 | 579 | } |
580 | 580 | } |
@@ -592,13 +592,13 @@ discard block |
||
592 | 592 | */ |
593 | 593 | private function replaceParameters(array $element, array $parameters) |
594 | 594 | { |
595 | - foreach($element as $key => $value){ |
|
596 | - if(is_array($value)){ |
|
595 | + foreach ($element as $key => $value) { |
|
596 | + if (is_array($value)) { |
|
597 | 597 | $element[$key] = $this->replaceParameters($value, $parameters); |
598 | 598 | } |
599 | 599 | |
600 | - if(is_string($value)){ |
|
601 | - foreach($parameters as $parameter => $replace){ |
|
600 | + if (is_string($value)) { |
|
601 | + foreach ($parameters as $parameter => $replace) { |
|
602 | 602 | $value = str_replace('%'.$parameter.'%', $replace, $value); |
603 | 603 | } |
604 | 604 |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function setType($type = null) |
43 | 43 | { |
44 | - if(null !== $type){ |
|
44 | + if (null !== $type) { |
|
45 | 45 | $this->type = $type; |
46 | 46 | } |
47 | 47 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function setText($text = null) |
63 | 63 | { |
64 | - if(null !== $text){ |
|
64 | + if (null !== $text) { |
|
65 | 65 | $this->text = $text; |
66 | 66 | } |
67 | 67 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function addAttributes(array $attributes) |
93 | 93 | { |
94 | - foreach($attributes as $key => $value){ |
|
94 | + foreach ($attributes as $key => $value) { |
|
95 | 95 | $this->addAttribute($key, $value); |
96 | 96 | } |
97 | 97 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function addChildren(array $children) |
135 | 135 | { |
136 | - foreach($children as $child){ |
|
136 | + foreach ($children as $child) { |
|
137 | 137 | $this->addChild($child); |
138 | 138 | } |
139 | 139 | |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | */ |
211 | 211 | private function renderChildren(Markup $root) |
212 | 212 | { |
213 | - foreach($this->children as $child){ |
|
213 | + foreach ($this->children as $child) { |
|
214 | 214 | $child->render($root); |
215 | 215 | } |
216 | 216 | } |
@@ -223,13 +223,13 @@ discard block |
||
223 | 223 | */ |
224 | 224 | private function renderAttributes(Markup $element, array $attributes) |
225 | 225 | { |
226 | - foreach($attributes as $attr => $value){ |
|
227 | - if(is_array($value)){ |
|
226 | + foreach ($attributes as $attr => $value) { |
|
227 | + if (is_array($value)) { |
|
228 | 228 | $glue = 'style' == $attr ? '; ' : ' '; |
229 | 229 | $value = implode($glue, $value); |
230 | 230 | } |
231 | 231 | |
232 | - if(null !== $value){ |
|
232 | + if (null !== $value) { |
|
233 | 233 | $element->set($attr, $value); |
234 | 234 | } |
235 | 235 | } |