| Conditions | 11 |
| Paths | 8 |
| Total Lines | 32 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 96 | public function pageAddAsset($type, $value, $weight = AssetBag::WEIGHT_DEFAULT) |
||
| 97 | { |
||
| 98 | if (empty($type) || empty($value)) { |
||
| 99 | throw new \InvalidArgumentException($this->translator->__('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); |
||
| 100 | } |
||
| 101 | if (!in_array($type, ['stylesheet', 'javascript', 'header', 'footer']) || !is_numeric($weight)) { |
||
| 102 | throw new \InvalidArgumentException($this->translator->__('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); |
||
| 103 | } |
||
| 104 | |||
| 105 | // ensure proper variable types |
||
| 106 | $value = (string) $value; |
||
| 107 | $type = (string) $type; |
||
| 108 | $weight = (int) $weight; |
||
| 109 | |||
| 110 | // @todo remove this code block at Core-2.0 because all themes are twig based |
||
| 111 | $themeBundle = $this->engine->getTheme(); |
||
| 112 | if (isset($themeBundle) && !$themeBundle->isTwigBased()) { |
||
| 113 | \PageUtil::addVar($type, $value); |
||
| 114 | |||
| 115 | return; |
||
| 116 | } |
||
| 117 | |||
| 118 | if ('stylesheet' == $type) { |
||
| 119 | $this->styleSheets->add([$value => $weight]); |
||
| 120 | } elseif ('javascript' == $type) { |
||
| 121 | $this->scripts->add([$value => $weight]); |
||
| 122 | } elseif ('header' == $type) { |
||
| 123 | $this->headers->add([$value => $weight]); |
||
| 124 | } elseif ('footer' == $type) { |
||
| 125 | $this->footers->add([$value => $weight]); |
||
| 126 | } |
||
| 127 | } |
||
| 128 | } |
||
| 129 |