Completed
Push — master ( d92413...ff1eea )
by Beñat
01:42
created

Pdo::nextIdentity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Shared Kernel library.
5
 *
6
 * Copyright (c) 2016-present LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace LIN3S\SharedKernel\Infrastructure\Persistence\Sql;
15
16
/**
17
 * @author Beñat Espiña <[email protected]>
18
 */
19
final class Pdo
20
{
21
    public const DATE_FORMAT = 'Y-m-d H:i:s';
22
23
    private $pdo;
24
25
    public function __construct(\PDO $pdo)
26
    {
27
        $this->pdo = $pdo;
28
    }
29
30
    public function exec($statement) : int
31
    {
32
        return $this->pdo->exec($statement);
33
    }
34
35
    public function beginTransaction() : void
36
    {
37
        $this->pdo->beginTransaction();
38
    }
39
40
    public function commit() : void
41
    {
42
        $this->pdo->commit();
43
    }
44
45
    public function rollback() : void
46
    {
47
        $this->pdo->rollBack();
48
    }
49
50
    public function execute($sql, array $parameters) : \PDOStatement
51
    {
52
        $statement = $this->pdo->prepare($sql);
53
        $result = $statement->execute($parameters);
54
55
        if (false === $result) {
56
            throw new PdoExecutionFailed($statement->errorInfo());
57
        }
58
59
        return $statement;
60
    }
61
}
62