UserAuthLoader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
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 UserAuthLoader 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('u.username AS v0', 'ug.identifier AS v1')
34
            ->from('users', 'u')
35
            ->innerJoin('users_user_groups', 'uug', 'uug.user_id = u.id AND uug.deleted_at IS NULL')
36
            ->innerJoin('user_groups', 'ug', 'uug.user_group_id = ug.id AND ug.deleted_at IS NULL')
37
            ->where('u.deleted_at IS NULL')
38
        ;
39
40
        $connection = $this->connectionPool->getReadConnection();
41
        $statement  = $connection->prepare($query->getSql());
42
        $statement->bindValues($query->getParameters());
43
        if (!$statement->execute()) {
44
            throw new Database($statement->errorInfo());
45
        }
46
47
        return $statement->fetchAll(\PDO::FETCH_ASSOC);
48
    }
49
}
50