| Conditions | 1 |
| Paths | 1 |
| Total Lines | 69 |
| 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 |
||
| 27 | protected function buildDeserializer() { |
||
| 28 | $entityIdDeserializerMock = $this->getMockBuilder( Deserializer::class )->getMock(); |
||
| 29 | $entityIdDeserializerMock->expects( $this->any() ) |
||
| 30 | ->method( 'deserialize' ) |
||
| 31 | ->with( $this->equalTo( 'Q42' ) ) |
||
| 32 | ->will( $this->returnValue( new ItemId( 'Q42' ) ) ); |
||
| 33 | |||
| 34 | $termListDeserializerMock = $this->getMockBuilder( Deserializer::class )->getMock(); |
||
| 35 | $termListDeserializerMock->expects( $this->any() ) |
||
| 36 | ->method( 'deserialize' ) |
||
| 37 | ->with( $this->equalTo( [ |
||
| 38 | 'en' => [ |
||
| 39 | 'lang' => 'en', |
||
| 40 | 'value' => 'foo' |
||
| 41 | ] |
||
| 42 | ] ) ) |
||
| 43 | ->will( $this->returnValue( new TermList( [ new Term( 'en', 'foo' ) ] ) ) ); |
||
| 44 | |||
| 45 | $aliasGroupListDeserializerMock = $this->getMockBuilder( Deserializer::class )->getMock(); |
||
| 46 | $aliasGroupListDeserializerMock->expects( $this->any() ) |
||
| 47 | ->method( 'deserialize' ) |
||
| 48 | ->with( $this->equalTo( [ |
||
| 49 | 'en' => [ |
||
| 50 | 'lang' => 'en', |
||
| 51 | 'values' => [ 'foo', 'bar' ] |
||
| 52 | ] |
||
| 53 | ] ) ) |
||
| 54 | ->will( $this->returnValue( |
||
| 55 | new AliasGroupList( [ new AliasGroup( 'en', [ 'foo', 'bar' ] ) ] ) ) |
||
| 56 | ); |
||
| 57 | |||
| 58 | $statement = new Statement( new PropertyNoValueSnak( 42 ) ); |
||
| 59 | $statement->setGuid( 'test' ); |
||
| 60 | |||
| 61 | $statementListDeserializerMock = $this->getMockBuilder( Deserializer::class )->getMock(); |
||
| 62 | $statementListDeserializerMock->expects( $this->any() ) |
||
| 63 | ->method( 'deserialize' ) |
||
| 64 | ->with( $this->equalTo( [ |
||
| 65 | 'P42' => [ |
||
| 66 | [ |
||
| 67 | 'mainsnak' => [ |
||
| 68 | 'snaktype' => 'novalue', |
||
| 69 | 'property' => 'P42' |
||
| 70 | ], |
||
| 71 | 'type' => 'statement', |
||
| 72 | 'rank' => 'normal' |
||
| 73 | ] |
||
| 74 | ] |
||
| 75 | ] ) ) |
||
| 76 | ->will( $this->returnValue( new StatementList( [ $statement ] ) ) ); |
||
| 77 | |||
| 78 | $siteLinkDeserializerMock = $this->getMockBuilder( Deserializer::class )->getMock(); |
||
| 79 | $siteLinkDeserializerMock->expects( $this->any() ) |
||
| 80 | ->method( 'deserialize' ) |
||
| 81 | ->with( $this->equalTo( [ |
||
| 82 | 'site' => 'enwiki', |
||
| 83 | 'title' => 'Nyan Cat', |
||
| 84 | 'badges' => [] |
||
| 85 | ] ) ) |
||
| 86 | ->will( $this->returnValue( new SiteLink( 'enwiki', 'Nyan Cat' ) ) ); |
||
| 87 | |||
| 88 | return new ItemDeserializer( |
||
| 89 | $entityIdDeserializerMock, |
||
|
|
|||
| 90 | $termListDeserializerMock, |
||
| 91 | $aliasGroupListDeserializerMock, |
||
| 92 | $statementListDeserializerMock, |
||
| 93 | $siteLinkDeserializerMock |
||
| 94 | ); |
||
| 95 | } |
||
| 96 | |||
| 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: