File tree Expand file tree Collapse file tree 7 files changed +76
-18
lines changed
tests/DependencyInjection Expand file tree Collapse file tree 7 files changed +76
-18
lines changed Original file line number Diff line number Diff line change 13
13
"require" : {
14
14
"php" : " ^8.1.0" ,
15
15
"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"
19
20
},
20
21
"require-dev" : {
21
- "laravel/pint" : " ^1.6" ,
22
+ "laravel/pint" : " ^1.6.0 " ,
22
23
"phpstan/phpstan" : " ^1.10.3" ,
23
- "symfony/phpunit-bridge" : " ^6.2"
24
+ "symfony/phpunit-bridge" : " ^6.2.7 "
24
25
},
25
26
"autoload" : {
26
27
"psr-4" : {
Original file line number Diff line number Diff line change
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
+ };
Original file line number Diff line number Diff line change 4
4
5
5
namespace OpenAI \Symfony \DependencyInjection ;
6
6
7
+ use Symfony \Component \Config \Definition \Builder \ArrayNodeDefinition ;
8
+ use Symfony \Component \Config \Definition \Builder \NodeBuilder ;
7
9
use Symfony \Component \Config \Definition \Builder \TreeBuilder ;
8
10
use Symfony \Component \Config \Definition \ConfigurationInterface ;
9
11
10
12
/**
11
- * @author Jérôme Tamarelle <[email protected] >
13
+ * @internal
12
14
*/
13
- class Configuration implements ConfigurationInterface
15
+ final class Configuration implements ConfigurationInterface
14
16
{
17
+ /**
18
+ * {@inheritDoc}
19
+ */
15
20
public function getConfigTreeBuilder (): TreeBuilder
16
21
{
17
22
$ treeBuilder = new TreeBuilder ('openai ' );
18
23
$ rootNode = $ treeBuilder ->getRootNode ();
19
24
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 ();
25
40
26
41
return $ treeBuilder ;
27
42
}
Original file line number Diff line number Diff line change 5
5
namespace OpenAI \Symfony \DependencyInjection ;
6
6
7
7
use OpenAI \Client ;
8
+ use Symfony \Component \Config \Definition \ConfigurationInterface ;
8
9
use Symfony \Component \Config \FileLocator ;
9
10
use Symfony \Component \DependencyInjection \ContainerBuilder ;
10
11
use Symfony \Component \DependencyInjection \Extension \Extension ;
11
12
use Symfony \Component \DependencyInjection \Loader \PhpFileLoader ;
12
13
13
14
/**
14
- * @author Jérôme Tamarelle <[email protected] >
15
+ * @internal
15
16
*/
16
- class OpenAIExtension extends Extension
17
+ final class OpenAIExtension extends Extension
17
18
{
19
+ /**
20
+ * @param array<int, array<int, mixed>> $configs
21
+ */
18
22
public function load (array $ configs , ContainerBuilder $ container ): void
19
23
{
20
24
$ loader = new PhpFileLoader ($ container , new FileLocator (__DIR__ .'/../Resources/config ' ));
21
25
$ loader ->load ('services.php ' );
22
26
23
27
$ configuration = $ this ->getConfiguration ($ configs , $ container );
28
+
29
+ assert ($ configuration instanceof ConfigurationInterface);
30
+
24
31
$ config = $ this ->processConfiguration ($ configuration , $ configs );
25
32
26
33
$ definition = $ container ->getDefinition (Client::class);
Original file line number Diff line number Diff line change 7
7
use Symfony \Component \HttpKernel \Bundle \Bundle ;
8
8
9
9
/**
10
- * @author Jérôme Tamarelle <[email protected] >
10
+ * @internal
11
11
*/
12
- class OpenAIBundle extends Bundle
12
+ final class OpenAIBundle extends Bundle
13
13
{
14
14
}
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace Symfony \Component \DependencyInjection \Loader \Configurator ;
4
6
5
7
use OpenAI ;
8
10
return static function (ContainerConfigurator $ container ) {
9
11
$ container ->services ()
10
12
->set (Client::class)
11
- ->factory ([ OpenAI::class, ' client ' ] )
13
+ ->factory (OpenAI::client (...) )
12
14
->args ([
13
15
abstract_arg ('API Key ' ),
14
16
abstract_arg ('Organisation ' ),
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace OpenAI \Symfony \Tests \DependencyInjection ;
4
6
5
7
use OpenAI \Client ;
6
8
use OpenAI \Symfony \DependencyInjection \OpenAIExtension ;
7
9
use PHPUnit \Framework \TestCase ;
8
10
use Symfony \Component \DependencyInjection \ContainerBuilder ;
9
11
10
- class OpenAIExtensionTest extends TestCase
12
+ final class OpenAIExtensionTest extends TestCase
11
13
{
12
14
public function testService (): void
13
15
{
You can’t perform that action at this time.
0 commit comments