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