Completed
Pull Request — master (#75)
by
unknown
01:26
created

Email   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 11.11 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 3
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A filter() 3 13 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace TraderInteractive\Filter;
4
5
/**
6
 * A collection of filters for emails.
7
 */
8
final class Email
9
{
10
    /**
11
     * Filter an email
12
     *
13
     * The return value is the email, as expected by the \TraderInteractive\Filterer class.
14
     *
15
     * @param mixed $value The value to filter.
16
     *
17
     * @return string The passed in $value.
18
     *
19
     * @throws Exception if the value did not pass validation.
20
     */
21
    public static function filter($value) : string
22
    {
23 View Code Duplication
        if (!is_string($value)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
            throw new Exception("Value '" . var_export($value, true) . "' is not a string");
25
        }
26
27
        $filteredEmail = filter_var($value, FILTER_VALIDATE_EMAIL);
28
        if ($filteredEmail === false) {
29
            throw new Exception("Value '{$value}' is not a valid email");
30
        }
31
32
        return $filteredEmail;
33
    }
34
}
35