findUserByEmail()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 11
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 11
ccs 6
cts 6
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Module\Authentication\PasswordReset\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
use App\Module\User\Data\UserData;
7
8
readonly class PasswordResetUserFinderRepository
9
{
10 6
    public function __construct(
11
        private QueryFactory $queryFactory,
12
    ) {
13 6
    }
14
15
    /**
16
     * Return user with given id if it exists
17
     * If there is no user, an empty object is returned because:
18
     * > It is considered a best practice to NEVER return null when returning a collection or enumerable
19
     * Source: https://stackoverflow.com/a/1970001/9013718.
20
     *
21
     * @param string|null $email
22
     *
23
     * @return UserData
24
     */
25 2
    public function findUserByEmail(?string $email): UserData
26
    {
27 2
        $query = $this->queryFactory->selectQuery()->select(['*'])->from('user')->andWhere(
28 2
            ['deleted_at IS' => null, 'email' => $email]
29 2
        );
30
31 2
        $userValues = $query->execute()->fetch('assoc') ?: [];
32
33
        // Empty user object if not found
34
        // $notRestricted true as values are safe as they come from the database. It's not a user input.
35 2
        return new UserData($userValues);
36
    }
37
}
38