Completed
Push — feature-static-files ( 136c95 )
by Arnaud
05:49
created

StaticLoad   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 47
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 32 3
A init() 0 4 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 Symfony\Component\Finder\Finder;
12
13
/**
14
 * Load static files.
15
 */
16
class StaticLoad extends AbstractStep
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function init($options)
22
    {
23
        if (is_dir($this->builder->getConfig()->getStaticPath())) {
24
            $this->process = true;
25
        }
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function process()
32
    {
33
        call_user_func_array($this->builder->getMessageCb(), ['DATA', 'Loading static files']);
34
35
        $files = Finder::create()
36
            ->files()
37
            ->in($this->builder->getConfig()->getStaticPath())
38
            ->sortByName(true);
39
        $max = count($files);
40
41
        if ($max <= 0) {
42
            $message = 'No files';
43
            call_user_func_array($this->builder->getMessageCb(), ['DATA_PROGRESS', $message]);
44
45
            return;
46
        }
47
48
        $count = 0;
49
50
        /* @var $file \Symfony\Component\Finder\SplFileInfo */
51
        foreach ($files as $file) {
52
            $staticFiles[$count]['path'] = $file->getRelativePathname();
53
            $staticFiles[$count]['date'] = (new \DateTime())->setTimestamp($file->getCTime());
54
            $staticFiles[$count]['updated'] = (new \DateTime())->setTimestamp($file->getMTime());
55
            $staticFiles[$count]['name'] = $file->getBasename();
56
            $staticFiles[$count]['basename'] = $file->getBasename('.'.$file->getExtension());
57
            $staticFiles[$count]['ext'] = $file->getExtension();
58
            $this->builder->setStatic($staticFiles);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $staticFiles seems to be defined later in this foreach loop on line 52. Are you sure it is defined here?
Loading history...
59
            $count++;
60
61
            $message = sprintf('%s', $file->getRelativePathname());
62
            call_user_func_array($this->builder->getMessageCb(), ['DATA_PROGRESS', $message, $count, $max]);
63
        }
64
    }
65
}
66