Passed
Push — master ( 3ac99b...e2f20d )
by Pol
13:14
created

Plugin::uninstall()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 6
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 8
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace drupol\ComposerPackages;
6
7
use Composer\Composer;
8
use Composer\EventDispatcher\EventSubscriberInterface;
9
use Composer\IO\IOInterface;
10
use Composer\Plugin\PluginInterface;
11
use Composer\Script\Event;
12
use Composer\Script\ScriptEvents;
13
use ReflectionException;
14
15
final class Plugin implements EventSubscriberInterface, PluginInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function activate(Composer $composer, IOInterface $io): void
21
    {
22
    }
23
24
    /**
25
     * @return array<string, string>
26
     */
27
    public static function getSubscribedEvents(): array
28
    {
29
        return [ScriptEvents::POST_AUTOLOAD_DUMP => 'regeneration'];
30 1
    }
31
32 1
    /**
33
     * @param Event $composerEvent
34
     *
35
     * @throws ReflectionException
36
     */
37
    public static function regeneration(Event $composerEvent): void
38
    {
39
        // This is to prevent issue when removing the package with composer.
40 2
        if (false === class_exists(ClassGenerator::class)) {
41
            return;
42
        }
43 2
44
        $composerEvent->getIO()->write('<info>drupol/composer-packages:</info> Regenerating classes...');
45
46
        (new ClassGenerator($composerEvent))->regenerateClasses();
47 2
48
        $composerEvent->getIO()->write('<info>drupol/composer-packages:</info> Done.');
49 2
    }
50
51 2
    public function deactivate(Composer $composer, IOInterface $io)
52 2
    {
53
    }
54
55
    public function uninstall(Composer $composer, IOInterface $io)
56
    {
57
        array_map(
58
            'unlink',
59
            glob(
0 ignored issues
show
Bug introduced by
It seems like glob(sprintf('%s/../build/', __DIR__)) can also be of type false; however, parameter $arr1 of array_map() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

59
            /** @scrutinizer ignore-type */ glob(
Loading history...
60
                sprintf(
61
                    '%s/../build/',
62
                    __DIR__
63
                )
64
            )
65
        );
66
    }
67
}
68