Passed
Push — master ( 8ea44c...0e1614 )
by Mr
02:02
created

ProvidesConnector::disconnect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/dbal project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Dbal\Connector;
10
11
trait ProvidesConnector
12
{
13
    private array $settings;
14
15
    /** @var mixed */
16
    private $connection;
17
18
    public function __construct(array $settings = [])
19
    {
20
        $this->settings = $settings;
21
    }
22
23
    public function __destruct()
24
    {
25
        $this->disconnect();
26
    }
27
28
    public function getConnection()
29
    {
30
        if (!$this->isConnected()) {
31
            $this->connection = $this->connect();
32
        }
33
34
        return $this->connection;
35
    }
36
37
    public function isConnected(): bool
38
    {
39
        return $this->connection !== null;
40
    }
41
42
    public function disconnect(): void
43
    {
44
        if ($this->isConnected()) {
45
            $this->connection = null;
46
        }
47
    }
48
49
    public function getSettings(): array
50
    {
51
        return $this->settings;
52
    }
53
54
    /** @return mixed */
55
    abstract protected function connect();
56
}
57