| Conditions | 12 |
| Paths | 12 |
| Total Lines | 34 |
| Code Lines | 25 |
| Lines | 12 |
| Ratio | 35.29 % |
| 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 |
||
| 19 | public function __construct($main, $slave = false, $strict = false) |
||
| 20 | { |
||
| 21 | var_dump($main); |
||
| 22 | var_dump($slave); |
||
| 23 | if ($strict) { |
||
| 24 | $this->mysqliW = new mysqli_strict($main['host'], |
||
| 25 | $main['user'], $main['pass'], |
||
| 26 | $main['name'], $main['port']); |
||
| 27 | View Code Duplication | if ($slave && is_array($slave) && isset($slave['enabled']) && $slave['enabled'] |
|
| 28 | === true) { |
||
| 29 | $this->mysqliR = new mysqli_strict($slave['host'], |
||
| 30 | $slave['user'], $slave['pass'], |
||
| 31 | $slave['name'], $slave['port']); |
||
| 32 | } |
||
| 33 | } else { |
||
| 34 | $this->mysqliW = new mysqli($main['host'], |
||
| 35 | $main['user'], $main['pass'], |
||
| 36 | $main['name'], $main['port']); |
||
| 37 | View Code Duplication | if ($slave && is_array($slave) && isset($slave['enabled']) && $slave['enabled'] |
|
| 38 | === true) { |
||
| 39 | $this->mysqliR = new mysqli($slave['host'], |
||
| 40 | $slave['user'], $slave['pass'], |
||
| 41 | $slave['name'], $slave['port']); |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | if ($this->mysqliW->connect_errno) { |
||
| 46 | throw new Exception("Failed to connect to MySQL: (".$this->mysqliW->connect_errno.") ".$this->mysqliW->connect_error); |
||
| 47 | } |
||
| 48 | |||
| 49 | if ($this->mysqliR->connect_errno) { |
||
| 50 | throw new Exception("Failed to connect to MySQL: (".$this->mysqliR->connect_errno.") ".$this->mysqliR->connect_error); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 85 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.