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

NullConnection::addListener()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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