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; |
||
0 ignored issues
–
show
|
|||
33 | |||
34 | View Code Duplication | foreach ($xml as $key => $value) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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.
Loading history...
|
|||
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 ); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
46% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them.
Loading history...
|
|||
47 | // Example: var_dump( '<pre>', NoXMLSpace::noSpace($xml) ); |
||
48 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.