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