| Conditions | 13 |
| Paths | 12 |
| Total Lines | 34 |
| Code Lines | 25 |
| Lines | 14 |
| Ratio | 41.18 % |
| 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 |
||
| 21 | public function __construct($main, $slave = false, $strict = false) |
||
| 22 | { |
||
| 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 | $this->slave = true; |
||
| 33 | } |
||
| 34 | } else { |
||
| 35 | $this->mysqliW = new mysqli($main['host'], |
||
| 36 | $main['user'], $main['pass'], |
||
| 37 | $main['name'], $main['port']); |
||
| 38 | View Code Duplication | if ($slave && is_array($slave) && isset($slave['enabled']) && $slave['enabled'] |
|
| 39 | === true) { |
||
| 40 | $this->mysqliR = new mysqli($slave['host'], |
||
| 41 | $slave['user'], $slave['pass'], |
||
| 42 | $slave['name'], $slave['port']); |
||
| 43 | $this->slave = true; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | if ($this->mysqliW->connect_errno) { |
||
| 48 | throw new Exception("Failed to connect to MySQL: (".$this->mysqliW->connect_errno.") ".$this->mysqliW->connect_error); |
||
| 49 | } |
||
| 50 | |||
| 51 | if ($this->slave === true && $this->mysqliR->connect_errno) { |
||
| 52 | throw new Exception("Failed to connect to MySQL: (".$this->mysqliR->connect_errno.") ".$this->mysqliR->connect_error); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 92 |
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.