Passed
Push — master ( 1d1b3b...024fd5 )
by Pol
02:36
created

Plugin::regeneration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 1
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 1
    public function activate(Composer $composer, IOInterface $io): void
23
    {
24 1
        $io->write('<info>drupol/composer-packages:</info> Enabled.');
25 1
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 1
    public static function getSubscribedEvents(): array
31
    {
32 1
        return [ScriptEvents::POST_AUTOLOAD_DUMP => 'regeneration'];
33
    }
34
35
    /**
36
     * @param \Composer\Script\Event $composerEvent
37
     *
38
     * @throws \ReflectionException
39
     * @throws \Twig\Error\LoaderError
40
     * @throws \Twig\Error\RuntimeError
41
     * @throws \Twig\Error\SyntaxError
42
     */
43 2
    public static function regeneration(Event $composerEvent): void
44
    {
45 2
        $composerEvent->getIO()->write('<info>drupol/composer-packages:</info> Regenerating classes...');
46
47 2
        (new ClassGenerator($composerEvent))->regenerateClasses();
48
49 2
        $composerEvent->getIO()->write('<info>drupol/composer-packages:</info> Done.');
50 2
    }
51
}
52