Completed
Push — master ( 5840b0...fcc03f )
by Frederik
04:51
created

ArrayGreyList::contains()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Genkgo\Mail\Protocol\Smtp\GreyList;
4
5
use Genkgo\Mail\MessageInterface;
6
use Genkgo\Mail\Protocol\Smtp\GreyListInterface;
7
8
/**
9
 * Class ArrayGreyList
10
 * @package Genkgo\Mail\Protocol\Smtp\GreyList
11
 */
12
final class ArrayGreyList implements GreyListInterface
13
{
14
15
    /**
16
     * @var array
17
     */
18
    private $list = [];
19
20
    /**
21
     * @param MessageInterface $message
22
     * @return bool
23
     */
24 2
    public function contains(MessageInterface $message): bool
25
    {
26 2
        $hash = hash('sha256', (string)$message);
27 2
        return isset($this->list[$hash]);
28
    }
29
30
    /**
31
     * @param MessageInterface $message
32
     */
33 2
    public function attach(MessageInterface $message): void
34
    {
35 2
        $hash = hash('sha256', (string)$message);
36 2
        $this->list[$hash] = true;
37 2
    }
38
39
    /**
40
     * @param MessageInterface $message
41
     */
42 2
    public function detach(MessageInterface $message): void
43
    {
44 2
        $hash = hash('sha256', (string)$message);
45 2
        unset($this->list[$hash]);
46
    }
47
}