Failed Conditions
Push — master ( 51347b...4787ce )
by Adrien
08:37
created

LogRepository::failedOften()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 32
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 4.0119

Importance

Changes 0
Metric Value
cc 4
eloc 22
nc 6
nop 2
dl 0
loc 32
ccs 20
cts 22
cp 0.9091
crap 4.0119
rs 9.568
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Repository;
6
7
use Application\Model\User;
8
use Ecodev\Felix\Repository\LimitedAccessSubQuery;
9
10
class LogRepository extends AbstractRepository implements \Ecodev\Felix\Repository\LogRepository, LimitedAccessSubQuery
11
{
12
    /**
13
     * Log message to be used when a door is opened
14
     */
15
    const DOOR_OPENED = 'door opened: ';
16
17
    use \Ecodev\Felix\Repository\Traits\LogRepository;
18
19
    /**
20
     * Returns pure SQL to get ID of all objects that are accessible to given user.
21
     */
22 1
    public function getAccessibleSubQuery(?\Ecodev\Felix\Model\User $user): string
23
    {
24 1
        if (!$user) {
25
            return '-1';
26
        }
27
28
        // Sysops and responsible can read all logs
29 1
        if (in_array($user->getRole(), [User::ROLE_RESPONSIBLE, User::ROLE_ADMINISTRATOR], true)) {
30 1
            return $this->getAllIdsQuery();
31
        }
32
33
        $subquery = '
34
            SELECT log.id FROM `log` WHERE
35
            message LIKE ' . $this->getEntityManager()->getConnection()->quote(self::DOOR_OPENED . '%') . '
36
            AND log.creator_id = ' . $user->getId();
37
38
        return $subquery;
39
    }
40
}
41