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

PagesCreate::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 3
nc 3
nop 0
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 process()
23
    {
24
        $this->builder->setPages(new PagesCollection());
25
        if (count($this->builder->getContent()) <= 0) {
26
            return;
27
        }
28
        call_user_func_array($this->builder->getMessageCb(), ['CREATE', 'Creating pages']);
29
        $max = count($this->builder->getContent());
30
        $count = 0;
31
        /* @var $file \Symfony\Component\Finder\SplFileInfo */
32
        foreach ($this->builder->getContent() as $file) {
33
            $count++;
34
            /* @var $page Page */
35
            $page = (new Page($file))->parse();
36
            $this->builder->getPages()->add($page);
37
            $message = $page->getPathname();
38
            call_user_func_array($this->builder->getMessageCb(), ['CREATE_PROGRESS', $message, $count, $max]);
39
        }
40
    }
41
}
42