Completed
Pull Request — master (#31)
by Gawain
02:03
created

NullConnection   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 20
lcom 1
cbo 0
dl 0
loc 69
rs 10
c 0
b 0
f 0

9 Methods

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