findPasswordHashFromUserId()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

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