diff --git a/src/Capacity/All.php b/src/Capacity/All.php index 57881e1..d1fd509 100644 --- a/src/Capacity/All.php +++ b/src/Capacity/All.php @@ -11,16 +11,13 @@ use function Kiboko\Component\SatelliteToolbox\Configuration\compileValueWhenExpression; -final class All implements CapacityInterface +final readonly class All implements CapacityInterface { - public function __construct(private readonly ExpressionLanguage $interpreter) {} + public function __construct(private ExpressionLanguage $interpreter) {} public function applies(array $config): bool { - $endpoints = array_merge( - Sylius\Validator\ExtractorConfigurationValidator::ADMIN_VALID_TYPES, - Sylius\Validator\ExtractorConfigurationValidator::SHOP_VALID_TYPES, - ); + $endpoints = [...Sylius\Validator\ExtractorConfigurationValidator::ADMIN_VALID_TYPES, ...Sylius\Validator\ExtractorConfigurationValidator::SHOP_VALID_TYPES]; return isset($config['type']) && \array_key_exists($config['type'], $endpoints) diff --git a/src/Capacity/Create.php b/src/Capacity/Create.php index d3b314b..0626939 100644 --- a/src/Capacity/Create.php +++ b/src/Capacity/Create.php @@ -13,10 +13,7 @@ final class Create implements CapacityInterface { public function applies(array $config): bool { - $endpoints = array_merge( - Sylius\Validator\ExtractorConfigurationValidator::ADMIN_VALID_TYPES, - Sylius\Validator\ExtractorConfigurationValidator::SHOP_VALID_TYPES, - ); + $endpoints = [...Sylius\Validator\ExtractorConfigurationValidator::ADMIN_VALID_TYPES, ...Sylius\Validator\ExtractorConfigurationValidator::SHOP_VALID_TYPES]; return isset($config['type']) && \array_key_exists($config['type'], $endpoints) diff --git a/src/Capacity/ListPerPage.php b/src/Capacity/ListPerPage.php index 3ab8dc4..ec13d11 100644 --- a/src/Capacity/ListPerPage.php +++ b/src/Capacity/ListPerPage.php @@ -11,16 +11,13 @@ use function Kiboko\Component\SatelliteToolbox\Configuration\compileValue; -final class ListPerPage implements CapacityInterface +final readonly class ListPerPage implements CapacityInterface { - public function __construct(private readonly ExpressionLanguage $interpreter) {} + public function __construct(private ExpressionLanguage $interpreter) {} public function applies(array $config): bool { - $endpoints = array_merge( - Sylius\Validator\ExtractorConfigurationValidator::ADMIN_VALID_TYPES, - Sylius\Validator\ExtractorConfigurationValidator::SHOP_VALID_TYPES, - ); + $endpoints = [...Sylius\Validator\ExtractorConfigurationValidator::ADMIN_VALID_TYPES, ...Sylius\Validator\ExtractorConfigurationValidator::SHOP_VALID_TYPES]; return isset($config['type']) && \array_key_exists($config['type'], $endpoints) diff --git a/src/Capacity/Upsert.php b/src/Capacity/Upsert.php index 17e7ed3..c524cc8 100644 --- a/src/Capacity/Upsert.php +++ b/src/Capacity/Upsert.php @@ -12,10 +12,7 @@ final class Upsert implements CapacityInterface { public function applies(array $config): bool { - $endpoints = array_merge( - Sylius\Validator\ExtractorConfigurationValidator::ADMIN_VALID_TYPES, - Sylius\Validator\ExtractorConfigurationValidator::SHOP_VALID_TYPES, - ); + $endpoints = [...Sylius\Validator\ExtractorConfigurationValidator::ADMIN_VALID_TYPES, ...Sylius\Validator\ExtractorConfigurationValidator::SHOP_VALID_TYPES]; return isset($config['type']) && \array_key_exists($config['type'], $endpoints) diff --git a/src/Configuration/Client.php b/src/Configuration/Client.php index 7ddbfc4..18c71bd 100644 --- a/src/Configuration/Client.php +++ b/src/Configuration/Client.php @@ -18,21 +18,15 @@ public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Bui /* @phpstan-ignore-next-line */ $builder->getRootNode() ->validate() - ->ifTrue(function ($v) { - return !empty($v['token']) && (!empty($v['username']) || !empty($v['password'])); - }) + ->ifTrue(fn($v) => !empty($v['token']) && (!empty($v['username']) || !empty($v['password']))) ->thenInvalid('You cannot specify both a token and a username/password combination.') ->end() ->validate() - ->ifTrue(function ($v) { - return (!empty($v['username']) && empty($v['password'])) || (empty($v['username']) && !empty($v['password'])); - }) + ->ifTrue(fn($v) => (!empty($v['username']) && empty($v['password'])) || (empty($v['username']) && !empty($v['password']))) ->thenInvalid('Both username and password must be defined together.') ->end() ->validate() - ->ifTrue(function ($v) { - return empty($v['token']) && (empty($v['username']) || empty($v['password'])); - }) + ->ifTrue(fn($v) => empty($v['token']) && (empty($v['username']) || empty($v['password']))) ->thenInvalid('You must specify either a token or a username and password combination.') ->end() ->children() diff --git a/src/Factory/Client.php b/src/Factory/Client.php index 87c1cf6..4016b57 100644 --- a/src/Factory/Client.php +++ b/src/Factory/Client.php @@ -94,7 +94,7 @@ public function compile(array $config): Repository\Client $clientBuilder->withClientBuilder( new Node\Expr\New_( new Node\Name\FullyQualified( - $this->type == Sylius\ApiType::ADMIN ? 'Diglin\\Sylius\\ApiClient\\SyliusAdminClientBuilder' : 'Diglin\\Sylius\\ApiClient\\SyliusShopClientBuilder' + $this->type == Sylius\ApiType::ADMIN ? \Diglin\Sylius\ApiClient\SyliusAdminClientBuilder::class : \Diglin\Sylius\ApiClient\SyliusShopClientBuilder::class ), ) ); diff --git a/src/Service.php b/src/Service.php index 47c6938..f0289a2 100644 --- a/src/Service.php +++ b/src/Service.php @@ -93,7 +93,7 @@ public function compile(array $config): Factory\Repository\Extractor|Factory\Rep $client = $clientFactory->compile($config['client']); $extractorBuilder - ->withClientType(ApiType::from($config['version']) == ApiType::ADMIN ? new Node\Name\FullyQualified(name: 'Diglin\\Sylius\\ApiClient\\SyliusAdminClientInterface') : new Node\Name\FullyQualified(name: 'Diglin\\Sylius\\ApiClient\\SyliusShopClientInterface')) + ->withClientType(ApiType::from($config['version']) == ApiType::ADMIN ? new Node\Name\FullyQualified(name: \Diglin\Sylius\ApiClient\SyliusAdminClientInterface::class) : new Node\Name\FullyQualified(name: \Diglin\Sylius\ApiClient\SyliusShopClientInterface::class)) ->withClient($client->getBuilder()->getNode()); $extractor->merge($client); @@ -109,7 +109,7 @@ public function compile(array $config): Factory\Repository\Extractor|Factory\Rep $client = $clientFactory->compile($config['client']); $loaderBuilder - ->withClientType(ApiType::from($config['version']) == ApiType::ADMIN ? new Node\Name\FullyQualified(name: 'Diglin\\Sylius\\ApiClient\\SyliusAdminClientInterface') : new Node\Name\FullyQualified(name: 'Diglin\\Sylius\\ApiClient\\SyliusShopClientInterface')) + ->withClientType(ApiType::from($config['version']) == ApiType::ADMIN ? new Node\Name\FullyQualified(name: \Diglin\Sylius\ApiClient\SyliusAdminClientInterface::class) : new Node\Name\FullyQualified(name: \Diglin\Sylius\ApiClient\SyliusShopClientInterface::class)) ->withClient($client->getBuilder()->getNode()); $loader->merge($client); diff --git a/src/Validator/ExtractorConfigurationValidator.php b/src/Validator/ExtractorConfigurationValidator.php index 7919040..f1ccb94 100644 --- a/src/Validator/ExtractorConfigurationValidator.php +++ b/src/Validator/ExtractorConfigurationValidator.php @@ -8,7 +8,7 @@ class ExtractorConfigurationValidator { - public const ADMIN_VALID_TYPES = [ + final public const ADMIN_VALID_TYPES = [ 'address' => [ 'get', ], @@ -167,7 +167,7 @@ class ExtractorConfigurationValidator ], ]; - public const SHOP_VALID_TYPES = [ + final public const SHOP_VALID_TYPES = [ 'address' => [ 'all', 'get', diff --git a/src/Validator/LoaderConfigurationValidator.php b/src/Validator/LoaderConfigurationValidator.php index 2ac6132..563e009 100644 --- a/src/Validator/LoaderConfigurationValidator.php +++ b/src/Validator/LoaderConfigurationValidator.php @@ -8,7 +8,7 @@ class LoaderConfigurationValidator { - public const ADMIN_VALID_TYPES = [ + final public const ADMIN_VALID_TYPES = [ 'address' => [ 'create', 'delete', @@ -157,7 +157,7 @@ class LoaderConfigurationValidator ], ]; - public const SHOP_VALID_TYPES = [ + final public const SHOP_VALID_TYPES = [ 'address' => [ 'create', 'delete',