| Conditions | 4 |
| Paths | 1 |
| Total Lines | 67 |
| 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 |
||
| 26 | protected function buildSerializer( $useObjectsForMaps = false ) { |
||
| 27 | $termListSerializerMock = $this->getMockBuilder( Serializer::class )->getMock(); |
||
| 28 | $termListSerializerMock->expects( $this->any() ) |
||
| 29 | ->method( 'serialize' ) |
||
| 30 | ->will( $this->returnCallback( function( TermList $termList ) { |
||
| 31 | if ( $termList->isEmpty() ) { |
||
| 32 | return []; |
||
| 33 | } |
||
| 34 | |||
| 35 | return [ |
||
| 36 | 'en' => [ 'lang' => 'en', 'value' => 'foo' ] |
||
| 37 | ]; |
||
| 38 | } ) ); |
||
| 39 | |||
| 40 | $aliasGroupListSerializerMock = $this->getMockBuilder( Serializer::class )->getMock(); |
||
| 41 | $aliasGroupListSerializerMock->expects( $this->any() ) |
||
| 42 | ->method( 'serialize' ) |
||
| 43 | ->will( $this->returnCallback( function( AliasGroupList $aliasGroupList ) { |
||
| 44 | if ( $aliasGroupList->isEmpty() ) { |
||
| 45 | return []; |
||
| 46 | } |
||
| 47 | |||
| 48 | return [ |
||
| 49 | 'en' => [ 'lang' => 'en', 'values' => [ 'foo', 'bar' ] ] |
||
| 50 | ]; |
||
| 51 | } ) ); |
||
| 52 | |||
| 53 | $statementListSerializerMock = $this->getMockBuilder( Serializer::class )->getMock(); |
||
| 54 | $statementListSerializerMock->expects( $this->any() ) |
||
| 55 | ->method( 'serialize' ) |
||
| 56 | ->will( $this->returnCallback( function( StatementList $statementList ) { |
||
| 57 | if ( $statementList->isEmpty() ) { |
||
| 58 | return []; |
||
| 59 | } |
||
| 60 | |||
| 61 | return [ |
||
| 62 | 'P42' => [ |
||
| 63 | [ |
||
| 64 | 'mainsnak' => [ |
||
| 65 | 'snaktype' => 'novalue', |
||
| 66 | 'property' => 'P42' |
||
| 67 | ], |
||
| 68 | 'type' => 'statement', |
||
| 69 | 'rank' => 'normal' |
||
| 70 | ] |
||
| 71 | ] |
||
| 72 | ]; |
||
| 73 | } ) ); |
||
| 74 | |||
| 75 | $siteLinkSerializerMock = $this->getMockBuilder( Serializer::class )->getMock(); |
||
| 76 | $siteLinkSerializerMock->expects( $this->any() ) |
||
| 77 | ->method( 'serialize' ) |
||
| 78 | ->with( $this->equalTo( new SiteLink( 'enwiki', 'Nyan Cat' ) ) ) |
||
| 79 | ->will( $this->returnValue( [ |
||
| 80 | 'site' => 'enwiki', |
||
| 81 | 'title' => 'Nyan Cat', |
||
| 82 | 'badges' => [] |
||
| 83 | ] ) ); |
||
| 84 | |||
| 85 | return new ItemSerializer( |
||
| 86 | $termListSerializerMock, |
||
|
|
|||
| 87 | $aliasGroupListSerializerMock, |
||
| 88 | $statementListSerializerMock, |
||
| 89 | $siteLinkSerializerMock, |
||
| 90 | $useObjectsForMaps |
||
| 91 | ); |
||
| 92 | } |
||
| 93 | |||
| 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: