Completed
Push — master ( 17c57a...8a23e4 )
by Sébastien
02:02
created

GenericPdo::getResource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
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 4
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\Pdo;
4
5
use Soluble\DbWrapper\Exception;
6
use Soluble\DbWrapper\Adapter\AdapterInterface;
7
use Soluble\DbWrapper\Result\Resultset;
8
9
abstract class GenericPdo implements AdapterInterface
10
{
11
12
    /**
13
     * {@inheritdoc}
14
     */
15 2
    public function execute($query)
16
    {
17
        try {
18 2
            $ret = $this->resource->exec($query);
0 ignored issues
show
Bug introduced by
The property resource 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...
19 2
            if ($ret === false) {
20 1
                throw new Exception\InvalidArgumentException("Cannot execute [$query].");
21
            }
22 2
        } catch (Exception\InvalidArgumentException $e) {
23 1
            throw $e;
24
        } catch (\Exception $e) {
25
            $msg = "PDOException : {$e->getMessage()} [$query]";
26
            throw new Exception\InvalidArgumentException($msg);
27
        }
28 2
    }
29
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 2
    public function query($query)
35
    {
36
        try {
37 2
            $stmt = $this->resource->query($query, \PDO::FETCH_ASSOC);
38 2
            if ($stmt === false) {
39 1
                throw new Exception\InvalidArgumentException("Query cannot be executed [$query].");
40
            }
41 2
            $results = new Resultset();
42 2
            foreach ($stmt as $row) {
43 2
                $results->append($row);
44 2
            }
45 2
        } catch (Exception\InvalidArgumentException $e) {
46 1
            throw $e;
47
        } catch (\Exception $e) {
48
            $msg = "PDOException : {$e->getMessage()} [$query]";
49
            throw new Exception\InvalidArgumentException($msg);
50
        }
51 2
        return $results;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 1
    public function quoteValue($value)
58
    {
59 1
        return $this->resource->quote($value);
60
    }
61
62
    /**
63
     * {@ineritdoc}
64
     * @return \PDO
65
     */
66 1
    public function getResource()
67
    {
68 1
        return $this->resource;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    abstract public function getCurrentSchema();
75
}
76