| Conditions | 1 |
| Paths | 1 |
| Total Lines | 115 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 102 | public function serializationProvider() { |
||
| 103 | $property = Property::newFromType( 'string' ); |
||
| 104 | |||
| 105 | $provider = [ |
||
| 106 | [ |
||
| 107 | [ |
||
| 108 | 'type' => 'property', |
||
| 109 | 'datatype' => 'string', |
||
| 110 | 'labels' => [], |
||
| 111 | 'descriptions' => [], |
||
| 112 | 'aliases' => [], |
||
| 113 | 'claims' => [], |
||
| 114 | ], |
||
| 115 | $property |
||
| 116 | ], |
||
| 117 | ]; |
||
| 118 | |||
| 119 | $property = new Property( new PropertyId( 'P42' ), null, 'string' ); |
||
| 120 | $provider[] = [ |
||
| 121 | [ |
||
| 122 | 'type' => 'property', |
||
| 123 | 'datatype' => 'string', |
||
| 124 | 'id' => 'P42', |
||
| 125 | 'labels' => [], |
||
| 126 | 'descriptions' => [], |
||
| 127 | 'aliases' => [], |
||
| 128 | 'claims' => [], |
||
| 129 | ], |
||
| 130 | $property |
||
| 131 | ]; |
||
| 132 | |||
| 133 | $property = Property::newFromType( 'string' ); |
||
| 134 | $property->setLabel( 'en', 'foo' ); |
||
| 135 | $provider[] = [ |
||
| 136 | [ |
||
| 137 | 'type' => 'property', |
||
| 138 | 'datatype' => 'string', |
||
| 139 | 'labels' => [ |
||
| 140 | 'en' => [ |
||
| 141 | 'lang' => 'en', |
||
| 142 | 'value' => 'foo' |
||
| 143 | ] |
||
| 144 | ], |
||
| 145 | 'descriptions' => [], |
||
| 146 | 'aliases' => [], |
||
| 147 | 'claims' => [], |
||
| 148 | ], |
||
| 149 | $property |
||
| 150 | ]; |
||
| 151 | |||
| 152 | $property = Property::newFromType( 'string' ); |
||
| 153 | $property->setDescription( 'en', 'foo' ); |
||
| 154 | $provider[] = [ |
||
| 155 | [ |
||
| 156 | 'type' => 'property', |
||
| 157 | 'datatype' => 'string', |
||
| 158 | 'labels' => [], |
||
| 159 | 'descriptions' => [ |
||
| 160 | 'en' => [ |
||
| 161 | 'lang' => 'en', |
||
| 162 | 'value' => 'foo' |
||
| 163 | ] |
||
| 164 | ], |
||
| 165 | 'aliases' => [], |
||
| 166 | 'claims' => [], |
||
| 167 | ], |
||
| 168 | $property |
||
| 169 | ]; |
||
| 170 | |||
| 171 | $property = Property::newFromType( 'string' ); |
||
| 172 | $property->setAliases( 'en', [ 'foo', 'bar' ] ); |
||
| 173 | $provider[] = [ |
||
| 174 | [ |
||
| 175 | 'type' => 'property', |
||
| 176 | 'datatype' => 'string', |
||
| 177 | 'labels' => [], |
||
| 178 | 'descriptions' => [], |
||
| 179 | 'aliases' => [ |
||
| 180 | 'en' => [ |
||
| 181 | 'lang' => 'en', |
||
| 182 | 'values' => [ 'foo', 'bar' ] |
||
| 183 | ] |
||
| 184 | ], |
||
| 185 | 'claims' => [], |
||
| 186 | ], |
||
| 187 | $property |
||
| 188 | ]; |
||
| 189 | |||
| 190 | $property = Property::newFromType( 'string' ); |
||
| 191 | $property->getStatements()->addNewStatement( new PropertyNoValueSnak( 42 ), null, null, 'test' ); |
||
| 192 | $provider[] = [ |
||
| 193 | [ |
||
| 194 | 'type' => 'property', |
||
| 195 | 'datatype' => 'string', |
||
| 196 | 'labels' => [], |
||
| 197 | 'descriptions' => [], |
||
| 198 | 'aliases' => [], |
||
| 199 | 'claims' => [ |
||
| 200 | 'P42' => [ |
||
| 201 | [ |
||
| 202 | 'mainsnak' => [ |
||
| 203 | 'snaktype' => 'novalue', |
||
| 204 | 'property' => 'P42' |
||
| 205 | ], |
||
| 206 | 'type' => 'statement', |
||
| 207 | 'rank' => 'normal' |
||
| 208 | ] |
||
| 209 | ] |
||
| 210 | ], |
||
| 211 | ], |
||
| 212 | $property |
||
| 213 | ]; |
||
| 214 | |||
| 215 | return $provider; |
||
| 216 | } |
||
| 217 | |||
| 219 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: