Completed
Push — master ( f6a106...f56acc )
by Frederik
01:42
created

NullConnection::pushResponseToBuffer()   C

Complexity

Conditions 12
Paths 12

Size

Total Lines 27
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 12

Importance

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

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 1
    public function addListener(string $name, \Closure $callback): void
17
    {
18 1
    }
19
20 1
    public function connect(): void
21
    {
22 1
    }
23
24 1
    public function disconnect(): void
25
    {
26 1
    }
27
28 11
    public function send(string $request): int
29
    {
30 11
        $this->pushResponseToBuffer($request);
31
32 11
        return 0;
33
    }
34
35 11
    public function receive(): string
36
    {
37 11
        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 11
    private function pushResponseToBuffer(string $request): void
54
    {
55 11
        $command = explode(' ', strtoupper(trim($request)));
56 11
        switch ($command[0]) {
57 11
            case 'AUTH':
58 10
            case 'HELO':
59 9
            case 'EHLO':
60 8
            case 'MAIL':
61 7
            case 'RCPT':
62 6
            case 'RSET':
63 5
            case 'NOOP':
64 4
            case '.':
65 7
                $this->receive = '250 Ok';
66 7
                break;
67 4
            case 'DATA':
68 1
                $this->receive = '354 End data with <CR><LF>.<CR><LF>';
69 1
                break;
70 3
            case 'QUIT':
71 1
                $this->receive = '221 Bye';
72 1
                break;
73 2
            case 'VRFY':
74 1
                $this->receive = '252 null@null';
75 1
                break;
76
            default:
77 1
                $this->receive = '';
78
        }
79 11
    }
80
}
81