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
|
|||
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 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.