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 |
||
| 37 | class Yaml |
||
| 38 | { |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Dump an PHP array as a YAML string |
||
| 42 | * |
||
| 43 | * @param mixed $var Variable which will be dumped |
||
| 44 | * @param integer $inline Nesting level where you switch to inline YAML |
||
| 45 | * @param integer $indent Number of spaces to indent for nested nodes |
||
| 46 | * |
||
| 47 | * @return string|bool YAML string or false on error |
||
| 48 | */ |
||
| 49 | 1 | public static function dump($var, $inline = 4, $indent = 4) |
|
| 59 | |||
| 60 | /** |
||
| 61 | * Load a YAML string into a PHP array |
||
| 62 | * |
||
| 63 | * @param string $yamlString YAML dump string |
||
| 64 | * |
||
| 65 | * @return array|boolean PHP array or false on error |
||
| 66 | */ |
||
| 67 | 1 | public static function load($yamlString) |
|
| 77 | |||
| 78 | /** |
||
| 79 | * Read a file containing YAML into a PHP array |
||
| 80 | * |
||
| 81 | * @param string $yamlFile filename of YAML file |
||
| 82 | * |
||
| 83 | * @return array|boolean PHP array or false on error |
||
| 84 | */ |
||
| 85 | 3 | View Code Duplication | public static function read($yamlFile) |
| 96 | |||
| 97 | /** |
||
| 98 | * Save a PHP array as a YAML file |
||
| 99 | * |
||
| 100 | * @param array $var variable which will be dumped |
||
| 101 | * @param string $yamlFile filename of YAML file |
||
| 102 | * @param integer $inline Nesting level where you switch to inline YAML |
||
| 103 | * @param integer $indent Number of spaces to indent for nested nodes |
||
| 104 | * |
||
| 105 | * @return integer|boolean number of bytes written, or false on error |
||
| 106 | */ |
||
| 107 | 2 | View Code Duplication | public static function save($var, $yamlFile, $inline = 4, $indent = 4) |
| 118 | |||
| 119 | /** |
||
| 120 | * Dump an PHP array as a YAML string with a php wrapper |
||
| 121 | * |
||
| 122 | * The wrap is a php header that surrounds the yaml with section markers, |
||
| 123 | * '---' and '...' along with php comment markers. The php wrapper keeps the |
||
| 124 | * yaml file contents from being revealed by serving the file directly from |
||
| 125 | * a poorly configured server. |
||
| 126 | * |
||
| 127 | * @param mixed $var Variable which will be dumped |
||
| 128 | * @param integer $inline Nesting level where you switch to inline YAML |
||
| 129 | * @param integer $indent Number of spaces to indent for nested nodes |
||
| 130 | * |
||
| 131 | * @return string|boolean YAML string or false on error |
||
| 132 | */ |
||
| 133 | 2 | public static function dumpWrapped($var, $inline = 4, $indent = 4) |
|
| 144 | |||
| 145 | /** |
||
| 146 | * Load a YAML string with a php wrapper into a PHP array |
||
| 147 | * |
||
| 148 | * The wrap is a php header that surrounds the yaml with section markers, |
||
| 149 | * '---' and '...' along with php comment markers. The php wrapper keeps the |
||
| 150 | * yaml file contents from being revealed by serving the file directly from |
||
| 151 | * a poorly configured server. |
||
| 152 | * |
||
| 153 | * @param string $yamlString YAML dump string |
||
| 154 | * |
||
| 155 | * @return array|boolean PHP array or false on error |
||
| 156 | */ |
||
| 157 | 3 | public static function loadWrapped($yamlString) |
|
| 183 | |||
| 184 | /** |
||
| 185 | * Read a file containing YAML with a php wrapper into a PHP array |
||
| 186 | * |
||
| 187 | * The wrap is a php header that surrounds the yaml with section markers, |
||
| 188 | * '---' and '...' along with php comment markers. The php wrapper keeps the |
||
| 189 | * yaml file contents from being revealed by serving the file directly from |
||
| 190 | * a poorly configured server. |
||
| 191 | * |
||
| 192 | * @param string $yamlFile filename of YAML file |
||
| 193 | * |
||
| 194 | * @return array|boolean PHP array or false on error |
||
| 195 | */ |
||
| 196 | 1 | View Code Duplication | public static function readWrapped($yamlFile) |
| 207 | |||
| 208 | /** |
||
| 209 | * Save a PHP array as a YAML file with a php wrapper |
||
| 210 | * |
||
| 211 | * The wrap is a php header that surrounds the yaml with section markers, |
||
| 212 | * '---' and '...' along with php comment markers. The php wrapper keeps the |
||
| 213 | * yaml file contents from being revealed by serving the file directly from |
||
| 214 | * a poorly configured server. |
||
| 215 | * |
||
| 216 | * @param array $var variable which will be dumped |
||
| 217 | * @param string $yamlFile filename of YAML file |
||
| 218 | * @param integer $inline Nesting level where you switch to inline YAML |
||
| 219 | * @param integer $indent Number of spaces to indent for nested nodes |
||
| 220 | * |
||
| 221 | * @return integer|boolean number of bytes written, or false on error |
||
| 222 | */ |
||
| 223 | 1 | View Code Duplication | public static function saveWrapped($var, $yamlFile, $inline = 4, $indent = 4) |
| 234 | |||
| 235 | /** |
||
| 236 | * @param \Exception $e throwable to log |
||
| 237 | */ |
||
| 238 | protected static function logError($e) |
||
| 246 | } |
||
| 247 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.