Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Plugin
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
4 / 4
5
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
 activate
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 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 * This file is part of fast-forward/dev-tools.
7 *
8 * This source file is subject to the license bundled
9 * with this source code in the file LICENSE.
10 *
11 * @copyright Copyright (c) 2026 Felipe SayĆ£o Lobato Abreu <github@mentordosnerds.com>
12 * @license   https://opensource.org/licenses/MIT MIT License
13 *
14 * @see       https://github.com/php-fast-forward/dev-tools
15 * @see       https://github.com/php-fast-forward
16 * @see       https://datatracker.ietf.org/doc/html/rfc2119
17 */
18
19namespace FastForward\DevTools\Composer;
20
21use Composer\Composer;
22use Composer\IO\IOInterface;
23use Composer\Plugin\Capability\CommandProvider;
24use Composer\Plugin\Capable;
25use Composer\Plugin\PluginInterface;
26use FastForward\DevTools\Composer\Capability\DevToolsCommandProvider;
27
28/**
29 * Implements the lifecycle of the Composer dev-tools extension framework.
30 * This plugin class MUST initialize and coordinate custom script registrations securely.
31 */
32final class Plugin implements Capable, PluginInterface
33{
34    /**
35     * Resolves the implemented Composer capabilities structure.
36     *
37     * This method MUST map the primary capability handlers to custom implementations.
38     * It SHALL describe how tools seamlessly integrate into the execution layer.
39     *
40     * @return array<string, string> the capability mapping configurations
41     */
42    public function getCapabilities(): array
43    {
44        return [
45            CommandProvider::class => DevToolsCommandProvider::class,
46        ];
47    }
48
49    /**
50     * Handles activation lifecycle events for the Composer session.
51     *
52     * The method MUST ensure the `dev-tools` script capability exists inside `composer.json` extras.
53     * It SHOULD append it if currently missing.
54     *
55     * @param Composer $composer the primary package configuration instance over Composer
56     * @param IOInterface $io interactive communication channels
57     *
58     * @return void
59     */
60    public function activate(Composer $composer, IOInterface $io): void
61    {
62        // Add dev-tools script to composer.json if not already present
63        $extra = $composer->getPackage()
64            ->getExtra() ?? [];
65
66        if (! isset($extra['scripts']['dev-tools'])) {
67            $extra['scripts']['dev-tools'] = 'dev-tools';
68            $composer->getPackage()
69                ->setExtra($extra);
70        }
71    }
72
73    /**
74     * Cleans up operations during Composer plugin deactivation events.
75     *
76     * This method MUST implement the standard Composer lifecycle correctly, even if vacant.
77     *
78     * @param Composer $composer the primary metadata controller object
79     * @param IOInterface $io defined interactions proxy
80     *
81     * @return void
82     */
83    public function deactivate(Composer $composer, IOInterface $io): void
84    {
85        // No deactivation logic needed for this plugin
86    }
87
88    /**
89     * Handles final uninstallation processes logically.
90     *
91     * This method MUST manage cleanup duties per Composer constraints, even if empty.
92     *
93     * @param Composer $composer system package registry utility
94     * @param IOInterface $io execution runtime outputs and inputs proxy interface
95     *
96     * @return void
97     */
98    public function uninstall(Composer $composer, IOInterface $io): void
99    {
100        // No uninstall logic needed for this plugin
101    }
102}