Completed
Pull Request — master (#31)
by Gawain
01:46
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 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