UserExistenceCheckerRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 26
ccs 9
cts 9
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 userWithEmailAlreadyExists() 0 11 2
1
<?php
2
3
namespace App\Module\User\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 UserExistenceCheckerRepository
8
{
9 19
    public function __construct(
10
        private QueryFactory $queryFactory,
11
    ) {
12 19
    }
13
14
    /**
15
     * Checks if user with given email already exists.
16
     *
17
     * @param string $email
18
     * @param int|null $userIdToExclude exclude user that already has the email from check (for update)
19
     *
20
     * @return bool
21
     */
22 12
    public function userWithEmailAlreadyExists(string $email, ?int $userIdToExclude = null): bool
23
    {
24 12
        $query = $this->queryFactory->selectQuery()->select(['id'])->from('user')->andWhere(
25 12
            ['deleted_at IS' => null, 'email' => $email]
26 12
        );
27
28 12
        if ($userIdToExclude !== null) {
29 6
            $query->andWhere(['id !=' => $userIdToExclude]);
30
        }
31
32 12
        return $query->execute()->fetch('assoc') !== false;
33
    }
34
}
35