| Conditions | 7 |
| Paths | 1 |
| Total Lines | 57 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 2 | Features | 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 |
||
| 76 | public function registerBladeDirectives() |
||
| 77 | { |
||
| 78 | $names = [ |
||
| 79 | 'keywords', |
||
| 80 | 'url', |
||
| 81 | 'author', |
||
| 82 | 'description', |
||
| 83 | 'title', |
||
| 84 | ]; |
||
| 85 | |||
| 86 | Blade::directive('meta', function ($expression) use ($names) { |
||
| 87 | $meta = ''; |
||
| 88 | $expression = trim($expression, '\"\''); |
||
| 89 | $metaData = metaData($expression); |
||
| 90 | $type = in_array($expression, $names) ? "name" : "property"; |
||
| 91 | |||
| 92 | if (is_array($metaData)) { |
||
| 93 | foreach ($metaData as $key => $og) { |
||
| 94 | $type = in_array($key, $names) ? "name" : "property"; |
||
| 95 | |||
| 96 | $meta .= "<meta {$type}='{$key}' content='{$og}'/>\n"; |
||
| 97 | } |
||
| 98 | } else { |
||
| 99 | $meta .= "<meta {$type}='{$expression}' content='{$metaData}'/>\n"; |
||
| 100 | } |
||
| 101 | return $meta; |
||
| 102 | }); |
||
| 103 | Blade::directive('keywords', function () { |
||
| 104 | return "<meta name='keywords' content='" . metaKeywords() . "'/>\n"; |
||
| 105 | }); |
||
| 106 | Blade::directive('url', function () { |
||
| 107 | return "<meta name='url' content='" . metaUrl() . "'/>\n"; |
||
| 108 | }); |
||
| 109 | Blade::directive('author', function () { |
||
| 110 | return "<meta name='author' content='" . metaAuthor() . "'/>\n"; |
||
| 111 | }); |
||
| 112 | Blade::directive('description', function () { |
||
| 113 | return "<meta name='description' content='" . metaDescription() . "'/>\n"; |
||
| 114 | }); |
||
| 115 | Blade::directive('title', function () { |
||
| 116 | return "<meta name='title' content='" . metaTitle() . "'/>\n"; |
||
| 117 | }); |
||
| 118 | Blade::directive('openGraph', function ($expression) { |
||
| 119 | $expression = trim($expression, '\"\''); |
||
| 120 | $meta = ''; |
||
| 121 | $metaOpenGraph = metaOpenGraph($expression); |
||
| 122 | if (is_array($metaOpenGraph)) { |
||
| 123 | foreach ($metaOpenGraph as $key => $og) { |
||
| 124 | $meta .= "<meta property='{$key}' content='{$og}'/>\n"; |
||
| 125 | } |
||
| 126 | } else { |
||
| 127 | $meta .= "<meta property='{$expression}' content='{$metaOpenGraph}'/>\n"; |
||
| 128 | } |
||
| 129 | return $meta; |
||
| 130 | }); |
||
| 131 | Blade::directive('titleDynamic', function () { |
||
| 132 | return metaTitleDynamic(); |
||
| 133 | }); |
||
| 137 |