Passed
Push — master ( 157485...b7615a )
by Nikolaos
09:23
created

Decorated   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A disconnect() 0 4 1
A connect() 0 2 1
1
<?php
2
3
/**
4
 * This file is part of the Phalcon Framework.
5
 *
6
 * (c) Phalcon Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 *
11
 * Implementation of this file has been influenced by AtlasPHP
12
 *
13
 * @link    https://github.com/atlasphp/Atlas.Pdo
14
 * @license https://github.com/atlasphp/Atlas.Pdo/blob/1.x/LICENSE.md
15
 */
16
17
declare(strict_types=1);
18
19
namespace Phalcon\DataMapper\Pdo\Connection;
20
21
use PDO;
22
use Phalcon\DataMapper\Pdo\Exception\CannotDisconnect;
23
use Phalcon\DataMapper\Pdo\Profiler\Profiler;
24
use Phalcon\DataMapper\Pdo\Profiler\ProfilerInterface;
25
26
/**
27
 * Decorates an existing PDO instance with the extended methods.
28
 */
29
class Decorated extends AbstractConnection
30
{
31
    /**
32
     *
33
     * Constructor.
34
     *
35
     * This overrides the parent so that it can take an existing PDO instance
36
     * and decorate it with the extended methods.
37
     *
38
     * @param PDO                    $pdo
39
     * @param ProfilerInterface|null $profiler
40
     *
41
     */
42
    public function __construct(PDO $pdo, ProfilerInterface $profiler = null)
43
    {
44
        $this->pdo = $pdo;
45
46
        if ($profiler === null) {
47
            $profiler = new Profiler();
48
        }
49
        $this->setProfiler($profiler);
50
    }
51
52
    /**
53
     * Connects to the database.
54
     */
55
    public function connect(): void
56
    {
57
        // already connected
58
    }
59
60
    /**
61
     * Disconnects from the database; disallowed with decorated PDO connections.
62
     *
63
     * @throws CannotDisconnect
64
     */
65
    public function disconnect(): void
66
    {
67
        $message = "Cannot disconnect a Decorated connection instance";
68
        throw new CannotDisconnect($message);
69
    }
70
}
71