| Total Complexity | 7 |
| Total Lines | 78 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | abstract class Connector |
||
| 12 | { |
||
| 13 | protected static $connetionCount = 0; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * PDO实例 |
||
| 17 | * |
||
| 18 | * @var PDO|null |
||
| 19 | */ |
||
| 20 | protected $pdo = 0; |
||
| 21 | /** |
||
| 22 | * 连接器类型 |
||
| 23 | * |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | protected static $type; |
||
| 27 | /** |
||
| 28 | * 配置信息 |
||
| 29 | * |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | protected $config; |
||
| 33 | /** |
||
| 34 | * 应用配置 |
||
| 35 | * |
||
| 36 | * @param array $config |
||
| 37 | * @return void |
||
| 38 | */ |
||
| 39 | public function applyConfig(array $config) { |
||
| 40 | $this->config = $config; |
||
|
|
|||
| 41 | } |
||
| 42 | /** |
||
| 43 | * 获取PDO链接描述 |
||
| 44 | * |
||
| 45 | * @return string |
||
| 46 | */ |
||
| 47 | abstract public function getDsn():string; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * 获取类型 |
||
| 51 | * |
||
| 52 | * @return string |
||
| 53 | */ |
||
| 54 | public static function type():string { |
||
| 55 | return static::$type; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * 链接数据库 |
||
| 60 | * |
||
| 61 | * @return void |
||
| 62 | */ |
||
| 63 | public function connect() |
||
| 64 | { |
||
| 65 | // 链接数据库 |
||
| 66 | if (is_null($this->pdo)) { |
||
| 67 | try { |
||
| 68 | $this->pdo = new PDO($this->getDsn(), $this->user, $this->password); |
||
| 69 | static::$connetionCount ++; |
||
| 70 | } catch (PDOException $e) { |
||
| 71 | throw new ConnectionException($e->getMessage(), $e->getCode()); |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | public function getPdo() |
||
| 77 | { |
||
| 78 | return $this->pdo; |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * 判断是否连接 |
||
| 83 | * |
||
| 84 | * @return boolean |
||
| 85 | */ |
||
| 86 | public function isConnected():bool |
||
| 89 | } |
||
| 90 | } |
||
| 91 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..