| Total Complexity | 4 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class TransactionLineRepository extends AbstractRepository implements LimitedAccessSubQueryInterface |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * Returns pure SQL to get ID of all objects that are accessible to given user. |
||
| 15 | * |
||
| 16 | * @param null|User $user |
||
| 17 | * |
||
| 18 | * @return string |
||
| 19 | */ |
||
| 20 | 6 | public function getAccessibleSubQuery(?User $user): string |
|
| 21 | { |
||
| 22 | 6 | if (!$user) { |
|
| 23 | 1 | return '-1'; |
|
| 24 | } |
||
| 25 | |||
| 26 | 5 | if (in_array($user->getRole(), [User::ROLE_RESPONSIBLE, User::ROLE_ADMINISTRATOR], true)) { |
|
| 27 | 2 | return $this->getAllIdsQuery(); |
|
| 28 | } |
||
| 29 | |||
| 30 | return 'SELECT transaction_line.id FROM transaction_line |
||
| 31 | JOIN account ON transaction_line.debit_id = account.id OR transaction_line.credit_id = account.id |
||
| 32 | 3 | WHERE account.owner_id = ' . $user->getId(); |
|
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Get all transaction lines matching a given account in credit or debit |
||
| 37 | * |
||
| 38 | * @return TransactionLine[] |
||
| 39 | */ |
||
| 40 | 1 | public function findByDebitOrCredit(Account $account): array |
|
| 52 | } |
||
| 53 | } |
||
| 54 |