Total Complexity | 27 |
Total Lines | 213 |
Duplicated Lines | 0 % |
Coverage | 54.88% |
Changes | 0 |
1 | <?php |
||
30 | class StrictObject implements IComparer, IStrictPropertiesContainer, IConvertibleToString |
||
31 | { |
||
32 | use PropertiesHandler; |
||
33 | |||
34 | /** |
||
35 | * Constructor. |
||
36 | */ |
||
37 | 320 | public function __construct() |
|
38 | { |
||
39 | 320 | } |
|
40 | |||
41 | /** |
||
42 | * Convierte esta instancia en su representación de cadena. |
||
43 | * Para modificar el funcionamiento de esta función, debe reemplazarse |
||
44 | * la función ObjectClass::toString() |
||
45 | * |
||
46 | * @return string |
||
47 | * @see StrictObject::toString() |
||
48 | * */ |
||
49 | 34 | final public function __toString() |
|
50 | { |
||
51 | //$args = null; |
||
52 | //list($args) = func_get_args(); |
||
53 | 34 | return $this->toString(); |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * Convierte la instancia actual en su representación de cadena. |
||
58 | * |
||
59 | * @return string |
||
60 | * */ |
||
61 | public function toString() |
||
62 | { |
||
63 | $type = typeof($this); |
||
64 | |||
65 | if (defined('CODE_ANALYSIS')) { |
||
66 | if ($type->Name != 'NelsonMartell\StrictObject') { |
||
67 | $args = [ |
||
68 | 'access' => 'public', |
||
69 | 'base_class' => __CLASS__, |
||
70 | 'class' => $type->Name, |
||
71 | 'function' => __FUNCTION__, |
||
72 | ]; |
||
73 | |||
74 | $msg = msg('Using default "{base_class}::{function}" ({access}) method.', $args); |
||
|
|||
75 | $msg .= msg( |
||
76 | ' You can replace (override) its behavior by creating "{class}::{function}" ({access}) method.', |
||
1 ignored issue
–
show
|
|||
77 | $args |
||
78 | ); |
||
79 | |||
80 | trigger_error($msg, E_USER_NOTICE); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | return '{ '.$type.' }'; |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Indica si el objeto especificado es igual a la instancia actual. |
||
89 | * |
||
90 | * Note: This methods must to be overriden. |
||
91 | * |
||
92 | * @param mixed $other Another object to compare equality. |
||
93 | * |
||
94 | * @return bool |
||
95 | * */ |
||
96 | public function equals($other) |
||
97 | { |
||
98 | if (defined('CODE_ANALYSIS')) { |
||
99 | if ($this instanceof IEquatable) { |
||
100 | $type = typeof($this); |
||
101 | |||
102 | $args = [ |
||
103 | 'access' => 'public', |
||
104 | 'base_class' => __CLASS__, |
||
105 | 'class' => $type->Name, |
||
106 | 'function' => __FUNCTION__, |
||
107 | ]; |
||
108 | |||
109 | $msg = msg( |
||
110 | 'You implemented IEquatable, but using default "{base_class}::{function}" ({access}) method.', |
||
1 ignored issue
–
show
|
|||
111 | $args |
||
112 | ); |
||
113 | |||
114 | $msg .= msg( |
||
115 | ' You can replace (override) its behavior by creating "{class}::{function}" ({access}) method.', |
||
1 ignored issue
–
show
|
|||
116 | $args |
||
117 | ); |
||
118 | |||
119 | trigger_error($msg, E_USER_NOTICE); |
||
120 | } |
||
121 | } |
||
122 | |||
123 | return $this == $other; |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Determina la posición relativa del objeto de la izquierda con respecto al de la derecha. |
||
128 | * |
||
129 | * Compatible with, strings, integers, boolean, arrays and classes implementing ``IComparable`` interface. |
||
1 ignored issue
–
show
|
|||
130 | * |
||
131 | * Puede usarse como segundo argumento en la función de ordenamiento de |
||
132 | * arrays 'usort'. |
||
133 | * |
||
134 | * Notes: |
||
135 | * - Comparison is made in natural way if they are of the same type. If not, is used the PHP standard |
||
1 ignored issue
–
show
|
|||
136 | * comparison. |
||
137 | * - If ``$left`` and ``$right`` are arrays, comparison is made by first by 'key' (as strings) and then by |
||
1 ignored issue
–
show
|
|||
138 | * 'values' (using this method recursively). |
||
139 | * |
||
140 | * # Override |
||
141 | * You can override this method to implement a contextual sorting behaviour for ``usort()`` function. |
||
1 ignored issue
–
show
|
|||
142 | * If you only need to compare instances of your class with other objects, implement |
||
143 | * ``NelsonMartell\IComparable`` instead. |
||
144 | * |
||
145 | * @param mixed $left Left object. |
||
146 | * @param mixed $right Right object. |
||
147 | * |
||
148 | * @return int|null |
||
149 | * Returns: |
||
150 | * - ``= 0`` if $left is considered equivalent to $other; |
||
151 | * - ``> 0`` if $left is considered greater than $other; |
||
152 | * - ``< 0`` if $left is considered less than $other; |
||
153 | * - ``null`` if $left can't be compared to $other . |
||
154 | * @see IComparer::compare() |
||
155 | * @see IComparable::compareTo() |
||
156 | * @see \strnatcmp() |
||
157 | * @see \usort() |
||
158 | * */ |
||
159 | 64 | public static function compare($left, $right) |
|
243 | } |
||
244 | } |
||
245 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.