| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 54 | 
| 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 | ||
| 104 | 	public function testModifyCaption_PreventCaptionOverride() { | ||
| 105 | |||
| 106 | $caption = 'Foo'; | ||
| 107 | |||
| 108 | $rule = $this->getMockBuilder( '\SMW\Schema\Rule' ) | ||
| 109 | ->disableOriginalConstructor() | ||
| 110 | ->getMock(); | ||
| 111 | |||
| 112 | $rule->expects( $this->at( 1 ) ) | ||
| 113 | ->method( 'has' ) | ||
| 114 | ->with( $this->stringContains( 'then.allow_caption_override' ) ) | ||
| 115 | ->will( $this->returnValue( true ) ); | ||
| 116 | |||
| 117 | $rule->expects( $this->at( 2 ) ) | ||
| 118 | ->method( 'then' ) | ||
| 119 | ->with( $this->stringContains( 'allow_caption_override' ) ) | ||
| 120 | ->will( $this->returnValue( false ) ); | ||
| 121 | |||
| 122 | $this->ruleFinder->expects( $this->any() ) | ||
| 123 | ->method( 'findRule' ) | ||
| 124 | ->will( $this->returnValue( $rule ) ); | ||
| 125 | |||
| 126 | $this->store->expects( $this->any() ) | ||
| 127 | ->method( 'getPropertyValues' ) | ||
| 128 | ->will( $this->returnValue( [] ) ); | ||
| 129 | |||
| 130 | $title = $this->getMockBuilder( '\Title' ) | ||
| 131 | ->disableOriginalConstructor() | ||
| 132 | ->getMock(); | ||
| 133 | |||
| 134 | $title->expects( $this->any() ) | ||
| 135 | ->method( 'getNamespace' ) | ||
| 136 | ->will( $this->returnValue( NS_MAIN ) ); | ||
| 137 | |||
| 138 | $file = $this->getMockBuilder( '\File' ) | ||
| 139 | ->disableOriginalConstructor() | ||
| 140 | ->getMock(); | ||
| 141 | |||
| 142 | $file->expects( $this->any() ) | ||
| 143 | ->method( 'getTitle' ) | ||
| 144 | ->will( $this->returnValue( $title ) ); | ||
| 145 | |||
| 146 | $instance = new ImageCaption( | ||
| 147 | $this->store, | ||
| 148 | $this->ruleFinder | ||
| 149 | ); | ||
| 150 | |||
| 151 | $instance->modifyCaption( $title, $file, $caption, 'en' ); | ||
| 152 | |||
| 153 | $this->assertEquals( | ||
| 154 | 'Foo', | ||
| 155 | $caption | ||
| 156 | ); | ||
| 157 | } | ||
| 158 | |||
| 160 |