Conditions | 1 |
Paths | 1 |
Total Lines | 62 |
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 |
||
41 | public function testModifyCaption_EmptyCaption() { |
||
42 | |||
43 | $caption = ''; |
||
44 | |||
45 | $rule = $this->getMockBuilder( '\SMW\Schema\Rule' ) |
||
46 | ->disableOriginalConstructor() |
||
47 | ->getMock(); |
||
48 | |||
49 | $rule->expects( $this->at( 1 ) ) |
||
50 | ->method( 'has' ) |
||
51 | ->with( $this->stringContains( 'then.caption_property' ) ) |
||
52 | ->will( $this->returnValue( true ) ); |
||
53 | |||
54 | $rule->expects( $this->at( 2 ) ) |
||
55 | ->method( 'then' ) |
||
56 | ->with( $this->stringContains( 'caption_property' ) ) |
||
57 | ->will( $this->returnValue( 'Foo' ) ); |
||
58 | |||
59 | $rule->expects( $this->at( 3 ) ) |
||
60 | ->method( 'has' ) |
||
61 | ->will( $this->returnValue( true ) ); |
||
62 | |||
63 | $rule->expects( $this->at( 4 ) ) |
||
64 | ->method( 'then' ) |
||
65 | ->with( $this->stringContains( 'max_length' ) ); |
||
66 | |||
67 | $this->ruleFinder->expects( $this->any() ) |
||
68 | ->method( 'findRule' ) |
||
69 | ->will( $this->returnValue( $rule ) ); |
||
70 | |||
71 | $this->store->expects( $this->any() ) |
||
72 | ->method( 'getPropertyValues' ) |
||
73 | ->will( $this->returnValue( [] ) ); |
||
74 | |||
75 | $title = $this->getMockBuilder( '\Title' ) |
||
76 | ->disableOriginalConstructor() |
||
77 | ->getMock(); |
||
78 | |||
79 | $title->expects( $this->any() ) |
||
80 | ->method( 'getNamespace' ) |
||
81 | ->will( $this->returnValue( NS_MAIN ) ); |
||
82 | |||
83 | $file = $this->getMockBuilder( '\File' ) |
||
84 | ->disableOriginalConstructor() |
||
85 | ->getMock(); |
||
86 | |||
87 | $file->expects( $this->any() ) |
||
88 | ->method( 'getTitle' ) |
||
89 | ->will( $this->returnValue( $title ) ); |
||
90 | |||
91 | $instance = new ImageCaption( |
||
92 | $this->store, |
||
93 | $this->ruleFinder |
||
94 | ); |
||
95 | |||
96 | $instance->modifyCaption( $title, $file, $caption, 'en' ); |
||
97 | |||
98 | $this->assertEquals( |
||
99 | '', |
||
100 | $caption |
||
101 | ); |
||
102 | } |
||
103 | |||
160 |