UserListFinderRepository::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
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 2
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Module\User\FindList\Repository;
4
5
use App\Infrastructure\Database\Hydrator;
6
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...
7
use App\Module\User\Data\UserData;
8
9
class UserListFinderRepository
10
{
11
    // Fields without password
12
    private array $fields = [
13
        'id',
14
        'first_name',
15
        'last_name',
16
        'email',
17
        'user_role_id',
18
        'status',
19
        'updated_at',
20
        'created_at',
21
        'theme',
22
        'language',
23
    ];
24
25 28
    public function __construct(
26
        private readonly QueryFactory $queryFactory,
27
        private readonly Hydrator $hydrator,
28
    ) {
29 28
    }
30
31
    /**
32
     * Return all users.
33
     *
34
     * @return UserData[]
35
     */
36 21
    public function findAllUsers(): array
37
    {
38
        // Convert to list of objects
39 21
        return $this->hydrator->hydrate($this->findAllUserRows(), UserData::class);
40
    }
41
42
    /**
43
     * Returns array of user rows.
44
     *
45
     * @return array
46
     */
47 25
    public function findAllUserRows(): array
48
    {
49 25
        $query = $this->queryFactory->selectQuery()->select($this->fields)->from('user')->where(
50 25
            ['deleted_at IS' => null]
51 25
        );
52
53 25
        return $query->execute()->fetchAll('assoc') ?: [];
54
    }
55
}
56