Passed
Push — master ( c5b65b...e4c895 )
by Pol
02:27
created

Plugin::activate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 2
ccs 0
cts 1
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
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 \Composer\Script\Event $composerEvent
36
     *
37
     * @throws \ReflectionException
38
     * @throws \Twig\Error\LoaderError
39
     * @throws \Twig\Error\RuntimeError
40
     * @throws \Twig\Error\SyntaxError
41
     */
42 2
    public static function regeneration(Event $composerEvent): void
43
    {
44 2
        $composerEvent->getIO()->write('<info>drupol/composer-packages:</info> Regenerating classes...');
45
46 2
        (new ClassGenerator($composerEvent))->regenerateClasses();
47
48 2
        $composerEvent->getIO()->write('<info>drupol/composer-packages:</info> Done.');
49 2
    }
50
}
51