Conditions | 5 |
Paths | 6 |
Total Lines | 25 |
Code Lines | 16 |
Lines | 6 |
Ratio | 24 % |
Tests | 8 |
CRAP Score | 6.9683 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
33 | 3 | public function __construct( |
|
34 | $host = '127.0.0.1', |
||
35 | $port = 6379, |
||
36 | $database = 0, |
||
37 | $prefix = 'simple-fork' |
||
38 | ) |
||
39 | { |
||
40 | 3 | $this->redis = new \Redis(); |
|
41 | 3 | $connection_result = $this->redis->connect($host, $port); |
|
42 | 3 | if (!$connection_result) { |
|
43 | throw new \RuntimeException('can not connect to the redis server'); |
||
44 | } |
||
45 | |||
46 | 3 | View Code Duplication | if ($database != 0) { |
|
|||
47 | $select_result = $this->redis->select($database); |
||
48 | if (!$select_result) { |
||
49 | throw new \RuntimeException('can not select the database'); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | 3 | if (empty($prefix)) { |
|
54 | throw new \InvalidArgumentException('prefix can not be empty'); |
||
55 | } |
||
56 | 3 | $this->prefix = $prefix; |
|
57 | 3 | } |
|
58 | |||
126 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.