FacilitatorDocumentRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 4
dl 0
loc 18
ccs 0
cts 4
cp 0
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getAccessibleSubQuery() 0 7 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Repository;
6
7
use Application\Model\FacilitatorDocument;
8
use Application\Model\User;
9
10
use Ecodev\Felix\Repository\LimitedAccessSubQuery;
11
12
/**
13
 * @extends AbstractRepository<FacilitatorDocument>
14
 */
15
class FacilitatorDocumentRepository extends AbstractRepository implements LimitedAccessSubQuery
16
{
17
    /**
18
     * Returns pure SQL to get ID of all objects that are accessible to given user.
19
     *
20
     * A user can access a file if at least one of the following conditions is true:
21
     *
22
     * - he is facilitator or administrator
23
     *
24
     * @param null|User $user
25
     */
26
    public function getAccessibleSubQuery(?\Ecodev\Felix\Model\User $user): string
27
    {
28
        if ($user && in_array($user->getRole(), [User::ROLE_FACILITATOR, User::ROLE_ADMINISTRATOR], true)) {
29
            return '';
30
        }
31
32
        return 'SELECT id FROM facilitator_document WHERE facilitator_document.is_active';
33
    }
34
}
35