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

LogRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
c 2
b 0
f 0
dl 0
loc 29
ccs 4
cts 8
cp 0.5
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getAccessibleSubQuery() 0 17 3
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