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

PagesCreate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
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\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