FileNotificationType   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 54
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A notify() 0 6 2
A getPathMessage() 0 4 1
A setPathMessage() 0 7 2
A getSubjectNotifyFilePath() 0 4 1
1
<?php
2
3
namespace TonicHealthCheck\Incident\Siren\NotificationType;
4
5
use TonicHealthCheck\Incident\IncidentInterface;
6
use TonicHealthCheck\Incident\Siren\Subject\SubjectInterface;
7
8
/**
9
 * Class FileNotificationType.
10
 */
11
class FileNotificationType implements NotificationTypeInterface
12
{
13
    protected $pathMessage;
14
15
    /**
16
     * FileNotificationType constructor.
17
     *
18
     * @param string $pathMessage
19
     */
20 2
    public function __construct($pathMessage)
21
    {
22 2
        $this->setPathMessage($pathMessage);
23 2
    }
24
25
    /**
26
     * @param SubjectInterface  $subject
27
     * @param IncidentInterface $incident
28
     */
29 1
    public function notify(SubjectInterface $subject, IncidentInterface $incident)
30
    {
31 1
        if ($incident->getStatus() != IncidentInterface::STATUS_OK) {
32 1
            file_put_contents($this->getSubjectNotifyFilePath($subject), $incident->getMessage());
33
        }
34 1
    }
35
36
    /**
37
     * @return string
38
     */
39 1
    public function getPathMessage()
40
    {
41 1
        return $this->pathMessage;
42
    }
43
44
    /**
45
     * @param string $pathMessage
46
     */
47 2
    public function setPathMessage($pathMessage)
48
    {
49 2
        if (!is_writable($pathMessage)) {
50 1
            throw FileNotificationTypeException::dirForMessageDoesNotWritable($pathMessage);
51
        }
52 2
        $this->pathMessage = rtrim($pathMessage, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
53 2
    }
54
55
    /**
56
     * @param SubjectInterface $subject
57
     *
58
     * @return string
59
     */
60 1
    public function getSubjectNotifyFilePath(SubjectInterface $subject)
61
    {
62 1
        return $this->getPathMessage().$subject;
63
    }
64
}
65