userWithEmailAlreadyExists()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

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