Skip to content

Commit 36763dd

Browse files
committed
refactor: improve container initialization check and enhance DevToolsServiceProvider documentation
Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
1 parent 7709574 commit 36763dd

4 files changed

Lines changed: 55 additions & 9 deletions

File tree

src/Console/DevTools.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function __construct(CommandLoaderInterface $commandLoader)
5858
*/
5959
public static function create(): self
6060
{
61-
if (self::$container === null) {
61+
if (! self::$container instanceof ContainerInterface) {
6262
$serviceProvider = new DevToolsServiceProvider();
6363
self::$container = new Container($serviceProvider->getFactories());
6464
}

src/ServiceProvider/DevToolsServiceProvider.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
<?php
22

3+
declare(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+
319
namespace FastForward\DevTools\ServiceProvider;
420

521
use Interop\Container\ServiceProviderInterface;
@@ -48,6 +64,9 @@
4864

4965
final class DevToolsServiceProvider implements ServiceProviderInterface
5066
{
67+
/**
68+
* @return array
69+
*/
5170
public function getFactories(): array
5271
{
5372
return [
@@ -87,6 +106,9 @@ public function getFactories(): array
87106
];
88107
}
89108

109+
/**
110+
* @return array
111+
*/
90112
public function getExtensions(): array
91113
{
92114
return [];

tests/Composer/Capability/DevToolsCommandProviderTest.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
use Composer\Command\BaseCommand;
2222
use FastForward\DevTools\Composer\Capability\DevToolsCommandProvider;
23-
use FastForward\DevTools\Console\Command\CodeStyleCommand;
2423
use FastForward\DevTools\Console\DevTools;
2524
use PHPUnit\Framework\Attributes\CoversClass;
2625
use PHPUnit\Framework\Attributes\Test;
@@ -31,8 +30,6 @@
3130
use Psr\Container\ContainerInterface;
3231
use ReflectionProperty;
3332
use Symfony\Component\Console\Command\Command;
34-
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
35-
use Symfony\Component\Filesystem\Filesystem;
3633

3734
#[CoversClass(DevToolsCommandProvider::class)]
3835
#[UsesClass(DevTools::class)]
@@ -41,6 +38,7 @@ final class DevToolsCommandProviderTest extends TestCase
4138
use ProphecyTrait;
4239

4340
private ObjectProphecy $container;
41+
4442
private ObjectProphecy $devTools;
4543

4644
private DevToolsCommandProvider $commandProvider;
@@ -57,14 +55,18 @@ protected function setUp(): void
5755
->willReturn($this->devTools->reveal())
5856
->shouldBeCalledOnce();
5957

60-
$this->devTools->all()->willReturn([])->shouldBeCalledOnce();
58+
$this->devTools->all()
59+
->willReturn([])->shouldBeCalledOnce();
6160

6261
$this->commandProvider = new DevToolsCommandProvider();
6362

6463
$property = new ReflectionProperty(DevTools::class, 'container');
6564
$property->setValue(null, $this->container->reveal());
6665
}
6766

67+
/**
68+
* @return void
69+
*/
6870
#[Test]
6971
public function getCommandsWillReturnEmptyArrayWhenNoCommandsAreRegistered(): void
7072
{
@@ -74,16 +76,17 @@ public function getCommandsWillReturnEmptyArrayWhenNoCommandsAreRegistered(): vo
7476
self::assertEmpty($commands);
7577
}
7678

79+
/**
80+
* @return void
81+
*/
7782
#[Test]
7883
public function getCommandsWillReturnRegisteredBaseCommands(): void
7984
{
8085
$composerCommand = $this->prophesize(BaseCommand::class)->reveal();
8186
$symfonyCommand = $this->prophesize(Command::class)->reveal();
8287

83-
$this->devTools->all()->willReturn([
84-
$composerCommand,
85-
$symfonyCommand,
86-
])->shouldBeCalledOnce();
88+
$this->devTools->all()
89+
->willReturn([$composerCommand, $symfonyCommand])->shouldBeCalledOnce();
8790

8891
$commands = $this->commandProvider->getCommands();
8992

tests/ServiceProvider/DevToolsServiceProviderTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33
declare(strict_types=1);
44

55
/**
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+
*
611
* @copyright Copyright (c) 2026 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
712
* @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
817
*/
918

1019
namespace FastForward\DevTools\Tests\ServiceProvider;
@@ -20,23 +29,35 @@ final class DevToolsServiceProviderTest extends TestCase
2029
{
2130
private DevToolsServiceProvider $provider;
2231

32+
/**
33+
* @return void
34+
*/
2335
protected function setUp(): void
2436
{
2537
$this->provider = new DevToolsServiceProvider();
2638
}
2739

40+
/**
41+
* @return void
42+
*/
2843
#[Test]
2944
public function implementsServiceProviderInterface(): void
3045
{
3146
self::assertInstanceOf(ServiceProviderInterface::class, $this->provider);
3247
}
3348

49+
/**
50+
* @return void
51+
*/
3452
#[Test]
3553
public function getExtensionsReturnEmptyArray(): void
3654
{
3755
self::assertEmpty($this->provider->getExtensions());
3856
}
3957

58+
/**
59+
* @return void
60+
*/
4061
#[Test]
4162
public function getFactoriesReturnFactories(): void
4263
{

0 commit comments

Comments
 (0)