SaveContentConfigObserver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 59
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __invoke() 0 9 1
A getConfigWriter() 0 4 1
A getTargetPath() 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\Observer;
11
12
use Zend\Config\Writer\PhpArray;
13
14
class SaveContentConfigObserver implements ParsedContentObserverInterface
15
{
16
17
    /**
18
     * Config writer
19
     *
20
     * @var PhpArray
21
     */
22
    private $configWriter;
23
24
    /**
25
     * Target path
26
     *
27
     * @var string
28
     */
29
    private $targetPath;
30
31
    public function __construct(PhpArray $configWriter,string $targetPath)
32
    {
33
        $this->configWriter = $configWriter;
34
        $this->targetPath = $targetPath;
35
    }
36
37
    /**
38
     * Save Content
39
     *
40
     * {@inheritDoc}
41
     * @see \Jolicht\MarkdownCms\Parser\Observer\ParsedContentObserverInterface::__invoke()
42
     */
43
    public function __invoke(array $config)
44
    {
45
        $markdownCmsConfig = [
46
            'markdown_cms' => [
47
                'content' => $config
48
            ]
49
        ];
50
        $this->getConfigWriter()->toFile($this->getTargetPath(), $markdownCmsConfig);
51
    }
52
53
    /**
54
     * Get config writer
55
     *
56
     * @return PhpArray
57
     */
58
    public function getConfigWriter() : PhpArray
59
    {
60
        return $this->configWriter;
61
    }
62
63
    /**
64
     * Get target path
65
     *
66
     * @return string
67
     */
68
    public function getTargetPath() : string
69
    {
70
        return $this->targetPath;
71
    }
72
}