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 ( e72770...dceff7 )
by Mario
38:28
created

DoctrineDatabase   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 124
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getContentsWithCollectionsCount() 0 30 1
B getObjectsWithCollections() 0 58 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Netgen\InformationCollection\Core\Persistence\Gateway;
6
7
use Doctrine\DBAL\Connection;
8
use PDO;
9
10
class DoctrineDatabase
11
{
12
    /**
13
     * @var \Doctrine\DBAL\Connection
14
     */
15
    protected $connection;
16
17
    /**
18
     * DoctrineDatabase constructor.
19
     *
20
     * @param \Doctrine\DBAL\Connection $connection
21
     */
22
    public function __construct(Connection $connection)
23
    {
24
        $this->connection = $connection;
25
    }
26
27
    /**
28
     * Returns number of content objects that have any collection.
29
     *
30
     * @throws \Doctrine\DBAL\DBALException
31
     *
32
     * @return int
33
     */
34
    public function getContentsWithCollectionsCount()
35
    {
36
        $query = $this->connection->createQueryBuilder();
37
        $query->select(
38
                'COUNT(DISTINCT eic.contentobject_id) AS count'
39
            )
40
            ->from($this->connection->quoteIdentifier('ezinfocollection'), 'eic')
41
            ->innerJoin(
42
                'eic',
43
                $this->connection->quoteIdentifier('ezcontentobject'),
44
                'eco',
45
                $query->expr()->eq(
46
                    $this->connection->quoteIdentifier('eic.contentobject_id'),
47
                    $this->connection->quoteIdentifier('eco.id')
48
                )
49
            )
50
            ->leftJoin(
51
                'eic',
52
                $this->connection->quoteIdentifier('ezcontentobject_tree'),
53
                'ecot',
54
                $query->expr()->eq(
55
                    $this->connection->quoteIdentifier('eic.contentobject_id'),
56
                    $this->connection->quoteIdentifier('ecot.contentobject_id')
57
                )
58
            );
59
60
        $statement = $query->execute();
61
62
        return (int) $statement->fetchColumn();
63
    }
64
65
    /**
66
     * Returns content objects with their collections.
67
     *
68
     * @param int $limit
69
     * @param int $offset
70
     *
71
     * @throws \Doctrine\DBAL\DBALException
72
     *
73
     * @return array
74
     */
75
    public function getObjectsWithCollections($limit, $offset)
76
    {
77
        $contentIdsQuery = $this->connection->createQueryBuilder();
78
        $contentIdsQuery
79
            ->select('DISTINCT contentobject_id AS id')
80
            ->from($this->connection->quoteIdentifier('ezinfocollection'));
81
82
        $statement = $contentIdsQuery->execute();
83
84
        $contents = [];
85
        foreach ($statement->fetchAll() as $content) {
86
            $contents[] = (int) $content['id'];
87
        }
88
89
        if (empty($contents)) {
90
            return [];
91
        }
92
93
        $query = $this->connection->createQueryBuilder();
94
        $query
95
            ->select(
96
                'eco.id AS content_id',
97
                'eco.name',
98
                'ecot.main_node_id',
99
                'ecc.serialized_name_list',
100
                'ecc.identifier AS class_identifier'
101
            )
102
            ->from($this->connection->quoteIdentifier('ezcontentobject'), 'eco')
103
            ->leftJoin(
104
                'eco',
105
                $this->connection->quoteIdentifier('ezcontentobject_tree'),
106
                'ecot',
107
                $query->expr()->eq(
108
                    $this->connection->quoteIdentifier('eco.id'),
109
                    $this->connection->quoteIdentifier('ecot.contentobject_id')
110
                )
111
            )
112
            ->innerJoin(
113
                'eco',
114
                $this->connection->quoteIdentifier('ezcontentclass'),
115
                'ecc',
116
                $query->expr()->eq(
117
                    $this->connection->quoteIdentifier('eco.contentclass_id'),
118
                    $this->connection->quoteIdentifier('ecc.id')
119
                )
120
            )
121
            ->where(
122
                $query->expr()->eq('ecc.version', 0)
123
            )
124
            ->andWhere($query->expr()->in('eco.id', $contents))
125
            ->groupBy($this->connection->quoteIdentifier('ecot.main_node_id'))
126
            ->setFirstResult($offset)
127
            ->setMaxResults($limit);
128
129
        $statement = $query->execute();
130
131
        return $statement->fetchAll(PDO::FETCH_ASSOC);
132
    }
133
}
134