getAccessibleSubQuery()   A
last analyzed

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\AccountingDocument;
8
use Application\Model\User;
9
10
use Ecodev\Felix\Repository\LimitedAccessSubQuery;
11
12
/**
13
 * @extends AbstractRepository<AccountingDocument>
14
 */
15
class AccountingDocumentRepository extends AbstractRepository implements LimitedAccessSubQuery
16
{
17
    /**
18
     * Returns pure SQL to get ID of all objects that are accessible to given user.
19
     *
20
     * @param null|User $user
21
     */
22 10
    public function getAccessibleSubQuery(?\Ecodev\Felix\Model\User $user): string
23
    {
24 10
        if (!$user) {
25 1
            return '-1';
26
        }
27
28 9
        if (in_array($user->getRole(), [User::ROLE_ACCOUNTING_VERIFICATOR, User::ROLE_RESPONSIBLE, User::ROLE_ADMINISTRATOR], true)) {
29 6
            return '';
30
        }
31
32 3
        return $this->getAllIdsForFamilyQuery($user);
33
    }
34
}
35