GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 9f0b0e...07a5d8 )
by joseph
27s queued 14s
created

QueryCachingLogger::startQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\Fixtures;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\Driver\Statement;
7
use Doctrine\DBAL\Logging\SQLLogger;
8
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException;
9
10
/**
11
 * This class is caches queries so that they can be run as quickly as possible on subsequent builds
12
 *
13
 * @see \EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\Fixtures\FixturesHelper::createDb
14
 */
15
class QueryCachingLogger implements SQLLogger
16
{
17
    private $queries = [];
18
19
    public function startQuery($sql, array $params = null, array $types = null)
20
    {
21
        $this->queries[$sql][] = [$params, $types];
22
    }
23
24
    public function stopQuery()
25
    {
26
        return;
27
    }
28
29
    public function run(Connection $connection): void
30
    {
31
        foreach ($this->queries as $query => $paramsArray) {
32
            if ('"START TRANSACTION"' === $query) {
33
                $connection->beginTransaction();
34
                continue;
35
            }
36
            if ('"COMMIT"' === $query) {
37
                $connection->commit();
38
                continue;
39
            }
40
            if ($connection->getDatabasePlatform()->getDummySelectSQL() === $query) {
41
                //this is a ping query
42
                unset($this->queries[$query]);
43
                continue;
44
            }
45
            if ([[[], []]] === $paramsArray) {
46
                $connection->prepare($query)->execute();
47
                continue;
48
            }
49
            $stmt = $connection->prepare($query);
50
            foreach ($paramsArray as $paramsTypes) {
51
                $this->runQuery($paramsTypes, $stmt, $connection, $query);
52
            }
53
        }
54
    }
55
56
    private function runQuery(array $paramsTypes, Statement $stmt, Connection $connection, string $query): void
57
    {
58
        try {
59
            list($params, $types) = $paramsTypes;
60
            if ($params !== null) {
61
                $colNum = 1;
62
                foreach ($params as $key => $value) {
63
                    $stmt->bindValue($colNum++, $value, $types[$key]);
64
                }
65
            }
66
            $stmt->execute();
67
        } catch (\Exception $e) {
68
            if ($connection->isTransactionActive()) {
69
                $connection->rollBack();
70
            }
71
            throw new DoctrineStaticMetaException(
72
                'Failed running logged query ' . $query . 'with params and types: '
73
                . print_r($paramsTypes, true),
74
                $e->getCode(),
75
                $e
76
            );
77
        }
78
    }
79
}
80