Passed
Push — fix/no-content ( dd2e1d )
by Arnaud
05:13
created

PagesCreate::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
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\Collection\Page\Collection as PagesCollection;
12
use Cecil\Collection\Page\Page;
13
14
/**
15
 * Create Pages collection from content iterator.
16
 */
17
class PagesCreate extends AbstractStep
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function init($options)
23
    {
24
        /** @var \Cecil\Builder $builder */
25
        $this->builder->setPages(new PagesCollection('all-pages'));
26
27
        if (is_dir($this->builder->getConfig()->getContentPath())) {
28
            $this->process = true;
29
        }
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function process()
36
    {
37
        if (count($this->builder->getContent()) <= 0) {
38
            return;
39
        }
40
        call_user_func_array($this->builder->getMessageCb(), ['CREATE', 'Creating pages']);
41
        $max = count($this->builder->getContent());
42
        $count = 0;
43
        /* @var $file \Symfony\Component\Finder\SplFileInfo */
44
        foreach ($this->builder->getContent() as $file) {
45
            $count++;
46
            /* @var $page Page */
47
            $page = new Page(Page::createId($file));
48
            $page->setFile($file)->parse();
49
            $this->builder->getPages()->add($page);
50
            $message = $page->getId();
51
            call_user_func_array($this->builder->getMessageCb(), ['CREATE_PROGRESS', $message, $count, $max]);
52
        }
53
    }
54
}
55