ClientReadNoteAmountFinderRepository   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 31
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A findClientNotesAmount() 0 17 1
1
<?php
2
3
namespace App\Module\Client\Read\Repository;
4
5
use App\Infrastructure\Database\QueryFactory;
0 ignored issues
show
Bug introduced by
The type App\Infrastructure\Database\QueryFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
readonly class ClientReadNoteAmountFinderRepository
8
{
9 4
    public function __construct(
10
        private QueryFactory $queryFactory,
11
    ) {
12 4
    }
13
14
    /**
15
     * Find the amount of notes without counting the main note.
16
     *
17
     * @param int $clientId
18
     *
19
     * @return int
20
     */
21 3
    public function findClientNotesAmount(int $clientId): int
22
    {
23 3
        $query = $this->queryFactory->selectQuery()->from('client');
24
25 3
        $query->select(['amount' => $query->func()->count('n.id')])
26 3
            ->join(['n' => ['table' => 'note', 'type' => 'LEFT', 'conditions' => 'n.client_id = client.id']])
27 3
            ->where(
28 3
                [
29 3
                    'client.id' => $clientId,
30
                    // The main note should not be counted in
31 3
                    'n.is_main' => 0,
32 3
                    'n.deleted_at IS' => null,
33 3
                ]
34 3
            );
35
36
        // Return amount of notes
37 3
        return (int)$query->execute()->fetch('assoc')['amount'];
38
    }
39
}
40