Completed
Push — master ( 5d3bf9...5839aa )
by Sebastian
03:18
created

Bootstrap::handleBootstrap()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 5
cts 5
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 3
nop 1
crap 4
1
<?php
2
namespace phpbu\App\Runner;
3
4
use phpbu\App\Configuration;
5
use phpbu\App\Exception;
6
7
/**
8
 * Bootstrap Runner
9
 *
10
 * @package    phpbu
11
 * @subpackage app
12
 * @author     Sebastian Feldmann <[email protected]>
13
 * @copyright  Sebastian Feldmann <[email protected]>
14
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
15
 * @link       http://phpbu.de/
16
 * @since      Class available since Release 3.0.0
17
 */
18
class Bootstrap extends Abstraction
19
{
20
    /**
21
     * Execute bootstrap runner.
22
     *
23
     * @param  \phpbu\App\Configuration $configuration
24
     * @throws \phpbu\App\Exception
25
     */
26 4
    public function run(Configuration $configuration)
27
    {
28 4
        $this->handleBootstrap($configuration);
29 4
    }
30 4
31 3
    /**
32
     * Handles the bootstrap file inclusion.
33
     *
34
     * @param  \phpbu\App\Configuration $configuration
35
     * @throws \phpbu\App\Exception
36
     */
37
    protected function handleBootstrap(Configuration $configuration)
38 4
    {
39
        $filename = $configuration->getBootstrap();
40
41 4
        if (!empty($filename)) {
42 1
            $pathToFile = stream_resolve_include_path($filename);
43 4
            if (!$pathToFile || !is_readable($pathToFile)) {
44 4
                throw new Exception(sprintf('Cannot open bootstrap file "%s".' . PHP_EOL, $filename));
45
            }
46
            require $pathToFile;
47
        }
48
    }
49
}
50