Skip to content

Commit a3acc2c

Browse files
committed
chore: minor styling and structure adjustments
1 parent 44d642f commit a3acc2c

File tree

7 files changed

+76
-18
lines changed

7 files changed

+76
-18
lines changed

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
"require": {
1414
"php": "^8.1.0",
1515
"openai-php/client": "^0.3.4",
16-
"symfony/config": "^5.4|^6.0",
17-
"symfony/dependency-injection": "^5.4|^6.0",
18-
"symfony/http-kernel": "^5.4|^6.0"
16+
"rector/rector": "^0.14.8",
17+
"symfony/config": "^5.4.21|^6.2.7",
18+
"symfony/dependency-injection": "^5.4.21|^6.2.7",
19+
"symfony/http-kernel": "^5.4.21|^6.2.7"
1920
},
2021
"require-dev": {
21-
"laravel/pint": "^1.6",
22+
"laravel/pint": "^1.6.0",
2223
"phpstan/phpstan": "^1.10.3",
23-
"symfony/phpunit-bridge": "^6.2"
24+
"symfony/phpunit-bridge": "^6.2.7"
2425
},
2526
"autoload": {
2627
"psr-4": {

rector.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
6+
use Rector\Config\RectorConfig;
7+
use Rector\Set\ValueObject\LevelSetList;
8+
use Rector\Set\ValueObject\SetList;
9+
10+
return static function (RectorConfig $rectorConfig): void {
11+
$rectorConfig->paths([
12+
__DIR__.'/src',
13+
]);
14+
15+
$rectorConfig->skip([
16+
__DIR__.'/src/Contracts/Response.php',
17+
]);
18+
19+
$rectorConfig->rules([
20+
InlineConstructorDefaultToPropertyRector::class,
21+
]);
22+
23+
$rectorConfig->sets([
24+
LevelSetList::UP_TO_PHP_81,
25+
SetList::CODE_QUALITY,
26+
SetList::DEAD_CODE,
27+
SetList::EARLY_RETURN,
28+
SetList::TYPE_DECLARATION,
29+
SetList::PRIVATIZATION,
30+
]);
31+
};

src/DependencyInjection/Configuration.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,39 @@
44

55
namespace OpenAI\Symfony\DependencyInjection;
66

7+
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
8+
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
79
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
810
use Symfony\Component\Config\Definition\ConfigurationInterface;
911

1012
/**
11-
* @author Jérôme Tamarelle <[email protected]>
13+
* @internal
1214
*/
13-
class Configuration implements ConfigurationInterface
15+
final class Configuration implements ConfigurationInterface
1416
{
17+
/**
18+
* {@inheritDoc}
19+
*/
1520
public function getConfigTreeBuilder(): TreeBuilder
1621
{
1722
$treeBuilder = new TreeBuilder('openai');
1823
$rootNode = $treeBuilder->getRootNode();
1924

20-
$rootNode
21-
->children()
22-
->scalarNode('api_key')->defaultValue('%env(OPENAI_API_KEY)%')->end()
23-
->scalarNode('organization')->defaultValue('%env(default::OPENAI_ORGANIZATION)%')->end()
24-
->end();
25+
assert($rootNode instanceof ArrayNodeDefinition);
26+
27+
$children = $rootNode->children();
28+
29+
assert($children instanceof NodeBuilder);
30+
31+
$children = $children->scalarNode('api_key')->defaultValue('%env(OPENAI_API_KEY)%')->end();
32+
33+
assert($children instanceof NodeBuilder);
34+
35+
$children = $children->scalarNode('organization')->defaultValue('%env(default::OPENAI_ORGANIZATION)%')->end();
36+
37+
assert($children instanceof NodeBuilder);
38+
39+
$children->end();
2540

2641
return $treeBuilder;
2742
}

src/DependencyInjection/OpenAIExtension.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,29 @@
55
namespace OpenAI\Symfony\DependencyInjection;
66

77
use OpenAI\Client;
8+
use Symfony\Component\Config\Definition\ConfigurationInterface;
89
use Symfony\Component\Config\FileLocator;
910
use Symfony\Component\DependencyInjection\ContainerBuilder;
1011
use Symfony\Component\DependencyInjection\Extension\Extension;
1112
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
1213

1314
/**
14-
* @author Jérôme Tamarelle <[email protected]>
15+
* @internal
1516
*/
16-
class OpenAIExtension extends Extension
17+
final class OpenAIExtension extends Extension
1718
{
19+
/**
20+
* @param array<int, array<int, mixed>> $configs
21+
*/
1822
public function load(array $configs, ContainerBuilder $container): void
1923
{
2024
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
2125
$loader->load('services.php');
2226

2327
$configuration = $this->getConfiguration($configs, $container);
28+
29+
assert($configuration instanceof ConfigurationInterface);
30+
2431
$config = $this->processConfiguration($configuration, $configs);
2532

2633
$definition = $container->getDefinition(Client::class);

src/OpenAIBundle.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use Symfony\Component\HttpKernel\Bundle\Bundle;
88

99
/**
10-
* @author Jérôme Tamarelle <[email protected]>
10+
* @internal
1111
*/
12-
class OpenAIBundle extends Bundle
12+
final class OpenAIBundle extends Bundle
1313
{
1414
}

src/Resources/config/services.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
46

57
use OpenAI;
@@ -8,7 +10,7 @@
810
return static function (ContainerConfigurator $container) {
911
$container->services()
1012
->set(Client::class)
11-
->factory([OpenAI::class, 'client'])
13+
->factory(OpenAI::client(...))
1214
->args([
1315
abstract_arg('API Key'),
1416
abstract_arg('Organisation'),

tests/DependencyInjection/OpenAIExtensionTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace OpenAI\Symfony\Tests\DependencyInjection;
46

57
use OpenAI\Client;
68
use OpenAI\Symfony\DependencyInjection\OpenAIExtension;
79
use PHPUnit\Framework\TestCase;
810
use Symfony\Component\DependencyInjection\ContainerBuilder;
911

10-
class OpenAIExtensionTest extends TestCase
12+
final class OpenAIExtensionTest extends TestCase
1113
{
1214
public function testService(): void
1315
{

0 commit comments

Comments
 (0)