RenderingProcessBuilder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 95.83%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 6
c 6
b 0
f 0
lcom 0
cbo 7
dl 0
loc 41
ccs 23
cts 24
cp 0.9583
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A newInstance() 0 8 1
A newView() 0 12 1
A setTemplate() 0 16 4
1
<?php
2
namespace Bookdown\Bookdown\Process\Rendering;
3
4
use Psr\Log\LoggerInterface;
5
use Aura\Html\HelperLocatorFactory;
6
use Aura\View\View;
7
use Aura\View\ViewFactory;
8
use Bookdown\Bookdown\Config\RootConfig;
9
use Bookdown\Bookdown\Exception;
10
use Bookdown\Bookdown\Fsio;
11
use Bookdown\Bookdown\Process\ProcessBuilderInterface;
12
13
class RenderingProcessBuilder implements ProcessBuilderInterface
14
{
15 3
    public function newInstance(RootConfig $config, LoggerInterface $logger, Fsio $fsio)
16
    {
17 3
        return new RenderingProcess(
18 3
            $logger,
19 3
            $fsio,
20 3
            $this->newView($config)
21 3
        );
22
    }
23
24 3
    protected function newView(RootConfig $config)
25
    {
26 3
        $helpersFactory = new HelperLocatorFactory();
27 3
        $helpers = $helpersFactory->newInstance();
28
29 3
        $viewFactory = new ViewFactory();
30 3
        $view = $viewFactory->newInstance($helpers);
31
32 3
        $this->setTemplate($view, $config);
33
34 3
        return $view;
35
    }
36
37 3
    protected function setTemplate(View $view, RootConfig $config)
38
    {
39 3
        $template = $config->getTemplate();
40 3
        if (! $template) {
41 3
            $template = dirname(dirname(dirname(__DIR__))) . '/templates/main.php';
42 3
        }
43
44 3
        if (! file_exists($template) && ! is_readable($template)) {
45
            throw new Exception("Cannot find template '$template'.");
46
        }
47
48 3
        $registry = $view->getViewRegistry();
49 3
        $registry->set('__BOOKDOWN__', $template);
50
51 3
        $view->setView('__BOOKDOWN__');
52 3
    }
53
}
54