MarkdownRenderController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 41
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addProcessor() 0 4 1
A renderAction() 0 14 3
1
<?php
2
3
namespace Knp\MegaMAN\Controller;
4
5
use Knp\MegaMAN\Markdown\Processor;
6
use Michelf\MarkdownExtra;
7
use Symfony\Component\HttpFoundation\Response;
8
9
class MarkdownRenderController
10
{
11
    /**
12
     * @var Processor[]
13
     */
14
    private $processors;
15
16
    public function __construct()
17
    {
18
        $this->processors = [];
19
    }
20
21
    /**
22
     * @param Processor $processor
23
     */
24
    public function addProcessor(Processor $processor)
25
    {
26
        $this->processors[] = $processor;
27
    }
28
29
    /**
30
     * @param string      $file
31
     * @param string|null $page
32
     *
33
     * @return Response
34
     */
35
    public function renderAction($file, $page = null)
36
    {
37
        if (null !== $page) {
38
            $file = sprintf('%s/%s', dirname($file), $page);
39
        }
40
41
        $html = MarkdownExtra::defaultTransform(file_get_contents($file));
42
43
        foreach ($this->processors as $processor) {
44
            $html = $processor->process($html);
45
        }
46
47
        return new Response($html);
48
    }
49
}
50