Total Complexity | 7 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
10 | trait TCPConfigurationTrait |
||
11 | { |
||
12 | /** @var \PDO */ |
||
13 | private $pdo; |
||
14 | private $dsn; |
||
15 | private $host; |
||
16 | private $port; |
||
17 | private $username; |
||
18 | private $password; |
||
19 | private $options = [ |
||
20 | \PDO::ATTR_TIMEOUT => 1, |
||
21 | ]; |
||
22 | |||
23 | public function isValid(): bool |
||
24 | { |
||
25 | $op = @fsockopen($this->host, $this->port, $errno, $errstr, 0.5); |
||
26 | |||
27 | if (!$op) { |
||
|
|||
28 | return false; |
||
29 | } |
||
30 | |||
31 | fclose($op); |
||
32 | |||
33 | try { |
||
34 | $this->pdo = new \PDO($this->dsn, $this->username, $this->password, $this->options); |
||
35 | return true; |
||
36 | } catch (\PDOException $e) { |
||
37 | return false; |
||
38 | } |
||
39 | } |
||
40 | |||
41 | public function buildConnection(): Connection |
||
51 | } |
||
52 | } |
||
54 |