Passed
Push — main ( 388f81...59708d )
by Sebastian
03:37
created

Util   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 37
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateBootstrapPath() 0 12 4
A bootstrapCmdOption() 0 7 3
1
<?php
2
3
/**
4
 * This file is part of CaptainHook.
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CaptainHook\App\Runner\Bootstrap;
13
14
use CaptainHook\App\Config;
15
use RuntimeException;
16
17
/**
18
 * Bootstrap Util
19
 *
20
 * @package CaptainHook
21
 * @author  Sebastian Feldmann <[email protected]>
22
 * @link    https://github.com/captainhookphp/captainhook
23
 * @since   Class available since Release 5.23.3
24
 */
25
class Util
26
{
27
    /**
28
     * Return the bootstrap file to load (can be empty)
29
     *
30
     * @param  bool                    $isPhar
31
     * @param  \CaptainHook\App\Config $config
32
     * @return string
33
     */
34 23
    public static function validateBootstrapPath(bool $isPhar, Config $config): string
35
    {
36 23
        $bootstrapFile = dirname($config->getPath()) . '/' . $config->getBootstrap();
37 23
        if (!file_exists($bootstrapFile)) {
38
            // since the phar has its own autoloader we don't need to do anything
39
            // if the bootstrap file is not actively set
40 4
            if ($isPhar && empty($config->getBootstrap(''))) {
41 1
                return '';
42
            }
43 3
            throw new RuntimeException('bootstrap file not found');
44
        }
45 19
        return $bootstrapFile;
46
    }
47
48
    /**
49
     * Returns the bootstrap command option (can be empty)
50
     *
51
     * @param bool                    $isPhar
52
     * @param \CaptainHook\App\Config $config
53
     * @return string
54
     */
55 51
    public static function bootstrapCmdOption(bool $isPhar, Config $config): string
56
    {
57
        // nothing to load => no option
58 51
        if ($isPhar && empty($config->getBootstrap(''))) {
59 4
            return '';
60
        }
61 47
        return ' --bootstrap=' . $config->getBootstrap();
62
    }
63
}
64