Passed
Pull Request — master (#50)
by Chubarov
02:51
created

Composer::bootstrap()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Foundation;
6
7
use RuntimeException;
8
use Composer\Script\Event;
9
10
class Composer
11
{
12
    /**
13
     * Handle post-install event.
14
     *
15
     * @param Event $event
16
     */
17 2 View Code Duplication
    public static function postInstall(Event $event): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
    {
19 2
        $vendor = $event->getComposer()->getConfig()->get('vendor-dir');
20
21
        /** @noinspection PhpIncludeInspection */
22 2
        require_once $vendor.'/autoload.php';
23
24 2
        self::bootstrap($vendor);
25 1
        self::discoverAssets();
26 1
    }
27
28
    /**
29
     * Handle post-update event.
30
     *
31
     * @param Event $event
32
     */
33 1 View Code Duplication
    public static function postUpdate(Event $event): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35 1
        $vendor = $event->getComposer()->getConfig()->get('vendor-dir');
36
37
        /** @noinspection PhpIncludeInspection */
38 1
        require_once $vendor.'/autoload.php';
39
40 1
        self::bootstrap($vendor);
41 1
        self::discoverAssets();
42 1
    }
43
44 3
    private static function bootstrap(string $vendor): void
45
    {
46 3
        $bootstrapFile = $vendor.'/../bootstrap/app.php';
47 3
        if (!file_exists($bootstrapFile)) {
48 1
            throw new RuntimeException('Bootstrap file does not exist.');
49
        }
50
51
        /** @noinspection PhpIncludeInspection */
52 2
        require_once $bootstrapFile;
53 2
    }
54
55 2
    private static function discoverAssets()
56
    {
57
        /** @var Assets $assets */
58 2
        $assets = resolve(Assets::class);
59
60 2
        $assets->discover();
61 2
    }
62
}
63