ParseContentExecutor   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 64
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 7 2
A getContentParser() 0 4 1
A getObservers() 0 4 1
A addObserver() 0 4 1
1
<?php
2
/**
3
 * Lichtenwallner  (https://lichtenwallner.at)
4
 *
5
 * @see https://github.com/jolicht/markdown-cms for the canonical source repository
6
 * @license https://github.com/jolicht/markdown-cms/blob/master/LICENSE MIT
7
 * @copyright Copyright (c) Johannes Lichtenwallner
8
 */
9
declare(strict_types = 1);
10
namespace Jolicht\MarkdownCms\Parser;
11
12
use Jolicht\MarkdownCms\Parser\Observer\ParsedContentObserverInterface;
13
14
class ParseContentExecutor
15
{
16
    /**
17
     * Content parser
18
     *
19
     * @var ContentParser
20
     */
21
    private $contentParser;
22
23
    /**
24
     * Observers
25
     *
26
     * @var array
27
     */
28
    private $observers = [];
29
30
    /**
31
     * Constructor
32
     *
33
     * @param ContentParser $contentParser
34
     */
35
    public function __construct(ContentParser $contentParser)
36
    {
37
        $this->contentParser = $contentParser;
38
    }
39
40
    public function __invoke()
41
    {
42
        $config = ($this->getContentParser())();
43
        foreach ($this->getObservers() as $observer) {
44
            $observer($config);
45
        }
46
    }
47
48
    /**
49
     * Get content parser
50
     *
51
     * @return ContentParser
52
     */
53
    public function getContentParser() : ContentParser
54
    {
55
        return $this->contentParser;
56
    }
57
58
    /**
59
     * Get observers
60
     *
61
     * @return array
62
     */
63
    public function getObservers() : array
64
    {
65
        return $this->observers;
66
    }
67
68
    /**
69
     * Add observer
70
     *
71
     * @param ParsedContentObserverInterface $observer
72
     */
73
    public function addObserver(ParsedContentObserverInterface $observer)
74
    {
75
        $this->observers[] = $observer;
76
    }
77
}