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 |
||
39 | class Yaml |
||
40 | { |
||
41 | |||
42 | /** |
||
43 | * Dump an PHP array as a YAML string |
||
44 | * |
||
45 | * @param mixed $var Variable which will be dumped |
||
46 | * @param integer $inline Nesting level where you switch to inline YAML |
||
47 | * @param integer $indent Number of spaces to indent for nested nodes |
||
48 | * |
||
49 | * @return string|bool YAML string or false on error |
||
50 | */ |
||
51 | 1 | View Code Duplication | public static function dump($var, $inline = 4, $indent = 4) |
61 | |||
62 | /** |
||
63 | * Load a YAML string into a PHP array |
||
64 | * |
||
65 | * @param string $yamlString YAML dump string |
||
66 | * |
||
67 | * @return array|boolean PHP array or false on error |
||
68 | */ |
||
69 | 1 | public static function load($yamlString) |
|
79 | |||
80 | /** |
||
81 | * Read a file containing YAML into a PHP array |
||
82 | * |
||
83 | * @param string $yamlFile filename of YAML file |
||
84 | * |
||
85 | * @return array|boolean PHP array or false on error |
||
86 | */ |
||
87 | 3 | View Code Duplication | public static function read($yamlFile) |
88 | { |
||
89 | try { |
||
90 | 3 | $yamlString = file_get_contents($yamlFile); |
|
91 | 3 | $ret = VendorYaml::parse($yamlString); |
|
92 | 3 | } catch (\Exception $e) { |
|
93 | \Xoops::getInstance()->events()->triggerEvent('core.exception', $e); |
||
94 | $ret = false; |
||
95 | } |
||
96 | 3 | return $ret; |
|
97 | 1 | } |
|
98 | |||
99 | /** |
||
100 | * Save a PHP array as a YAML file |
||
101 | * |
||
102 | * @param array $var variable which will be dumped |
||
103 | * @param string $yamlFile filename of YAML file |
||
104 | * @param integer $inline Nesting level where you switch to inline YAML |
||
105 | * @param integer $indent Number of spaces to indent for nested nodes |
||
106 | * |
||
107 | * @return integer|boolean number of bytes written, or false on error |
||
108 | */ |
||
109 | 2 | View Code Duplication | public static function save($var, $yamlFile, $inline = 4, $indent = 4) |
120 | |||
121 | /** |
||
122 | * Dump an PHP array as a YAML string with a php wrapper |
||
123 | * |
||
124 | * The wrap is a php header that surrounds the yaml with section markers, |
||
125 | * '---' and '...' along with php comment markers. The php wrapper keeps the |
||
126 | * yaml file contents from being revealed by serving the file directly from |
||
127 | * a poorly configured server. |
||
128 | * |
||
129 | * @param mixed $var Variable which will be dumped |
||
130 | * @param integer $inline Nesting level where you switch to inline YAML |
||
131 | * @param integer $indent Number of spaces to indent for nested nodes |
||
132 | * |
||
133 | * @return string|boolean YAML string or false on error |
||
134 | */ |
||
135 | 1 | public static function dumpWrapped($var, $inline = 4, $indent = 4) |
|
146 | |||
147 | /** |
||
148 | * Load a YAML string with a php wrapper into a PHP array |
||
149 | * |
||
150 | * The wrap is a php header that surrounds the yaml with section markers, |
||
151 | * '---' and '...' along with php comment markers. The php wrapper keeps the |
||
152 | * yaml file contents from being revealed by serving the file directly from |
||
153 | * a poorly configured server. |
||
154 | * |
||
155 | * @param string $yamlString YAML dump string |
||
156 | * |
||
157 | * @return array|boolean PHP array or false on error |
||
158 | */ |
||
159 | 1 | public static function loadWrapped($yamlString) |
|
172 | |||
173 | /** |
||
174 | * Read a file containing YAML with a php wrapper into a PHP array |
||
175 | * |
||
176 | * The wrap is a php header that surrounds the yaml with section markers, |
||
177 | * '---' and '...' along with php comment markers. The php wrapper keeps the |
||
178 | * yaml file contents from being revealed by serving the file directly from |
||
179 | * a poorly configured server. |
||
180 | * |
||
181 | * @param string $yamlFile filename of YAML file |
||
182 | * |
||
183 | * @return array|boolean PHP array or false on error |
||
184 | */ |
||
185 | 1 | View Code Duplication | public static function readWrapped($yamlFile) |
196 | |||
197 | /** |
||
198 | * Save a PHP array as a YAML file with a php wrapper |
||
199 | * |
||
200 | * The wrap is a php header that surrounds the yaml with section markers, |
||
201 | * '---' and '...' along with php comment markers. The php wrapper keeps the |
||
202 | * yaml file contents from being revealed by serving the file directly from |
||
203 | * a poorly configured server. |
||
204 | * |
||
205 | * @param array $var variable which will be dumped |
||
206 | * @param string $yamlFile filename of YAML file |
||
207 | * @param integer $inline Nesting level where you switch to inline YAML |
||
208 | * @param integer $indent Number of spaces to indent for nested nodes |
||
209 | * |
||
210 | * @return integer|boolean number of bytes written, or false on error |
||
211 | */ |
||
212 | 1 | View Code Duplication | public static function saveWrapped($var, $yamlFile, $inline = 4, $indent = 4) |
223 | } |
||
224 |
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.