Request   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 56.9 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 33
loc 58
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A withAddedRecipient() 7 7 1
A withAddedRecipients() 9 9 2
A withRecipient() 8 8 1
A withRecipients() 9 9 2
A validateEmail() 0 6 2

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
namespace SamIT\React\Smtp;
3
4
/**
5
 * Description of Request
6
 *
7
 * @author Sam
8
 */
9
class Request implements RequestInterface 
10
{
11
    use \GuzzleHttp\Psr7\MessageTrait {
12
        withHeader as withParentHeader;
13
    }
14
15
    /** @var array Cached HTTP header collection with lowercase key to values */
16
    private $recipients = [];
0 ignored issues
show
Unused Code introduced by
The property $recipients is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
17
18
19 View Code Duplication
    public function withAddedRecipient($email, $name = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
20
    {
21
        $this->validateEmail($email);
22
        $new = clone $this;
23
        $new->recipients[$email] = $name;
24
        return $new;
25
    }
26
27 View Code Duplication
    public function withAddedRecipients(array $recipients) 
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
28
    {
29
        $new = clone $this;
30
        foreach($recipients as $email => $name) {
31
            $this->validateEmail($email);
32
            $new->recipients[$email] = $name;
33
        }
34
        return $new;
35
    }
36
37 View Code Duplication
    public function withRecipient($email, $name = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
38
    {
39
        $this->validateEmail($email);
40
        $new = clone $this;
41
        $new->recipients = [];
42
        $new->recipients[$email] = $name;
43
        return $new;
44
    }
45
46 View Code Duplication
    public function withRecipients(array $recipients) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
47
        $new = clone $this;
48
        $new->recipients = [];
49
        foreach($recipients as $email => $name) {
50
            $this->validateEmail($email);
51
            $new->recipients[$email] = $name;
52
        }
53
        return $new;
54
    }
55
56
    /**
57
     * @throws \InvalidArgumentException
58
     */
59
    protected function validateEmail($email)
60
    {
61
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
62
            throw new \InvalidArgumentException("$email is not a valid email address");
63
        }
64
    }
65
66
}
67