UserFinderRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 37
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findUserById() 0 8 2
A __construct() 0 3 1
1
<?php
2
3
namespace App\Module\User\Find\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
class UserFinderRepository
8
{
9
    // Fields without password
10
    private array $fields = [
11
        'id',
12
        'first_name',
13
        'last_name',
14
        'email',
15
        'user_role_id',
16
        'status',
17
        'updated_at',
18
        'created_at',
19
        'theme',
20
        'language',
21
    ];
22
23 203
    public function __construct(
24
        private readonly QueryFactory $queryFactory,
25
    ) {
26 203
    }
27
28
    /**
29
     * Return user with given id if it exists
30
     * otherwise null.
31
     *
32
     * @param int $id
33
     *
34
     * @return array user row
35
     */
36 157
    public function findUserById(int $id): array
37
    {
38 157
        $query = $this->queryFactory->selectQuery()->select($this->fields)->from('user')->where(
39 157
            ['deleted_at IS' => null, 'id' => $id]
40 157
        );
41
42
        // Empty array if not found
43 157
        return $query->execute()->fetch('assoc') ?: [];
44
    }
45
}
46