| Conditions | 1 |
| Paths | 1 |
| Total Lines | 117 |
| 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 |
||
| 111 | public function deserializationProvider() { |
||
| 112 | $property = Property::newFromType( 'string' ); |
||
| 113 | |||
| 114 | $provider = [ |
||
| 115 | [ |
||
| 116 | $property, |
||
| 117 | [ |
||
| 118 | 'type' => 'property', |
||
| 119 | 'datatype' => 'string' |
||
| 120 | ] |
||
| 121 | ], |
||
| 122 | ]; |
||
| 123 | |||
| 124 | $property = new Property( new PropertyId( 'P42' ), null, 'string' ); |
||
| 125 | $provider[] = [ |
||
| 126 | $property, |
||
| 127 | [ |
||
| 128 | 'type' => 'property', |
||
| 129 | 'datatype' => 'string', |
||
| 130 | 'id' => 'P42' |
||
| 131 | ] |
||
| 132 | ]; |
||
| 133 | |||
| 134 | $property = Property::newFromType( 'string' ); |
||
| 135 | $property->setLabel( 'en', 'foo' ); |
||
| 136 | $provider[] = [ |
||
| 137 | $property, |
||
| 138 | [ |
||
| 139 | 'type' => 'property', |
||
| 140 | 'datatype' => 'string', |
||
| 141 | 'labels' => [ |
||
| 142 | 'en' => [ |
||
| 143 | 'lang' => 'en', |
||
| 144 | 'value' => 'foo' |
||
| 145 | ] |
||
| 146 | ] |
||
| 147 | ] |
||
| 148 | ]; |
||
| 149 | |||
| 150 | $property = Property::newFromType( 'string' ); |
||
| 151 | $property->setDescription( 'en', 'foo' ); |
||
| 152 | $provider[] = [ |
||
| 153 | $property, |
||
| 154 | [ |
||
| 155 | 'type' => 'property', |
||
| 156 | 'datatype' => 'string', |
||
| 157 | 'descriptions' => [ |
||
| 158 | 'en' => [ |
||
| 159 | 'lang' => 'en', |
||
| 160 | 'value' => 'foo' |
||
| 161 | ] |
||
| 162 | ] |
||
| 163 | ] |
||
| 164 | ]; |
||
| 165 | |||
| 166 | $property = Property::newFromType( 'string' ); |
||
| 167 | $property->setAliases( 'en', [ 'foo', 'bar' ] ); |
||
| 168 | $provider[] = [ |
||
| 169 | $property, |
||
| 170 | [ |
||
| 171 | 'type' => 'property', |
||
| 172 | 'datatype' => 'string', |
||
| 173 | 'aliases' => [ |
||
| 174 | 'en' => [ |
||
| 175 | 'lang' => 'en', |
||
| 176 | 'values' => [ 'foo', 'bar' ] |
||
| 177 | ] |
||
| 178 | ] |
||
| 179 | ] |
||
| 180 | ]; |
||
| 181 | |||
| 182 | $property = Property::newFromType( 'string' ); |
||
| 183 | $property->getStatements()->addNewStatement( new PropertyNoValueSnak( 42 ), null, null, 'test' ); |
||
| 184 | $provider[] = [ |
||
| 185 | $property, |
||
| 186 | [ |
||
| 187 | 'type' => 'property', |
||
| 188 | 'datatype' => 'string', |
||
| 189 | 'claims' => [ |
||
| 190 | 'P42' => [ |
||
| 191 | [ |
||
| 192 | 'mainsnak' => [ |
||
| 193 | 'snaktype' => 'novalue', |
||
| 194 | 'property' => 'P42' |
||
| 195 | ], |
||
| 196 | 'type' => 'statement', |
||
| 197 | 'rank' => 'normal' |
||
| 198 | ] |
||
| 199 | ] |
||
| 200 | ] |
||
| 201 | ] |
||
| 202 | ]; |
||
| 203 | |||
| 204 | $property = Property::newFromType( 'string' ); |
||
| 205 | $property->getStatements()->addNewStatement( new PropertyNoValueSnak( 42 ), null, null, 'test' ); |
||
| 206 | $provider[] = [ |
||
| 207 | $property, |
||
| 208 | [ |
||
| 209 | 'type' => 'property', |
||
| 210 | 'datatype' => 'string', |
||
| 211 | 'claims' => [ |
||
| 212 | 'P42' => [ |
||
| 213 | [ |
||
| 214 | 'mainsnak' => [ |
||
| 215 | 'snaktype' => 'novalue', |
||
| 216 | 'property' => 'P42' |
||
| 217 | ], |
||
| 218 | 'type' => 'statement', |
||
| 219 | 'rank' => 'normal' |
||
| 220 | ] |
||
| 221 | ] |
||
| 222 | ] |
||
| 223 | ] |
||
| 224 | ]; |
||
| 225 | |||
| 226 | return $provider; |
||
| 227 | } |
||
| 228 | |||
| 230 |
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: