Completed
Pull Request — master (#50)
by Vladimir
04:58 queued 02:00
created

Composer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 37.74 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 20
loc 53
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A postInstall() 10 10 1
A postUpdate() 10 10 1
A bootstrap() 0 10 2
A discoverAssets() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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