Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
DevTools
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 create
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getContainer
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 getDefaultCommands
100.00% covered (success)
100.00%
2 / 2
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\Console;
21
22use FastForward\DevTools\ServiceProvider\DevToolsServiceProvider;
23use Override;
24use Composer\Console\Application as ComposerApplication;
25use DI\Container;
26use Psr\Container\ContainerInterface;
27use ReflectionMethod;
28use Symfony\Component\Console\Application;
29use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
30
31/**
32 * Wraps the fast-forward console tooling suite conceptually as an isolated application instance.
33 * Extending the base application, it MUST provide default command injections safely.
34 */
35 class DevTools extends ComposerApplication
36{
37    /**
38     * @var ContainerInterface holds the static container instance for global access within the DevTools context
39     */
40    private static ?ContainerInterface $container = null;
41
42    /**
43     * Initializes the DevTools global context and dependency graph.
44     *
45     * The method MUST define default configurations and MAY accept an explicit command provider.
46     * It SHALL instruct the runner to treat the `standards` command generically as its default endpoint.
47     *
48     * @param CommandLoaderInterface $commandLoader the command loader responsible for providing command instances
49     */
50    public function __construct(CommandLoaderInterface $commandLoader)
51    {
52        parent::__construct('Fast Forward Dev Tools');
53
54        $this->setDefaultCommand('standards');
55        $this->setCommandLoader($commandLoader);
56    }
57
58    /**
59     * Create DevTools instance from container.
60     *
61     * @return DevTools
62     */
63    public static function create(): self
64    {
65        return self::getContainer()->get(self::class);
66    }
67
68    /**
69     * Retrieves the shared DevTools service container.
70     */
71    public static function getContainer(): ContainerInterface
72    {
73        if (! self::$container instanceof ContainerInterface) {
74            $serviceProvider = new DevToolsServiceProvider();
75            self::$container = new Container($serviceProvider->getFactories());
76        }
77
78        return self::$container;
79    }
80
81    /**
82     * Retrieves the default set of commands provided by the Symfony Application.
83     *
84     * The method SHOULD NOT add composer-specific commands to the list,
85     * as they are handled separately by composer when loaded as a plugin.
86     *
87     * @return array
88     */
89    #[Override]
90    protected function getDefaultCommands(): array
91    {
92        $reflectionMethod = new ReflectionMethod(Application::class, __FUNCTION__);
93
94        return $reflectionMethod->invoke($this);
95    }
96}