Conditions | 1 |
Paths | 1 |
Total Lines | 67 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
99 | public function toDiffProvider() { |
||
100 | $argLists = $this->getCommonArgLists(); |
||
101 | |||
102 | $old = array( 42, 42 ); |
||
103 | $new = array( 42 ); |
||
104 | $expected = array( new DiffOpRemove( 42 ) ); |
||
105 | |||
106 | $argLists[] = array( $old, $new, $expected, |
||
107 | '[42, 42] to [42] should [rem(42)]' ); |
||
108 | |||
109 | |||
110 | $old = array( 42 ); |
||
111 | $new = array( 42, 42 ); |
||
112 | $expected = array( new DiffOpAdd( 42 ) ); |
||
113 | |||
114 | $argLists[] = array( $old, $new, $expected, |
||
115 | '[42] to [42, 42] should [add(42)]' ); |
||
116 | |||
117 | |||
118 | $old = array( '42' ); |
||
119 | $new = array( 42 ); |
||
120 | $expected = array( new DiffOpRemove( '42' ), new DiffOpAdd( 42 ) ); |
||
121 | |||
122 | $argLists[] = array( $old, $new, $expected, |
||
123 | '["42"] to [42] should [rem("42"), add(42)]' ); |
||
124 | |||
125 | |||
126 | $old = array( array( 1 ) ); |
||
127 | $new = array( array( 2 ) ); |
||
128 | $expected = array( new DiffOpRemove( array( 1 ) ), new DiffOpAdd( array( 2 ) ) ); |
||
129 | |||
130 | $argLists[] = array( $old, $new, $expected, |
||
131 | '[[1]] to [[2]] should [rem([1]), add([2])]' ); |
||
132 | |||
133 | |||
134 | $old = array( array( 2 ) ); |
||
135 | $new = array( array( 2 ) ); |
||
136 | $expected = array(); |
||
137 | |||
138 | $argLists[] = array( $old, $new, $expected, |
||
139 | '[[2]] to [[2]] should result in an empty diff' ); |
||
140 | |||
141 | // test "soft" object comparison |
||
142 | $obj1 = new \stdClass(); |
||
143 | $obj2 = new \stdClass(); |
||
144 | $objX = new \stdClass(); |
||
145 | |||
146 | $obj1->test = 'Test'; |
||
147 | $obj2->test = 'Test'; |
||
148 | $objX->xest = 'Test'; |
||
149 | |||
150 | $old = array( $obj1 ); |
||
151 | $new = array( $obj2 ); |
||
152 | $expected = array( ); |
||
153 | |||
154 | $argLists[] = array( $old, $new, $expected, |
||
155 | 'Two arrays containing equivalent objects should result in an empty diff' ); |
||
156 | |||
157 | $old = array( $obj1 ); |
||
158 | $new = array( $objX ); |
||
159 | $expected = array( new DiffOpRemove( $obj1 ), new DiffOpAdd( $objX ) ); |
||
160 | |||
161 | $argLists[] = array( $old, $new, $expected, |
||
162 | 'Two arrays containing different objects of the same type should result in an add and a remove op.' ); |
||
163 | |||
164 | return $argLists; |
||
165 | } |
||
166 | |||
231 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.