Passed
Pull Request — master (#75)
by Nathan
05:29
created

EntitySlackMessageBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getMessage() 0 5 1
1
<?php
2
3
/*
4
 * Copyright (C) 2018
5
 * Nathan Boiron <[email protected]>
6
 * Romain Canon <[email protected]>
7
 *
8
 * This file is part of the TYPO3 NotiZ project.
9
 * It is free software; you can redistribute it and/or modify it
10
 * under the terms of the GNU General Public License, either
11
 * version 3 of the License, or any later version.
12
 *
13
 * For the full copyright and license information, see:
14
 * http://www.gnu.org/licenses/gpl-3.0.html
15
 */
16
17
namespace CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\Service;
18
19
use CuyZ\Notiz\Core\Channel\Payload;
20
use CuyZ\Notiz\Core\Property\Service\MarkerParser;
21
use CuyZ\Notiz\Domain\Notification\Slack\SlackNotification;
22
use CuyZ\Notiz\Domain\Property\Marker;
23
24
class EntitySlackMessageBuilder
25
{
26
    /**
27
     * @var SlackNotification
28
     */
29
    protected $notification;
30
31
    /**
32
     * @var MarkerParser
33
     */
34
    protected $markerParser;
35
36
    /**
37
     * @var Marker[]
38
     */
39
    protected $markers = [];
40
41
    /**
42
     * @param Payload $payload
43
     * @param MarkerParser $markerParser
44
     */
45
    public function __construct(Payload $payload, MarkerParser $markerParser)
46
    {
47
        $this->notification = $payload->getNotification();
48
        $this->markerParser = $markerParser;
49
50
        $this->markers = $payload->getEvent()->getProperties(Marker::class);
51
    }
52
53
    /**
54
     * Returns the message with markers replaced.
55
     *
56
     * @return string
57
     */
58
    public function getMessage()
59
    {
60
        return $this->markerParser->replaceMarkers(
61
            $this->notification->getMessage(),
62
            $this->markers
63
        );
64
    }
65
}
66