Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
88.89% |
8 / 9 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| DevTools | |
88.89% |
8 / 9 |
|
75.00% |
3 / 4 |
5.03 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getHelp | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| create | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getContainer | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(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 | |
| 20 | namespace FastForward\DevTools\Console; |
| 21 | |
| 22 | use Override; |
| 23 | use FastForward\DevTools\ServiceProvider\DevToolsServiceProvider; |
| 24 | use DI\Container; |
| 25 | use Psr\Container\ContainerInterface; |
| 26 | use Symfony\Component\Console\Application; |
| 27 | use Symfony\Component\Console\CommandLoader\CommandLoaderInterface; |
| 28 | |
| 29 | /** |
| 30 | * Wraps the fast-forward console tooling suite conceptually as an isolated application instance. |
| 31 | * Extending the base application, it MUST provide default command injections safely. |
| 32 | */ |
| 33 | class DevTools extends Application |
| 34 | { |
| 35 | private const string LOGO = <<<'LOGO' |
| 36 | ____ _____ _ |
| 37 | | _ \ _____ _|_ _|__ ___ | |___ |
| 38 | | | | |/ _ \ \ / / | |/ _ \ / _ \| / __| |
| 39 | | |_| | __/\ V / | | (_) | (_) | \__ \ |
| 40 | |____/ \___| \_/ |_|\___/ \___/|_|___/ |
| 41 | LOGO; |
| 42 | |
| 43 | /** |
| 44 | * @var ContainerInterface holds the static container instance for global access within the DevTools context |
| 45 | */ |
| 46 | private static ?ContainerInterface $container = null; |
| 47 | |
| 48 | /** |
| 49 | * Initializes the DevTools global context and dependency graph. |
| 50 | * |
| 51 | * The method MUST define default configurations and MAY accept an explicit command provider. |
| 52 | * It SHALL instruct the runner to treat the `standards` command generically as its default endpoint. |
| 53 | * |
| 54 | * @param CommandLoaderInterface $commandLoader the command loader responsible for providing command instances |
| 55 | */ |
| 56 | public function __construct(CommandLoaderInterface $commandLoader) |
| 57 | { |
| 58 | parent::__construct('Fast Forward Dev Tools'); |
| 59 | |
| 60 | $this->setDefaultCommand('standards'); |
| 61 | $this->setCommandLoader($commandLoader); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Gets the help message for the DevTools application, including the ASCII logo. |
| 66 | * |
| 67 | * @return string |
| 68 | */ |
| 69 | #[Override] |
| 70 | public function getHelp(): string |
| 71 | { |
| 72 | return self::LOGO . "\n\n" . parent::getHelp(); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Create DevTools instance from container. |
| 77 | * |
| 78 | * @return DevTools |
| 79 | */ |
| 80 | public static function create(): self |
| 81 | { |
| 82 | return self::getContainer()->get(self::class); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Retrieves the shared DevTools service container. |
| 87 | */ |
| 88 | public static function getContainer(): ContainerInterface |
| 89 | { |
| 90 | if (! self::$container instanceof ContainerInterface) { |
| 91 | $serviceProvider = new DevToolsServiceProvider(); |
| 92 | self::$container = new Container($serviceProvider->getFactories()); |
| 93 | } |
| 94 | |
| 95 | return self::$container; |
| 96 | } |
| 97 | } |