| Conditions | 12 |
| Paths | 12 |
| Total Lines | 32 |
| Code Lines | 23 |
| Lines | 12 |
| Ratio | 37.5 % |
| 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 | if ($strict) { |
||
| 22 | $this->mysqliW = new mysqli_strict($main['host'], |
||
| 23 | $main['user'], $main['pass'], |
||
| 24 | $main['name'], $main['port']); |
||
| 25 | View Code Duplication | if ($slave && is_array($slave) && isset($slave['enabled']) && $slave['enabled'] |
|
| 26 | === true) { |
||
| 27 | $this->mysqliR = new mysqli_strict($slave['host'], |
||
| 28 | $slave['user'], $slave['pass'], |
||
| 29 | $slave['name'], $slave['port']); |
||
| 30 | } |
||
| 31 | } else { |
||
| 32 | $this->mysqliW = new mysqli($main['host'], |
||
| 33 | $main['user'], $main['pass'], |
||
| 34 | $main['name'], $main['port']); |
||
| 35 | View Code Duplication | if ($slave && is_array($slave) && isset($slave['enabled']) && $slave['enabled'] |
|
| 36 | === true) { |
||
| 37 | $this->mysqliR = new mysqli($slave['host'], |
||
| 38 | $slave['user'], $slave['pass'], |
||
| 39 | $slave['name'], $slave['port']); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | if ($this->mysqliW->connect_errno) { |
||
| 44 | throw new Exception("Failed to connect to MySQL: (".$this->mysqliW->connect_errno.") ".$this->mysqliW->connect_error); |
||
| 45 | } |
||
| 46 | |||
| 47 | if ($this->mysqliR->connect_errno) { |
||
| 48 | throw new Exception("Failed to connect to MySQL: (".$this->mysqliR->connect_errno.") ".$this->mysqliR->connect_error); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 83 | } |
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.