Passed
Push — master ( 12d4ac...c8ed08 )
by Pol
02:10
created

Plugin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 3 1
A activate() 0 2 1
A regeneration() 0 12 2
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
14
/**
15
 * Class Plugin.
16
 */
17
final class Plugin implements EventSubscriberInterface, PluginInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function activate(Composer $composer, IOInterface $io): void
23
    {
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 1
    public static function getSubscribedEvents(): array
30
    {
31 1
        return [ScriptEvents::POST_AUTOLOAD_DUMP => 'regeneration'];
32
    }
33
34
    /**
35
     * @param Event $composerEvent
36
     *
37
     * @throws \ReflectionException
38
     */
39 2
    public static function regeneration(Event $composerEvent): void
40
    {
41
        // This is to prevent issue when removing the package with composer.
42 2
        if (false === \class_exists(ClassGenerator::class)) {
43
            return;
44
        }
45
46 2
        $composerEvent->getIO()->write('<info>drupol/composer-packages:</info> Regenerating classes...');
47
48 2
        (new ClassGenerator($composerEvent))->regenerateClasses();
49
50 2
        $composerEvent->getIO()->write('<info>drupol/composer-packages:</info> Done.');
51 2
    }
52
}
53