ContentCreator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 11 1
A getOptions() 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\ContentType;
11
12
use Jolicht\MarkdownCms\Markdown\MarkdownDocument;
13
14
class ContentCreator
15
{
16
    /**
17
     * Options
18
     *
19
     * @var array
20
     */
21
    private $options;
22
23
    /**
24
     * Constructor
25
     *
26
     * @param array $options
27
     */
28
    public function __construct(array $options)
29
    {
30
        $this->options = $options;
31
    }
32
33
    /**
34
     * Get content type
35
     * @param MarkdownDocument $document
36
     * @return ContentTypeInterface
37
     */
38
    public function __invoke(MarkdownDocument $document) : ContentTypeInterface
39
    {
40
        $options = $this->getOptions();
41
42
        $type = $document->getParam('type', $options['content_type_default']);
43
44
        $class = $options['content_types'][$type]['creator'];
45
46
        $creator = new $class($options['content_types'][$type]['default_template']);
47
        return $creator($document);
48
    }
49
50
    /**
51
     * Get options
52
     *
53
     * @return array
54
     */
55
    public function getOptions() : array
56
    {
57
        return $this->options;
58
    }
59
}