Test Failed
Push — feature-laravel-5.4 ( 4fdb88...efd971 )
by Kirill
03:29
created

AbstractRenderer::parseEventsOutput()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of laravel.su package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace App\Services\ContentRenderer;
10
11
/**
12
 * Class Renderer.
13
 */
14
abstract class AbstractRenderer implements ContentRenderInterface
15
{
16
    private const EVENT_PARSE_BEFORE = 'parse.before';
17
    private const EVENT_PARSE_AFTER = 'parse.after';
18
19
    /**
20
     * @var array|\Closure[]
21
     */
22
    private $before = [];
23
24
    /**
25
     * @var array|\Closure[]
26
     */
27
    private $after = [];
28
29
    /**
30
     * @param  \Closure                     $callback
31
     * @return $this|ContentRenderInterface
32
     */
33
    public function before(\Closure $callback): ContentRenderInterface
34
    {
35
        $this->before[] = $callback;
36
37
        return $this;
38
    }
39
40
    /**
41
     * @param  \Closure                     $callback
42
     * @return $this|ContentRenderInterface
43
     */
44
    public function after(\Closure $callback): ContentRenderInterface
45
    {
46
        $this->after[] = $callback;
47
48
        return $this;
49
    }
50
51
    /**
52
     * @param  string $body
53
     * @return string
54
     */
55
    protected function fireBefore(string $body): string
56
    {
57
        foreach ($this->before as $before) {
58
            if (is_string($parsed = $before($body))) {
59
                $body = $parsed;
60
            }
61
        }
62
63
        return $body;
64
    }
65
66
    /**
67
     * @param  string $body
68
     * @return string
69
     */
70
    protected function fireAfter(string $body): string
71
    {
72
        foreach ($this->after as $after) {
73
            if (is_string($parsed = $after($body))) {
74
                $body = $parsed;
75
            }
76
        }
77
78
        return $body;
79
    }
80
}
81