Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#995)
by Paul Kofi
02:57
created

Email   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
wmc 8
dl 0
loc 42
ccs 13
cts 15
cp 0.8667
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A validate() 0 12 4
A getEmailValidator() 0 8 3
1
<?php
2
3
/*
4
 * This file is part of Respect/Validation.
5
 *
6
 * (c) Alexandre Gomes Gaigalas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the "LICENSE.md"
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Respect\Validation\Rules;
15
16
use Egulias\EmailValidator\EmailValidator;
17
use Egulias\EmailValidator\Validation\RFCValidation;
18
use const FILTER_VALIDATE_EMAIL;
19
use function class_exists;
20
use function filter_var;
21
use function is_string;
22
23
/**
24
 * Validates an email address.
25
 *
26
 * @author Eduardo Gulias Davis <[email protected]>
27
 * @author Henrique Moody <[email protected]>
28
 * @author Paul Karikari <[email protected]>
29
 */
30
final class Email extends AbstractRule
31
{
32
    /**
33
     * Assigns email validator.
34
     *
35
     * @param EmailValidator $emailValidator
36
     */
37 7
    public function __construct(EmailValidator $emailValidator = null)
38
    {
39 7
        $this->emailValidator = $emailValidator;
0 ignored issues
show
Bug Best Practice introduced by
The property emailValidator does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
40 7
    }
41
42
    /**
43
     * Gets email validator.
44
     *
45
     * @return EmailValidator | null
46
     */
47 20
    public function getEmailValidator()
48
    {
49 20
        if (class_exists(EmailValidator::class)
50 20
            && !$this->emailValidator instanceof EmailValidator) {
51 18
            $this->emailValidator = new EmailValidator();
0 ignored issues
show
Bug Best Practice introduced by
The property emailValidator does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
52
        }
53
54 20
        return $this->emailValidator;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60 18
    public function validate($input): bool
61
    {
62 18
        $emailValidator = $this->getEmailValidator();
63 18
        if (!$emailValidator instanceof EmailValidator) {
64
            return is_string($input) && filter_var($input, FILTER_VALIDATE_EMAIL);
65
        }
66
67 18
        if (!class_exists(RFCValidation::class)) {
68
            return $emailValidator->isValid($input);
0 ignored issues
show
Bug introduced by
The call to Egulias\EmailValidator\EmailValidator::isValid() has too few arguments starting with emailValidation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
            return $emailValidator->/** @scrutinizer ignore-call */ isValid($input);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
69
        }
70
71 18
        return $emailValidator->isValid($input, new RFCValidation());
72
    }
73
}
74