UserPasswordHashFinderRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 25
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A findPasswordHashFromUserId() 0 10 2
1
<?php
2
3
namespace App\Module\Authentication\Validation\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 UserPasswordHashFinderRepository
8
{
9 48
    public function __construct(
10
        private QueryFactory $queryFactory,
11
    ) {
12 48
    }
13
14
    /**
15
     * Return user with password hash if it exists
16
     * otherwise null.
17
     *
18
     * @param int $id
19
     *
20
     * @return string|null
21
     */
22 4
    public function findPasswordHashFromUserId(int $id): ?string
23
    {
24 4
        $query = $this->queryFactory->selectQuery()->select(['password_hash'])->from('user')->where(
25 4
            ['deleted_at IS' => null, 'id' => $id]
26 4
        );
27 4
        $userValues = $query->execute()->fetch('assoc') ?: [];
28
29
        // Empty user object if not found
30
        // $notRestricted true as values are safe as they come from the database. It's not a user input.
31 4
        return $userValues['password_hash'] ?? null;
32
    }
33
}
34