| Conditions | 3 |
| Paths | 8 |
| Total Lines | 53 |
| Code Lines | 34 |
| 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 |
||
| 15 | public function testRun() |
||
| 16 | { |
||
| 17 | if( !class_exists( '\\Predis\\Client' ) ) { |
||
| 18 | $this->markTestSkipped( 'Predis library not available' ); |
||
| 19 | } |
||
| 20 | |||
| 21 | try |
||
| 22 | { |
||
| 23 | $predis = new \Predis\Client(); |
||
| 24 | |||
| 25 | $client = new \Aimeos\Base\Cache\Redis( [], $predis ); |
||
| 26 | $client->clear(); |
||
| 27 | } |
||
| 28 | catch( \Exception $e ) |
||
| 29 | { |
||
| 30 | $this->markTestSkipped( 'Predis server not available' ); |
||
| 31 | } |
||
| 32 | |||
| 33 | |||
| 34 | $client->set( 'arc-single-key', 'single-value' ); |
||
|
|
|||
| 35 | $valSingle = $client->get( 'arc-single-key' ); |
||
| 36 | $valNone = $client->get( 'arc-no-key', 'none' ); |
||
| 37 | |||
| 38 | $client->set( 'arc-mkey3', 'mvalue3', '2000-01-01 00:00:00' ); |
||
| 39 | $valExpired = $client->get( 'arc-mkey3' ); |
||
| 40 | |||
| 41 | $client->setMultiple( array( 'arc-mkey1' => 'mvalue1', 'arc-mkey2' => 'mvalue2' ) ); |
||
| 42 | $listNormal = $client->getMultiple( array( 'arc-mkey1', 'arc-mkey2' ) ); |
||
| 43 | |||
| 44 | $pairs = array( 'arc-mkey4' => 'mvalue4', 'arc-mkey5' => 'mvalue5' ); |
||
| 45 | $tags = array( 'arc-mkey4' => 'arc-mtag4', 'arc-mkey5' => 'arc-mtag5' ); |
||
| 46 | $expires = array( 'arc-mkey5' => '2000-01-01 00:00:00' ); |
||
| 47 | $client->setMultiple( $pairs, $expires, $tags ); |
||
| 48 | $listExpired = $client->getMultiple( array( 'arc-mkey4', 'arc-mkey5' ) ); |
||
| 49 | |||
| 50 | $client->deleteByTags( array( 'arc-mtag4', 'arc-mtag5' ) ); |
||
| 51 | $listDelByTags = $client->getMultiple( array( 'arc-mkey4', 'arc-mkey5' ) ); |
||
| 52 | |||
| 53 | $client->deleteMultiple( array( 'arc-mkey1', 'arc-mkey2' ) ); |
||
| 54 | $listDelList = $client->getMultiple( array( 'arc-mkey1', 'arc-mkey2' ) ); |
||
| 55 | |||
| 56 | $client->delete( 'arc-single-key' ); |
||
| 57 | $valDelSingle = $client->get( 'arc-single-key' ); |
||
| 58 | |||
| 59 | |||
| 60 | $this->assertEquals( 'single-value', $valSingle ); |
||
| 61 | $this->assertEquals( 'none', $valNone ); |
||
| 62 | $this->assertEquals( null, $valExpired ); |
||
| 63 | $this->assertEquals( array( 'arc-mkey1' => 'mvalue1', 'arc-mkey2' => 'mvalue2' ), $listNormal ); |
||
| 64 | $this->assertEquals( array( 'arc-mkey4' => 'mvalue4' ), $listExpired ); |
||
| 65 | $this->assertEquals( [], $listDelByTags ); |
||
| 66 | $this->assertEquals( [], $listDelList ); |
||
| 67 | $this->assertEquals( null, $valDelSingle ); |
||
| 68 | } |
||
| 70 |