FrontMatterFilter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
/*
4
 * This is part of the webuni/front-matter package.
5
 *
6
 * (c) Martin Hasoň <[email protected]>
7
 * (c) Webuni s.r.o. <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Webuni\FrontMatter\Haml;
14
15
use MtHaml\Filter\FilterInterface;
16
use MtHaml\Node\Filter;
17
use MtHaml\NodeVisitor\RendererAbstract;
18
use Webuni\FrontMatter\Document;
19
use Webuni\FrontMatter\FrontMatterInterface;
20
21
class FrontMatterFilter implements FilterInterface
22
{
23
    /** @var FrontMatterInterface */
24
    private $parser;
25
26
    /** @var FilterInterface */
27
    private $filter;
28
29
    public function __construct(FrontMatterInterface $parser, FilterInterface $filter)
30
    {
31
        $this->parser = $parser;
32
        $this->filter = $filter;
33
    }
34
35
    /**
36
     * @param array<string, mixed> $options
37
     */
38
    public function isOptimizable(RendererAbstract $renderer, Filter $node, $options): bool
39
    {
40
        return $this->filter->isOptimizable($renderer, $node, $options);
41
    }
42
43
    /**
44
     * @param array<string, mixed> $options
45
     */
46
    public function optimize(RendererAbstract $renderer, Filter $node, $options): string
47
    {
48
        return $this->filter->optimize($renderer, $node, $options);
49
    }
50
51
    /**
52
     * @param string $content
53
     * @param array<mixed, mixed> $context
54
     * @param array<string, mixed> $options
55
     */
56
    public function filter($content, array $context, $options): Document
57
    {
58
        $document = $this->parser->parse($content);
59
        $document->setContent($this->filter->filter($document, $context, $options));
60
61
        return $document;
62
    }
63
}
64