Completed
Push — master ( 1e5783...b9ed2d )
by Sebastian
02:56
created

Bootstrapper::run()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 8.8571
cc 5
eloc 7
nc 6
nop 1
crap 5
1
<?php
2
namespace phpbu\App\Configuration;
3
4
use phpbu\App\Configuration;
5
use phpbu\App\Exception;
6
7
/**
8
 * Bootstrapper
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 5.0.8
17
 */
18
class Bootstrapper
19
{
20
    /**
21
     * Path to bootstrap filename.
22
     *
23
     * @var string
24
     */
25
    private $file;
26
27
    /**
28
     * Bootstrapper constructor.
29
     *
30
     * @param string $pathToFile
31
     */
32 6
    public function __construct(string $pathToFile = '')
33
    {
34 6
        $this->file = $pathToFile;
35 6
    }
36
37
    /**
38
     * Execute bootstrap runner.
39
     *
40
     * @param  \phpbu\App\Configuration $configuration
41
     * @throws \phpbu\App\Exception
42
     */
43 4
    public function run(Configuration $configuration)
44
    {
45 4
        $filename = !empty($this->file) ? $this->file : $configuration->getBootstrap();
46
47 4
        if (!empty($filename)) {
48 4
            $pathToFile = stream_resolve_include_path($filename);
49 4
            if (!$pathToFile || !is_readable($pathToFile)) {
50 1
                throw new Exception(sprintf('Cannot open bootstrap file "%s".' . PHP_EOL, $filename));
51
            }
52 3
            require $pathToFile;
53
        }
54 3
    }
55
}
56