Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
77.78% covered (warning)
77.78%
7 / 9
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
DevToolsCommandProvider
77.78% covered (warning)
77.78%
7 / 9
0.00% covered (danger)
0.00%
0 / 1
4.18
0.00% covered (danger)
0.00%
0 / 1
 getCommands
77.78% covered (warning)
77.78%
7 / 9
0.00% covered (danger)
0.00%
0 / 1
4.18
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\Capability;
21
22use Composer\Plugin\Capability\CommandProvider;
23use FastForward\DevTools\Composer\Command\ProxyCommand;
24use FastForward\DevTools\Console\DevTools;
25
26/**
27 * Provides a registry of custom dev-tools commands mapped for Composer integration.
28 * This capability struct MUST implement the defined `CommandProvider`.
29 */
30 class DevToolsCommandProvider implements CommandProvider
31{
32    private const string COMMAND_NAMESPACE = 'FastForward\\DevTools\\Console\\Command\\';
33
34    /**
35     * {@inheritDoc}
36     */
37    public function getCommands()
38    {
39        $commands = [];
40
41        foreach (DevTools::create()->all() as $command) {
42            if (! str_starts_with($command::class, self::COMMAND_NAMESPACE)) {
43                continue;
44            }
45
46            $id = spl_object_hash($command);
47
48            if (isset($commands[$id])) {
49                continue;
50            }
51
52            $commands[$id] = new ProxyCommand($command);
53        }
54
55        return $commands;
56    }
57}