Completed
Push — master ( dbcbc1...04d817 )
by Sébastien
02:01
created

PdoSqliteAdapter::getConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Soluble\DbWrapper\Adapter;
4
5
use Soluble\DbWrapper\Exception;
6
use Soluble\DbWrapper\Adapter\Pdo\GenericPdo;
7
use Soluble\DbWrapper\Connection\PdoSqliteConnection;
8
use PDO;
9
10
11
class PdoSqliteAdapter extends GenericPdo implements AdapterInterface
12
{
13
14
    /**
15
     *
16
     * @var \PDO
17
     */
18
    protected $resource;
19
20
21
    /**
22
     * Constructor
23
     *
24
     * @throws Exception\InvalidArgumentException
25
     * @throws Exception\RuntimeException
26
     * @param \PDO $resource
27
     */
28 5
    public function __construct(PDO $resource)
29
    {
30 5
        $this->checkEnvironment();
31 5
        if ($resource->getAttribute(\PDO::ATTR_DRIVER_NAME) != 'sqlite') {
32 1
            $msg = __CLASS__ . " requires pdo connection to be 'sqlite'";
33 1
            throw new Exception\InvalidArgumentException($msg);
34
        }
35 5
        $this->resource = $resource;
36 5
        $this->connection = new PdoSqliteConnection($this, $resource);
0 ignored issues
show
Bug introduced by
The property connection does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
37 5
    }
38
    
39
    
40
    /**
41
     * {@inheritdoc}
42
     * @return PdoSqliteConnection
43
     */
44 2
    public function getConnection() {
45 2
        return $this->connection;    
46
    }    
47
    
48
}
49