Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
Plugin
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
6 / 6
6
100.00% covered (success)
100.00%
1 / 1
 getCapabilities
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getSubscribedEvents
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 runSyncCommand
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 activate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 deactivate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 uninstall
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * Fast Forward Development Tools for PHP projects.
7 *
8 * This file is part of fast-forward/dev-tools project.
9 *
10 * @author   Felipe SayĆ£o Lobato Abreu <github@mentordosnerds.com>
11 * @license  https://opensource.org/licenses/MIT MIT License
12 *
13 * @see      https://github.com/php-fast-forward/
14 * @see      https://github.com/php-fast-forward/dev-tools
15 * @see      https://github.com/php-fast-forward/dev-tools/issues
16 * @see      https://php-fast-forward.github.io/dev-tools/
17 * @see      https://datatracker.ietf.org/doc/html/rfc2119
18 */
19
20namespace FastForward\DevTools\Composer;
21
22use Composer\Composer;
23use Composer\EventDispatcher\EventSubscriberInterface;
24use Composer\Script\Event;
25use Composer\IO\IOInterface;
26use Composer\Plugin\Capability\CommandProvider;
27use Composer\Plugin\Capable;
28use Composer\Plugin\PluginInterface;
29use Composer\Script\ScriptEvents;
30use FastForward\DevTools\Composer\Capability\DevToolsCommandProvider;
31
32/**
33 * Implements the lifecycle of the Composer dev-tools extension framework.
34 * This plugin class MUST initialize and coordinate custom script registrations securely.
35 */
36 class Plugin implements Capable, EventSubscriberInterface, PluginInterface
37{
38    /**
39     * Resolves the implemented Composer capabilities structure.
40     *
41     * This method MUST map the primary capability handlers to custom implementations.
42     * It SHALL describe how tools seamlessly integrate into the execution layer.
43     *
44     * @return array<string, string> the capability mapping configurations
45     */
46    public function getCapabilities(): array
47    {
48        return [
49            CommandProvider::class => DevToolsCommandProvider::class,
50        ];
51    }
52
53    /**
54     * Retrieves the comprehensive map of events this listener SHALL handle.
55     *
56     * This method MUST define the lifecycle triggers for script installation and
57     * synchronization during Composer package operations.
58     *
59     * @return array<string, string> the event mapping registry
60     */
61    public static function getSubscribedEvents(): array
62    {
63        return [
64            ScriptEvents::POST_INSTALL_CMD => 'runSyncCommand',
65            ScriptEvents::POST_UPDATE_CMD => 'runSyncCommand',
66        ];
67    }
68
69    /**
70     * Handles the automated script installation.
71     *
72     * This method MUST execute the `dev-tools:sync` command after relevant Composer operations to ensure
73     * the development tools are correctly synchronized with the current project state.
74     *
75     * @param Event $event the Composer script event context
76     *
77     * @return void
78     */
79    public function runSyncCommand(Event $event): void
80    {
81        $event->getComposer()
82            ->getLoop()
83            ->getProcessExecutor()
84            ->execute('vendor/bin/dev-tools dev-tools:sync');
85    }
86
87    /**
88     * Handles activation lifecycle events for the Composer session.
89     *
90     * This method MUST adhere to the standard Composer plugin activation protocol, even if no specific logic is required.
91     *
92     * @param Composer $composer the primary package configuration instance over Composer
93     * @param IOInterface $io interactive communication channels
94     *
95     * @return void
96     */
97    public function activate(Composer $composer, IOInterface $io): void
98    {
99        // No activation logic needed for this plugin
100    }
101
102    /**
103     * Cleans up operations during Composer plugin deactivation events.
104     *
105     * This method MUST implement the standard Composer lifecycle correctly, even if vacant.
106     *
107     * @param Composer $composer the primary metadata controller object
108     * @param IOInterface $io defined interactions proxy
109     *
110     * @return void
111     */
112    public function deactivate(Composer $composer, IOInterface $io): void
113    {
114        // No deactivation logic needed for this plugin
115    }
116
117    /**
118     * Handles final uninstallation processes logically.
119     *
120     * This method MUST manage cleanup duties per Composer constraints, even if empty.
121     *
122     * @param Composer $composer system package registry utility
123     * @param IOInterface $io execution runtime outputs and inputs proxy interface
124     *
125     * @return void
126     */
127    public function uninstall(Composer $composer, IOInterface $io): void
128    {
129        // No uninstall logic needed for this plugin
130    }
131}