Conditions | 4 |
Paths | 1 |
Total Lines | 55 |
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 |
||
24 | protected function buildSerializer() { |
||
25 | $termListSerializerMock = $this->getMockBuilder( Serializer::class )->getMock(); |
||
26 | $termListSerializerMock->expects( $this->any() ) |
||
27 | ->method( 'serialize' ) |
||
28 | ->will( $this->returnCallback( function( TermList $termList ) { |
||
29 | if ( $termList->isEmpty() ) { |
||
30 | return []; |
||
31 | } |
||
32 | |||
33 | return [ |
||
34 | 'en' => [ 'lang' => 'en', 'value' => 'foo' ] |
||
35 | ]; |
||
36 | } ) ); |
||
37 | |||
38 | $aliasGroupListSerializerMock = $this->getMockBuilder( Serializer::class )->getMock(); |
||
39 | $aliasGroupListSerializerMock->expects( $this->any() ) |
||
40 | ->method( 'serialize' ) |
||
41 | ->will( $this->returnCallback( function( AliasGroupList $aliasGroupList ) { |
||
42 | if ( $aliasGroupList->isEmpty() ) { |
||
43 | return []; |
||
44 | } |
||
45 | |||
46 | return [ |
||
47 | 'en' => [ 'lang' => 'en', 'values' => [ 'foo', 'bar' ] ] |
||
48 | ]; |
||
49 | } ) ); |
||
50 | |||
51 | $statementListSerializerMock = $this->getMockBuilder( Serializer::class )->getMock(); |
||
52 | $statementListSerializerMock->expects( $this->any() ) |
||
53 | ->method( 'serialize' ) |
||
54 | ->will( $this->returnCallback( function( StatementList $statementList ) { |
||
55 | if ( $statementList->isEmpty() ) { |
||
56 | return []; |
||
57 | } |
||
58 | |||
59 | return [ |
||
60 | 'P42' => [ |
||
61 | [ |
||
62 | 'mainsnak' => [ |
||
63 | 'snaktype' => 'novalue', |
||
64 | 'property' => 'P42' |
||
65 | ], |
||
66 | 'type' => 'statement', |
||
67 | 'rank' => 'normal' |
||
68 | ] |
||
69 | ] |
||
70 | ]; |
||
71 | } ) ); |
||
72 | |||
73 | return new PropertySerializer( |
||
74 | $termListSerializerMock, |
||
|
|||
75 | $aliasGroupListSerializerMock, |
||
76 | $statementListSerializerMock |
||
77 | ); |
||
78 | } |
||
79 | |||
219 |
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: