FrontendUserRepository::__construct()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DMK\MKSamlAuth\Repository;
6
7
use DMK\MKSamlAuth\Model\FrontendUser;
8
use TYPO3\CMS\Core\Database\ConnectionPool;
9
10
class FrontendUserRepository
11
{
12
    /**
13
     * @var string
14
     */
15
    private $table = 'fe_users';
16
17
    /**
18
     * @var ConnectionPool
19
     */
20
    private $pool;
21
22
    public function __construct(ConnectionPool $pool)
23
    {
24
        $this->pool = $pool;
25
    }
26
27
    public function find(int $uid)
28
    {
29
        $qb = $this->pool->getConnectionForTable($this->table)->createQueryBuilder();
30
        $qb->select('*')->from($this->table);
31
        $qb->where($qb->expr()->eq('uid', ':uid'));
32
        $qb->setParameter('uid', $uid);
33
        $data = $qb->execute()->fetch(\PDO::FETCH_ASSOC);
34
35
        if (\is_array($data)) {
36
            return new FrontendUser($data);
37
        }
38
39
        return null;
40
    }
41
42
    public function findByUsername(string $username, int $pid)
43
    {
44
        $qb = $this->pool->getConnectionForTable($this->table)->createQueryBuilder();
45
        $qb->select('*')->from($this->table);
46
        $qb->where($qb->expr()->andX(
47
            $qb->expr()->eq('username', ':username'),
48
            $qb->expr()->eq('pid', ':pid')
49
        ));
50
        $qb->setParameter('username', $username);
51
        $qb->setParameter('pid', $pid);
52
53
        $data = $qb->execute()->fetch(\PDO::FETCH_ASSOC);
54
55
        if (\is_array($data)) {
56
            return new FrontendUser($data);
57
        }
58
59
        return null;
60
    }
61
}
62