Passed
Push — master ( a8b983...5b3176 )
by Adrien
10:48
created

OrderRepository::getAccessibleSubQuery()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 3
rs 10
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 OrderRepository extends AbstractRepository implements LimitedAccessSubQuery
11
{
12
    /**
13
     * Returns pure SQL to get ID of all objects that are accessible to given user.
14
     *
15
     * @param null|User $user
16
     */
17 9
    public function getAccessibleSubQuery(?\Ecodev\Felix\Model\User $user): string
18
    {
19 9
        if (!$user) {
20 1
            return '-1';
21
        }
22
23 8
        if (in_array($user->getRole(), [User::ROLE_FACILITATOR, User::ROLE_ADMINISTRATOR], true)) {
24 3
            return $this->getAllIdsQuery();
25
        }
26
27 5
        return $this->getAllIdsForOwnerQuery($user);
28
    }
29
}
30