Completed
Push — master ( 3ac846...67b859 )
by Adrien
07:43
created

TransactionLineRepository::findByDebitOrCredit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0
ccs 8
cts 8
cp 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Repository;
6
7
use Application\Model\User;
8
9
class TransactionLineRepository 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 7
    public function getAccessibleSubQuery(?User $user): string
19
    {
20 7
        if (!$user) {
21 1
            return '-1';
22
        }
23
24 6
        if (in_array($user->getRole(), [User::ROLE_RESPONSIBLE, User::ROLE_ADMINISTRATOR], true)) {
25 3
            return $this->getAllIdsQuery();
26
        }
27
28
        return 'SELECT transaction_line.id FROM transaction_line
29
              JOIN account ON transaction_line.debit_id = account.id OR transaction_line.credit_id = account.id 
30 3
              WHERE account.owner_id = ' . $user->getId();
31
    }
32
}
33