FrontendUserRepository   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 50
ccs 0
cts 31
cp 0
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A findByUsername() 0 18 2
A __construct() 0 3 1
A find() 0 13 2
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