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
03:13
created

Email::validate()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.3731

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 5
cts 7
cp 0.7143
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 4
nop 1
crap 4.3731
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 is_string;
20
use function filter_var;
21
use function class_exists;
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