Completed
Pull Request — master (#7)
by
unknown
14:27
created

Plugin::getCapabilities()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 1
cts 1
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\Capable;
11
use Composer\Plugin\PluginInterface;
12
use Composer\Script\Event;
13
use Composer\Script\ScriptEvents;
14
15
/**
16
 * Class Plugin.
17
 */
18
final class Plugin implements Capable, EventSubscriberInterface, PluginInterface
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function activate(Composer $composer, IOInterface $io): void
24
    {
25
    }
26
27
    /**
28
     * @return array
29 1
     */
30
    public function getCapabilities(): array
31 1
    {
32
        return [
33
            \Composer\Plugin\Capability\CommandProvider::class => CommandProvider::class,
34
        ];
35
    }
36
37
    /**
38
     * {@inheritdoc}
39 2
     */
40
    public static function getSubscribedEvents(): array
41
    {
42 2
        return [ScriptEvents::POST_AUTOLOAD_DUMP => 'regeneration'];
43
    }
44
45
    /**
46 2
     * @param Event $composerEvent
47
     *
48 2
     * @throws \ReflectionException
49
     */
50 2
    public static function regeneration(Event $composerEvent): void
51 2
    {
52
        // This is to prevent issue when removing the package with composer.
53
        if (false === class_exists(ClassGenerator::class)) {
54
            return;
55
        }
56
57
        $composerEvent->getIO()->write('<info>drupol/composer-packages:</info> Regenerating classes...');
58
59
        (new ClassGenerator($composerEvent))->regenerateClasses();
60
61
        $composerEvent->getIO()->write('<info>drupol/composer-packages:</info> Done.');
62
    }
63
}
64