GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

NotThrowawayEmailValidator::validate()   B
last analyzed

Complexity

Conditions 7
Paths 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 8.8333
c 0
b 0
f 0
cc 7
nc 4
nop 2
1
<?php
2
3
/*
4
 * This file is part of the EmailChecker package.
5
 *
6
 * (c) Matthieu Moquet <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EmailChecker\Constraints;
13
14
use EmailChecker\Adapter\BuiltInAdapter;
15
use EmailChecker\EmailChecker;
16
use Symfony\Component\Validator\Constraint;
17
use Symfony\Component\Validator\ConstraintValidator;
18
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
19
20
/**
21
 * @author Matthieu Moquet <[email protected]>
22
 */
23
class NotThrowawayEmailValidator extends ConstraintValidator
24
{
25
    protected $emailChecker;
26
27
    /**
28
     * @param EmailChecker $emailChecker
29
     */
30
    public function __construct(EmailChecker $emailChecker = null)
31
    {
32
        $this->emailChecker = $emailChecker ?: new EmailChecker(new BuiltInAdapter());
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function validate($value, Constraint $constraint)
39
    {
40
        if (null === $value || '' === $value) {
41
            return;
42
        }
43
44
        if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
45
            throw new UnexpectedTypeException($value, 'string');
46
        }
47
48
        if (!$this->emailChecker->isValid($value)) {
49
            $this->context->addViolation($constraint->message);
50
        }
51
    }
52
}
53