Passed
Push — master ( 456903...1d1b3b )
by Pol
01:51
created

Plugin   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 55.56%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 33
ccs 5
cts 9
cp 0.5556
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 3 1
A regeneration() 0 7 1
A activate() 0 3 1
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
    public static function regeneration(Event $composerEvent): void
44
    {
45
        $composerEvent->getIO()->write('<info>drupol/composer-packages:</info> Regenerating classes...');
46
47
        (new ClassGenerator($composerEvent))->regenerateClasses();
48
49
        $composerEvent->getIO()->write('<info>drupol/composer-packages:</info> Done.');
50
    }
51
}
52