PdoPreparedStatement   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 49
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getStatement() 0 4 1
A setStatement() 0 4 1
A execute() 0 10 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Crossjoin\Browscap\Parser\Sqlite\Adapter;
5
6
/**
7
 * Class PdoPreparedStatement
8
 *
9
 * @package Crossjoin\Browscap\Parser\Sqlite\Adapter
10
 * @author Christoph Ziegenberg <[email protected]>
11
 * @link https://github.com/crossjoin/browscap
12
 */
13
class PdoPreparedStatement implements PreparedStatementInterface
14
{
15
    /**
16
     * @var \PDOStatement
17
     */
18
    protected $statement;
19
20
    /**
21
     * PdoPreparedStatement constructor.
22
     *
23
     * @param \PDOStatement $statement
24
     */
25
    public function __construct(\PDOStatement $statement)
26
    {
27
        $this->setStatement($statement);
28
    }
29
30
    /**
31
     * @return \PDOStatement
32
     */
33
    protected function getStatement() : \PDOStatement
34
    {
35
        return $this->statement;
36
    }
37
38
    /**
39
     * @param \PDOStatement $statement
40
     */
41
    protected function setStatement(\PDOStatement $statement)
42
    {
43
        $this->statement = $statement;
44
    }
45
46
    /**
47
     * @param array $params
48
     *
49
     * @return array
50
     */
51
    public function execute(array $params = []) : array
52
    {
53
        foreach ($params as $paramName => $paramValue) {
54
            $type = is_int($paramValue) ? \PDO::PARAM_INT : \PDO::PARAM_STR;
55
            $this->getStatement()->bindValue($paramName, $paramValue, $type);
56
        }
57
        $this->getStatement()->execute();
58
59
        return $this->getStatement()->fetchAll(\PDO::FETCH_ASSOC);
60
    }
61
}
62