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 | * NoXMLSpace |
||
5 | * |
||
6 | * @author Thiago Augustus de Oliveira |
||
7 | * @version 1.0.0 |
||
8 | * @copyright MIT Copyright (c) 2015 |
||
9 | */ |
||
10 | final class NoXMLSpace |
||
11 | { |
||
12 | |||
13 | /** |
||
14 | * noSpace |
||
15 | * Remove all spaces in both side of the words in a .xml file |
||
16 | * |
||
17 | * Here is an inline example: |
||
18 | * <code> |
||
19 | * <?php |
||
20 | * $file = simplexml_load_file($_FILES['xml']['tmp_name']); |
||
21 | * $xml = noSpace($xml); |
||
22 | * ?> |
||
23 | * </code> |
||
24 | * |
||
25 | * @param xml |
||
26 | * @return xml |
||
27 | * @access public |
||
28 | */ |
||
29 | public static function noSpace($xml = null) |
||
30 | { |
||
31 | |||
32 | if (empty($xml) || is_null($xml)) return false; |
||
33 | |||
34 | View Code Duplication | foreach ($xml as $key => $value) { |
|
0 ignored issues
–
show
|
|||
35 | if (sizeof($value) > 1) { |
||
36 | noSpace($value); // Get next node |
||
37 | } else { |
||
38 | $xml->$key = trim($value); |
||
39 | } |
||
40 | } |
||
41 | return $xml; |
||
42 | } |
||
43 | |||
44 | } |
||
45 | |||
46 | // $xml = simplexml_load_file( $xml_file ); |
||
47 | // Example: var_dump( '<pre>', NoXMLSpace::noSpace($xml) ); |
||
48 |
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.