These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * noSpace |
||
5 | * Remove all spaces in both side of the words in a .xml file |
||
6 | * |
||
7 | * Here is an inline example: |
||
8 | * <code> |
||
9 | * <?php |
||
10 | * $file = simplexml_load_file($_FILES['xml']['tmp_name']); |
||
11 | * $xml = noSpace($xml); |
||
12 | * ?> |
||
13 | * </code> |
||
14 | * |
||
15 | * @author Thiago Augustus de Oliveira |
||
16 | * @version 1.0.0 |
||
17 | * @copyright MIT Copyright (c) 2015 |
||
18 | * @param xml |
||
19 | * @return xml |
||
20 | */ |
||
21 | function noSpace($xml) { |
||
22 | View Code Duplication | foreach ($xml as $key => $value) { |
|
0 ignored issues
–
show
|
|||
23 | if (sizeof($value) > 1) { |
||
24 | noSpace($value); // Get next node |
||
25 | } else { |
||
26 | $xml->$key = trim($value); |
||
27 | } |
||
28 | } |
||
29 | return $xml; |
||
30 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.