Completed
Push — code ( eb95c2 )
by Arnaud
02:14
created

PagesGenerate   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 6 2
A process() 0 19 3
1
<?php
2
/*
3
 * Copyright (c) Arnaud Ligny <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Cecil\Step;
10
11
use Cecil\Generator\GeneratorManager;
12
13
/**
14
 * Generates virtual pages.
15
 */
16
class PagesGenerate extends AbstractStep
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function init($options)
22
    {
23
        if (count($this->builder->getConfig()->get('generators')) > 0) {
24
            $this->process = true;
25
        }
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function process()
32
    {
33
        if ($this->process) {
34
            $generatorManager = new GeneratorManager();
35
            $generators = $this->builder->getConfig()->get('generators');
36
            array_walk($generators, function ($generator, $priority) use ($generatorManager) {
37
                if (!class_exists($generator)) {
38
                    $message = sprintf("Unable to load generator '%s'", $generator);
39
                    call_user_func_array($this->builder->getMessageCb(), ['GENERATE_ERROR', $message]);
40
41
                    return;
42
                }
43
                $generatorManager->addGenerator(new $generator($this->builder->getConfig()), $priority);
44
            });
45
            call_user_func_array($this->builder->getMessageCb(), ['GENERATE', 'Generating pages']);
46
            $pages = $generatorManager->process($this->builder->getPages(), $this->builder->getMessageCb());
47
            $this->builder->setPages($pages);
48
        }
49
    }
50
}
51