Failed Conditions
Push — master ( 977552...4856db )
by Adrien
12:24
created

getAccessibleSubQuery()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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