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

ContentLoad   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 8 2
A process() 0 16 2
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\Exception\Exception;
12
use Symfony\Component\Finder\Finder;
13
14
/**
15
 * Locates content.
16
 */
17
class ContentLoad extends AbstractStep
18
{
19
    /**
20
     * {@inheritdoc}
21
     *
22
     * @throws Exception
23
     */
24
    public function init($options)
25
    {
26
        if (!is_dir($this->builder->getConfig()->getContentPath())) {
27
            throw new Exception(sprintf('%s not found!', $this->builder->getConfig()->getContentPath()));
28
        }
29
30
        $this->process = true;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function process()
37
    {
38
        call_user_func_array($this->builder->getMessageCb(), ['LOCATE', 'Loading content']);
39
40
        $content = Finder::create()
41
            ->files()
42
            ->in($this->builder->getConfig()->getContentPath())
43
            ->name('/\.('.implode('|', $this->builder->getConfig()->get('content.ext')).')$/');
44
        if (!$content instanceof Finder) {
45
            throw new Exception(sprintf("'%s->%s()' result must be an instance of 'Finder'.", __CLASS__, __FUNCTION__));
46
        }
47
        $count = $content->count();
48
        call_user_func_array($this->builder->getMessageCb(), ['LOCATE_PROGRESS', 'Start locating', 0, $count]);
49
        $this->builder->setContent($content);
50
        call_user_func_array($this->builder->getMessageCb(), ['LOCATE_PROGRESS', 'Files loaded', $count, $count]);
51
    }
52
}
53