Request::withAddedRecipient()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 7
loc 7
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
crap 2
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