| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 125 | public function testExecuteOnUntouchedTemplate() { |
||
| 126 | |||
| 127 | $container = $this->getMockBuilder( Container::class ) |
||
| 128 | ->disableOriginalConstructor() |
||
| 129 | ->getMock(); |
||
| 130 | |||
| 131 | $container->expects( $this->atLeastOnce() ) |
||
| 132 | ->method( 'has' ) |
||
| 133 | ->will( $this->returnValue( true ) ); |
||
| 134 | |||
| 135 | $blobStore = $this->getMockBuilder( BlobStore::class ) |
||
| 136 | ->disableOriginalConstructor() |
||
| 137 | ->getMock(); |
||
| 138 | |||
| 139 | $blobStore->expects( $this->atLeastOnce() ) |
||
| 140 | ->method( 'read' ) |
||
| 141 | ->will( $this->returnValue( $container ) ); |
||
| 142 | |||
| 143 | $cacheHelper = $this->getMockBuilder( CacheHelper::class ) |
||
| 144 | ->disableOriginalConstructor() |
||
| 145 | ->getMock(); |
||
| 146 | |||
| 147 | $cacheHelper->expects( $this->any() ) |
||
| 148 | ->method( 'getBlobStore' ) |
||
| 149 | ->will( $this->returnValue( $blobStore ) ); |
||
| 150 | |||
| 151 | $cacheHelper->expects( $this->atLeastOnce() ) |
||
| 152 | ->method( 'newTitleFromText' ) |
||
| 153 | ->will( $this->returnValue( Title::newFromText( __METHOD__ ) ) ); |
||
| 154 | |||
| 155 | $params = array( |
||
| 156 | 'text' => 'Some text', |
||
| 157 | 'title' => 'Foo', |
||
| 158 | 'template' => 'Bar' |
||
| 159 | ); |
||
| 160 | |||
| 161 | $instance = new ApiSummaryCardContentParser( |
||
| 162 | $this->newApiMain( $params ), |
||
| 163 | 'summarycards' |
||
| 164 | ); |
||
| 165 | |||
| 166 | $instance->setCacheHelper( $cacheHelper ); |
||
| 167 | $instance->execute(); |
||
| 168 | |||
| 169 | $result = $instance->getResult()->getResultData(); |
||
| 170 | |||
| 171 | $this->assertInternalType( |
||
| 172 | 'float', |
||
| 173 | $result['summarycards']['time']['cached'] |
||
| 174 | ); |
||
| 175 | } |
||
| 176 | |||
| 201 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: