AdminResourceAuthLoader   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 14
c 1
b 0
f 0
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A loadAll() 0 17 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Admin\Databases\Queries;
6
7
use AbterPhp\Admin\Exception\Database;
8
use Opulence\Databases\ConnectionPools\ConnectionPool;
9
use Opulence\QueryBuilders\MySql\QueryBuilder;
10
11
/** @phan-file-suppress PhanTypeMismatchArgument */
12
13
class AdminResourceAuthLoader implements IAuthLoader
14
{
15
    protected ConnectionPool $connectionPool;
16
17
    /**
18
     * BlockCache constructor.
19
     *
20
     * @param ConnectionPool $connectionPool
21
     */
22
    public function __construct(ConnectionPool $connectionPool)
23
    {
24
        $this->connectionPool = $connectionPool;
25
    }
26
27
    /**
28
     * @return array
29
     */
30
    public function loadAll(): array
31
    {
32
        $query = (new QueryBuilder())
33
            ->select('ug.identifier AS v0', 'ar.identifier AS v1')
34
            ->from('user_groups_admin_resources', 'ugar')
35
            ->innerJoin('admin_resources', 'ar', 'ugar.admin_resource_id = ar.id AND ar.deleted_at IS NULL')
36
            ->innerJoin('user_groups', 'ug', 'ugar.user_group_id = ug.id AND ug.deleted_at IS NULL')
37
        ;
38
39
        $connection = $this->connectionPool->getReadConnection();
40
        $statement  = $connection->prepare($query->getSql());
41
        $statement->bindValues($query->getParameters());
42
        if (!$statement->execute()) {
43
            throw new Database($statement->errorInfo());
44
        }
45
46
        return $statement->fetchAll(\PDO::FETCH_ASSOC);
47
    }
48
}
49