ProcessorBuilder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 4
c 4
b 0
f 2
lcom 1
cbo 2
dl 0
loc 45
ccs 26
cts 26
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A newProcessor() 0 14 1
A newProcess() 0 18 2
1
<?php
2
namespace Bookdown\Bookdown\Service;
3
4
use Psr\Log\LoggerInterface;
5
use Bookdown\Bookdown\Config\RootConfig;
6
use Bookdown\Bookdown\Exception;
7
use Bookdown\Bookdown\Fsio;
8
9
class ProcessorBuilder
10
{
11
    protected $logger;
12
    protected $fsio;
13
14 21
    public function __construct(LoggerInterface $logger, Fsio $fsio)
15
    {
16 21
        $this->logger = $logger;
17 21
        $this->fsio = $fsio;
18 21
    }
19
20 2
    public function newProcessor(RootConfig $config)
21
    {
22 2
        return new Processor(
23 2
            $this->logger,
24
            array(
25 2
                $this->newProcess($config, 'Conversion'),
26 2
                $this->newProcess($config, 'Copyright'),
27 2
                $this->newProcess($config, 'Headings'),
28 2
                $this->newProcess($config, 'CopyImage'),
29 2
                $this->newProcess($config, 'Toc'),
30 2
                $this->newProcess($config, 'Rendering'),
31
            )
32 2
        );
33
    }
34
35 18
    public function newProcess(RootConfig $config, $name)
36
    {
37 18
        $method = "get{$name}Process";
38 18
        $class = $config->$method();
39
40 18
        $implemented = is_subclass_of(
41 18
            $class,
42
            'Bookdown\Bookdown\Process\ProcessBuilderInterface'
43 18
        );
44 18
        if (! $implemented) {
45 1
            throw new Exception(
46 1
                "'{$class}' does not implement ProcessBuilderInterface"
47 1
            );
48
        }
49
50 17
        $builder = new $class();
51 17
        return $builder->newInstance($config, $this->logger, $this->fsio);
52
    }
53
}
54