Completed
Pull Request — master (#31)
by Gawain
01:46
created

NullConnection::setReceive()   C

Complexity

Conditions 12
Paths 12

Size

Total Lines 27
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 156

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 0
cts 24
cp 0
rs 5.1612
c 0
b 0
f 0
cc 12
eloc 24
nc 12
nop 1
crap 156

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol\Smtp;
5
6
use Genkgo\Mail\Protocol\ConnectionInterface;
7
8
/**
9
 * Class NullConnection
10
 * @package Genkgo\Mail\Protocol
11
 */
12
final class NullConnection implements ConnectionInterface
13
{
14
    private $receive;
15
16 2
    public function addListener(string $name, \Closure $callback): void
17
    {
18 2
    }
19
20 1
    public function connect(): void
21
    {
22 1
    }
23
24 1
    public function disconnect(): void
25
    {
26 1
    }
27
28
    public function send(string $request): int
29
    {
30
        $this->setReceive($request);
31
32
        return 0;
33
    }
34
35
    public function receive(): string
36
    {
37
        return $this->receive;
38
    }
39
40 1
    public function upgrade(int $type): void
41
    {
42 1
    }
43
44 1
    public function timeout(float $timeout): void
45
    {
46 1
    }
47
48 1
    public function getMetaData(array $keys = []): array
49
    {
50 1
        return [];
51
    }
52
53
    private function setReceive(string $request): void
54
    {
55
        $command = explode(' ', strtoupper(trim($request)));
56
        switch ($command[0]) {
57
            case 'AUTH':
58
            case 'HELO':
59
            case 'EHLO':
60
            case 'MAIL':
61
            case 'RCPT':
62
            case 'RSET':
63
            case 'NOOP':
64
            case '.':
65
                $this->receive = '250 Ok';
66
                break;
67
            case 'DATA':
68
                $this->receive = '354 End data with <CR><LF>.<CR><LF>';
69
                break;
70
            case 'QUIT':
71
                $this->receive = '221 Bye';
72
                break;
73
            case 'VRFY':
74
                $this->receive = '252 null@null';
75
                break;
76
            default:
77
                $this->receive = '';
78
        }
79
    }
80
}
81