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   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 61
ccs 0
cts 53
cp 0
rs 10
c 0
b 0
f 0
wmc 14

4 Methods

Rating   Name   Duplication   Size   Complexity  
B run() 0 23 7
A stopQuery() 0 3 1
A runQuery() 0 20 5
A startQuery() 0 3 1
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