Plugin::onCreateProject()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 19
ccs 11
cts 11
cp 1
crap 2
rs 9.9332
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antidot\Installer;
6
7
use Antidot\Installer\ApplicationType\ApplicationTypeFactory;
8
use Antidot\Installer\Question\ApplicationTypes;
9
use Antidot\Installer\Question\InstallationPath;
10
use Composer\Composer;
11
use Composer\EventDispatcher\EventSubscriberInterface;
12
use Composer\IO\IOInterface;
13
use Composer\Plugin\PluginInterface;
14
use Composer\Script\Event;
15
use Composer\Script\ScriptEvents;
16
17
use function dirname;
18
19
class Plugin implements PluginInterface, EventSubscriberInterface
20
{
21
    protected Composer $composer;
22
    protected IOInterface $io;
23
    protected InstallationPath $installationPathQuestion;
24
25 2
    public function activate(Composer $composer, IOInterface $io): void
26
    {
27 2
        $this->composer = $composer;
28 2
        $this->io = $io;
29 2
        $this->installationPathQuestion = new InstallationPath($io);
30 2
    }
31
32
33
    /** @return array<string, string> */
34 1
    public static function getSubscribedEvents(): array
35
    {
36
        return [
37 1
            ScriptEvents::POST_CREATE_PROJECT_CMD => 'onCreateProject',
38
        ];
39
    }
40
41 2
    public function onCreateProject(Event $event): void
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

41
    public function onCreateProject(/** @scrutinizer ignore-unused */ Event $event): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
    {
43 2
        $package = $this->composer->getPackage();
44 2
        if ('antidot-fw/skeleton' !== $package->getName()) {
45 1
            return;
46
        }
47
48
        /** @var int $answer */
49 1
        $answer = $this->io->select(ApplicationTypes::QUESTION, ApplicationTypes::OPTIONS, ApplicationTypes::WEB_APP);
50 1
        $installer = ApplicationTypeFactory::createByApplicationTypeName(
51 1
            ApplicationTypes::OPTIONS[$answer],
52 1
            $this->io
53
        );
54
55 1
        $installationPath = $this->installationPathQuestion->ask(
56 1
            dirname($this->composer->getInstallationManager()->getInstallPath($package), 3) . '/'
57
        );
58
59 1
        $installer->install($installationPath);
60 1
    }
61
}
62