getAccessibleSubQuery()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
c 1
b 0
f 0
cc 3
nc 2
nop 1
crap 12
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