IfAvailableBootstrapFileLoader::execute()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 9.1928
c 0
b 0
f 0
cc 5
nc 5
nop 1
1
<?php
2
/**
3
 * @author stev leibelt <[email protected]>
4
 * @since 2015-05-31 
5
 */
6
7
namespace Net\Bazzline\Component\Locator\Process\Transformer\FileLoader;
8
9
use Net\Bazzline\Component\ProcessPipe\ExecutableException;
10
use Net\Bazzline\Component\ProcessPipe\ExecutableInterface;
11
12
class IfAvailableBootstrapFileLoader implements ExecutableInterface
13
{
14
    /**
15
     * @param array $input
16
     * @return array
17
     * @throws ExecutableException
18
     */
19
    public function execute($input = null)
20
    {
21
        if (!is_array($input)) {
22
            throw new ExecutableException(
23
                'input must be an array'
24
            );
25
        }
26
27
        if (isset($input['bootstrap_file'])) {
28
            if (!is_file($input['bootstrap_file'])) {
29
                throw new ExecutableException(
30
                    'provided bootstrap path "' . $input['bootstrap_file'] . '" must be a valid file'
31
                );
32
            }
33
34
            if (!is_readable($input['bootstrap_file'])) {
35
                throw new ExecutableException(
36
                    'provided bootstrap file "' . $input['bootstrap_file'] . '" must be readable'
37
                );
38
            }
39
40
            require_once $input['bootstrap_file'];
41
        }
42
43
        return $input;
44
    }
45
}