| Conditions | 6 |
| Paths | 14 |
| Total Lines | 22 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 42 |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | public function connect($conn = null) { |
||
| 17 | if ($conn === null) { |
||
| 18 | $conn = 'db.main'; |
||
| 19 | } |
||
| 20 | $dbConf = []; |
||
|
|
|||
| 21 | if (is_string($conn)) { |
||
| 22 | $dbConf = app('config')->get($conn); |
||
| 23 | } elseif (is_array($conn)) { |
||
| 24 | $dbConf = $conn; |
||
| 25 | } else { |
||
| 26 | throw new \InvalidArgumentException("数据库配置必须为字符串或者数组"); |
||
| 27 | } |
||
| 28 | if (is_null($dbConf)) { |
||
| 29 | throw new \InvalidArgumentException("数据库配置异常!"); |
||
| 30 | } |
||
| 31 | $confMd5 = md5(serialize($dbConf)); |
||
| 32 | if (!isset($this->connPool[$confMd5])) { |
||
| 33 | $obj = new Mysql($dbConf); |
||
| 34 | $this->connPool[$confMd5] = $obj; |
||
| 35 | } |
||
| 36 | return $this->connPool[$confMd5]; |
||
| 37 | } |
||
| 38 | |||
| 54 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.