Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 20 | class Minify |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var \ArjanSchouten\HtmlMinifier\Placeholders\PlaceholderInterface[] |
||
| 24 | */ |
||
| 25 | protected $placeholders = [ |
||
| 26 | PhpPlaceholder::class, |
||
| 27 | CommentPlaceholder::class, |
||
| 28 | WhitespacePlaceholder::class, |
||
| 29 | ]; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var \ArjanSchouten\HtmlMinifier\Minifiers\MinifierInterface[] |
||
| 33 | */ |
||
| 34 | protected $minifiers = [ |
||
| 35 | CommentMinifier::class, |
||
| 36 | WhitespaceMinifier::class, |
||
| 37 | AttributeQuoteMinifier::class, |
||
| 38 | EmptyAttributeMinifier::class, |
||
| 39 | OptionalElementMinifier::class, |
||
| 40 | BooleanAttributeMinifier::class, |
||
| 41 | JavascriptEventsMinifier::class, |
||
| 42 | RedundantAttributeMinifier::class, |
||
| 43 | ]; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param \ArjanSchouten\HtmlMinifier\MinifyContext $context |
||
| 47 | * @param array $options |
||
| 48 | * |
||
| 49 | * @return \ArjanSchouten\HtmlMinifier\MinifyContext |
||
| 50 | */ |
||
| 51 | 3 | public function run(MinifyContext $context, $options = []) |
|
| 59 | |||
| 60 | /** |
||
| 61 | * @param \ArjanSchouten\HtmlMinifier\MinifyContext $context |
||
| 62 | * |
||
| 63 | * @return \ArjanSchouten\HtmlMinifier\MinifyContext |
||
| 64 | */ |
||
| 65 | 3 | protected function placeholders(MinifyContext $context) |
|
| 74 | |||
| 75 | /** |
||
| 76 | * @param \ArjanSchouten\HtmlMinifier\MinifyContext $context |
||
| 77 | * @param array $options |
||
| 78 | * |
||
| 79 | * @return \ArjanSchouten\HtmlMinifier\MinifyContext |
||
| 80 | */ |
||
| 81 | 3 | protected function minifiers(MinifyContext $context, $options = []) |
|
| 95 | |||
| 96 | /** |
||
| 97 | * Checks if all minifiers should be runned. |
||
| 98 | * |
||
| 99 | * @param array $options |
||
| 100 | * |
||
| 101 | * @return bool |
||
| 102 | */ |
||
| 103 | 3 | protected function runAll($options = []) |
|
| 107 | |||
| 108 | /** |
||
| 109 | * Check whether an option is set in the options aray. |
||
| 110 | * |
||
| 111 | * @param string $provides |
||
| 112 | * @param array $options |
||
| 113 | * |
||
| 114 | * @return bool |
||
| 115 | */ |
||
| 116 | 2 | protected function isOptionSet($provides, $options = []) |
|
| 126 | |||
| 127 | /** |
||
| 128 | * Restore placeholders with their original content. |
||
| 129 | * |
||
| 130 | * @param \ArjanSchouten\HtmlMinifier\MinifyContext $context |
||
| 131 | * |
||
| 132 | * @return \ArjanSchouten\HtmlMinifier\MinifyContext |
||
| 133 | */ |
||
| 134 | 3 | protected function restore(MinifyContext $context) |
|
| 140 | |||
| 141 | /** |
||
| 142 | * @return \ArjanSchouten\HtmlMinifier\Placeholders\PlaceholderInterface[] |
||
| 143 | */ |
||
| 144 | 1 | public function getPlaceholders() |
|
| 148 | |||
| 149 | /** |
||
| 150 | * Add a placeholder strategy to the registered placeholders. |
||
| 151 | * |
||
| 152 | * @param string $placeholder |
||
| 153 | * |
||
| 154 | * @return \ArjanSchouten\HtmlMinifier\Placeholders\PlaceholderInterface[] |
||
|
|
|||
| 155 | */ |
||
| 156 | 1 | View Code Duplication | public function addPlaceholder($placeholder) |
| 168 | |||
| 169 | /** |
||
| 170 | * @return \ArjanSchouten\HtmlMinifier\Minifiers\MinifierInterface[] |
||
| 171 | */ |
||
| 172 | 1 | public function getMinifiers() |
|
| 176 | |||
| 177 | /** |
||
| 178 | * Add a placeholder strategy to the registered placeholders. |
||
| 179 | * |
||
| 180 | * @param string $minifier |
||
| 181 | * |
||
| 182 | * @return \ArjanSchouten\HtmlMinifier\Minifiers\MinifierInterface[] |
||
| 183 | */ |
||
| 184 | 1 | View Code Duplication | public function addMinifier($minifier) |
| 196 | |||
| 197 | /** |
||
| 198 | * Get the classname without the namespace. |
||
| 199 | * |
||
| 200 | * @param $object |
||
| 201 | * |
||
| 202 | * @return string |
||
| 203 | */ |
||
| 204 | 3 | private function getClassName($object) |
|
| 215 | } |
||
| 216 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.