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

NullConnection   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 29.27%

Importance

Changes 0
Metric Value
wmc 20
lcom 1
cbo 0
dl 0
loc 69
ccs 12
cts 41
cp 0.2927
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 upgrade() 0 3 1
A timeout() 0 3 1
A getMetaData() 0 4 1
A send() 0 6 1
A receive() 0 4 1
C setReceive() 0 27 12
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