UserFinderRepository::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
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