diff --git a/src/ApiType.php b/src/ApiType.php index df140cb..8be5d1d 100644 --- a/src/ApiType.php +++ b/src/ApiType.php @@ -1,5 +1,7 @@ getRootNode() ->validate() - ->ifTrue(fn($v) => !empty($v['token']) && (!empty($v['username']) || !empty($v['password']))) + ->ifTrue(fn ($value) => !empty($value['token']) && (!empty($value['username']) || !empty($value['password']))) ->thenInvalid('You cannot specify both a token and a username/password combination.') ->end() ->validate() - ->ifTrue(fn($v) => (!empty($v['username']) && empty($v['password'])) || (empty($v['username']) && !empty($v['password']))) + ->ifTrue(fn ($value) => (!empty($value['username']) && empty($value['password'])) || (empty($value['username']) && !empty($value['password']))) ->thenInvalid('Both username and password must be defined together.') ->end() ->validate() - ->ifTrue(fn($v) => empty($v['token']) && (empty($v['username']) || empty($v['password']))) + ->ifTrue(fn ($value) => empty($value['token']) && (empty($value['username']) || empty($value['password']))) ->thenInvalid('You must specify either a token or a username and password combination.') ->end() ->children() diff --git a/src/Configuration/Extractor.php b/src/Configuration/Extractor.php index 81a5de9..e491b82 100644 --- a/src/Configuration/Extractor.php +++ b/src/Configuration/Extractor.php @@ -4,7 +4,6 @@ namespace Kiboko\Plugin\Sylius\Configuration; -use Kiboko\Plugin\Sylius\Validator\ExtractorConfigurationValidator; use Symfony\Component\Config; use function Kiboko\Component\SatelliteToolbox\Configuration\asExpression; @@ -12,7 +11,7 @@ final class Extractor implements Config\Definition\ConfigurationInterface { - public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Builder\TreeBuilder + public function getConfigTreeBuilder(): Config\Definition\Builder\TreeBuilder { $filters = new Search(); diff --git a/src/Configuration/Loader.php b/src/Configuration/Loader.php index 1c45a0d..74c812e 100644 --- a/src/Configuration/Loader.php +++ b/src/Configuration/Loader.php @@ -4,12 +4,11 @@ namespace Kiboko\Plugin\Sylius\Configuration; -use Kiboko\Plugin\Sylius\Validator\LoaderConfigurationValidator; use Symfony\Component\Config; final class Loader implements Config\Definition\ConfigurationInterface { - public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Builder\TreeBuilder + public function getConfigTreeBuilder(): Config\Definition\Builder\TreeBuilder { $builder = new Config\Definition\Builder\TreeBuilder('loader'); diff --git a/src/Configuration/Search.php b/src/Configuration/Search.php index b03d484..0ab9dc7 100644 --- a/src/Configuration/Search.php +++ b/src/Configuration/Search.php @@ -11,7 +11,7 @@ final class Search implements Config\Definition\ConfigurationInterface { - public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Builder\TreeBuilder + public function getConfigTreeBuilder(): Config\Definition\Builder\TreeBuilder { $builder = new Config\Definition\Builder\TreeBuilder('search'); diff --git a/src/Factory/Client.php b/src/Factory/Client.php index 4016b57..98877a6 100644 --- a/src/Factory/Client.php +++ b/src/Factory/Client.php @@ -76,39 +76,39 @@ public function compile(array $config): Repository\Client compileValueWhenExpression($this->interpreter, $config['api_url']), ); -// if (isset($config['context'])) { -// if (isset($config['context']['http_client'])) { -// $clientBuilder->withHttpClient($this->buildFactoryNode($config['context']['http_client'])); -// } -// if (isset($config['context']['http_request_factory'])) { -// $clientBuilder->withHttpRequestFactory($this->buildFactoryNode($config['context']['http_request_factory'])); -// } -// if (isset($config['context']['http_stream_factory'])) { -// $clientBuilder->withHttpStreamFactory($this->buildFactoryNode($config['context']['http_stream_factory'])); -// } -// if (isset($config['context']['filesystem'])) { -// $clientBuilder->withFileSystem($this->buildFactoryNode($config['context']['filesystem'])); -// } -// } + // if (isset($config['context'])) { + // if (isset($config['context']['http_client'])) { + // $clientBuilder->withHttpClient($this->buildFactoryNode($config['context']['http_client'])); + // } + // if (isset($config['context']['http_request_factory'])) { + // $clientBuilder->withHttpRequestFactory($this->buildFactoryNode($config['context']['http_request_factory'])); + // } + // if (isset($config['context']['http_stream_factory'])) { + // $clientBuilder->withHttpStreamFactory($this->buildFactoryNode($config['context']['http_stream_factory'])); + // } + // if (isset($config['context']['filesystem'])) { + // $clientBuilder->withFileSystem($this->buildFactoryNode($config['context']['filesystem'])); + // } + // } $clientBuilder->withClientBuilder( new Node\Expr\New_( new Node\Name\FullyQualified( - $this->type == Sylius\ApiType::ADMIN ? \Diglin\Sylius\ApiClient\SyliusAdminClientBuilder::class : \Diglin\Sylius\ApiClient\SyliusShopClientBuilder::class + Sylius\ApiType::ADMIN == $this->type ? 'Diglin\\Sylius\\ApiClient\\SyliusAdminClientBuilder' : 'Diglin\\Sylius\\ApiClient\\SyliusShopClientBuilder' ), ) ); -// if (isset($config['client_id']) && isset($config['secret'])) { -// if (isset($config['api_type']) && $config['api_type'] === Sylius\Validator\ApiType::LEGACY->value) { -// $clientBuilder->withSecret( -// compileValueWhenExpression($this->interpreter, $config['client_id']), -// compileValueWhenExpression($this->interpreter, $config['secret']) -// ); -// } -// } + // if (isset($config['client_id']) && isset($config['secret'])) { + // if (isset($config['api_type']) && $config['api_type'] === Sylius\Validator\ApiType::LEGACY->value) { + // $clientBuilder->withSecret( + // compileValueWhenExpression($this->interpreter, $config['client_id']), + // compileValueWhenExpression($this->interpreter, $config['secret']) + // ); + // } + // } - if (isset($config['username']) && isset($config['password'])) { + if (isset($config['username'], $config['password'])) { $clientBuilder->withPassword( compileValueWhenExpression($this->interpreter, $config['username']), compileValueWhenExpression($this->interpreter, $config['password']), diff --git a/src/Factory/NoApplicableCapacityException.php b/src/Factory/NoApplicableCapacityException.php index 2922447..1ab18bc 100644 --- a/src/Factory/NoApplicableCapacityException.php +++ b/src/Factory/NoApplicableCapacityException.php @@ -4,4 +4,6 @@ namespace Kiboko\Plugin\Sylius\Factory; -final class NoApplicableCapacityException extends \OutOfRangeException {} +final class NoApplicableCapacityException extends \OutOfRangeException +{ +} diff --git a/src/MissingAuthenticationMethodException.php b/src/MissingAuthenticationMethodException.php index 8389a55..577827b 100644 --- a/src/MissingAuthenticationMethodException.php +++ b/src/MissingAuthenticationMethodException.php @@ -4,4 +4,6 @@ namespace Kiboko\Plugin\Sylius; -final class MissingAuthenticationMethodException extends \RuntimeException {} +final class MissingAuthenticationMethodException extends \RuntimeException +{ +} diff --git a/src/MissingEndpointException.php b/src/MissingEndpointException.php index 847c93b..ea86064 100644 --- a/src/MissingEndpointException.php +++ b/src/MissingEndpointException.php @@ -4,4 +4,6 @@ namespace Kiboko\Plugin\Sylius; -final class MissingEndpointException extends \RuntimeException {} +final class MissingEndpointException extends \RuntimeException +{ +} diff --git a/src/MissingParameterException.php b/src/MissingParameterException.php index 5119d4b..2cb38d5 100644 --- a/src/MissingParameterException.php +++ b/src/MissingParameterException.php @@ -4,4 +4,6 @@ namespace Kiboko\Plugin\Sylius; -final class MissingParameterException extends \UnexpectedValueException {} +final class MissingParameterException extends \UnexpectedValueException +{ +} diff --git a/src/Service.php b/src/Service.php index f0289a2..cdb1acf 100644 --- a/src/Service.php +++ b/src/Service.php @@ -7,10 +7,10 @@ use Kiboko\Contract\Configurator; use Kiboko\Contract\Configurator\ConfigurationExceptionInterface; use Kiboko\Contract\Configurator\InvalidConfigurationException; +use PhpParser\Node; use Symfony\Component\Config\Definition\Exception as Symfony; use Symfony\Component\Config\Definition\Processor; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; -use PhpParser\Node; #[Configurator\Pipeline( name: 'sylius', @@ -93,8 +93,9 @@ 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::class) : new Node\Name\FullyQualified(name: \Diglin\Sylius\ApiClient\SyliusShopClientInterface::class)) - ->withClient($client->getBuilder()->getNode()); + ->withClientType(ApiType::ADMIN == ApiType::from($config['version']) ? new Node\Name\FullyQualified(name: 'Diglin\\Sylius\\ApiClient\\SyliusAdminClientInterface') : new Node\Name\FullyQualified(name: 'Diglin\\Sylius\\ApiClient\\SyliusShopClientInterface')) + ->withClient($client->getBuilder()->getNode()) + ; $extractor->merge($client); @@ -109,8 +110,9 @@ 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::class) : new Node\Name\FullyQualified(name: \Diglin\Sylius\ApiClient\SyliusShopClientInterface::class)) - ->withClient($client->getBuilder()->getNode()); + ->withClientType(ApiType::ADMIN == ApiType::from($config['version']) ? new Node\Name\FullyQualified(name: 'Diglin\\Sylius\\ApiClient\\SyliusAdminClientInterface') : new Node\Name\FullyQualified(name: 'Diglin\\Sylius\\ApiClient\\SyliusShopClientInterface')) + ->withClient($client->getBuilder()->getNode()) + ; $loader->merge($client); diff --git a/src/Validator/ExtractorConfigurationValidator.php b/src/Validator/ExtractorConfigurationValidator.php index f1ccb94..ef5d2e6 100644 --- a/src/Validator/ExtractorConfigurationValidator.php +++ b/src/Validator/ExtractorConfigurationValidator.php @@ -75,7 +75,7 @@ class ExtractorConfigurationValidator 'get', ], 'paymentMethod' => [ - 'all' , + 'all', 'get', ], 'payment' => [ @@ -103,7 +103,7 @@ class ExtractorConfigurationValidator 'get', ], 'productTaxon' => [ - 'all' , + 'all', 'get', ], 'productTranslation' => [ @@ -118,7 +118,7 @@ class ExtractorConfigurationValidator ], 'product' => [ 'all', - 'get' + 'get', ], 'promotionCoupon' => [ 'all', @@ -215,7 +215,7 @@ class ExtractorConfigurationValidator 'get', ], 'paymentMethod' => [ - 'all' , + 'all', 'get', ], 'payment' => [ @@ -246,7 +246,7 @@ class ExtractorConfigurationValidator ], 'product' => [ 'all', - 'get' + 'get', ], 'shippingMethod' => [ 'all', @@ -263,29 +263,18 @@ class ExtractorConfigurationValidator public static function validate(string $type, string $method, string $version = 'admin'): void { - $validTypes = $version === 'admin' ? self::ADMIN_VALID_TYPES : self::SHOP_VALID_TYPES; + $validTypes = 'admin' === $version ? self::ADMIN_VALID_TYPES : self::SHOP_VALID_TYPES; - if ($validTypes === null) { + if (null === $validTypes) { throw new InvalidConfigurationException(sprintf('Unknown version "%s".', $version)); } - if (!array_key_exists($type, $validTypes)) { - throw new InvalidConfigurationException(sprintf( - 'Invalid extractor type "%s" for version "%s". Valid types are: %s.', - $type, - $version, - implode(', ', array_keys($validTypes)) - )); + if (!\array_key_exists($type, $validTypes)) { + throw new InvalidConfigurationException(sprintf('Invalid extractor type "%s" for version "%s". Valid types are: %s.', $type, $version, implode(', ', array_keys($validTypes)))); } - if (!in_array($method, $validTypes[$type], true)) { - throw new InvalidConfigurationException(sprintf( - 'Invalid method "%s" for extractor type "%s" and version "%s". Valid methods are: %s.', - $method, - $type, - $version, - implode(', ', $validTypes[$type]) - )); + if (!\in_array($method, $validTypes[$type], true)) { + throw new InvalidConfigurationException(sprintf('Invalid method "%s" for extractor type "%s" and version "%s". Valid methods are: %s.', $method, $type, $version, implode(', ', $validTypes[$type]))); } } } diff --git a/src/Validator/LoaderConfigurationValidator.php b/src/Validator/LoaderConfigurationValidator.php index 563e009..c5ed589 100644 --- a/src/Validator/LoaderConfigurationValidator.php +++ b/src/Validator/LoaderConfigurationValidator.php @@ -181,32 +181,20 @@ class LoaderConfigurationValidator ], ]; - public static function validate(string $type, string $method, string $version = 'admin'): void { - $validTypes = $version === 'admin' ? self::ADMIN_VALID_TYPES : self::SHOP_VALID_TYPES; + $validTypes = 'admin' === $version ? self::ADMIN_VALID_TYPES : self::SHOP_VALID_TYPES; - if ($validTypes === null) { + if (null === $validTypes) { throw new InvalidConfigurationException(sprintf('Unknown version "%s".', $version)); } - if (!array_key_exists($type, $validTypes)) { - throw new InvalidConfigurationException(sprintf( - 'Invalid loader type "%s" for version "%s". Valid types are: %s.', - $type, - $version, - implode(', ', array_keys($validTypes)) - )); + if (!\array_key_exists($type, $validTypes)) { + throw new InvalidConfigurationException(sprintf('Invalid loader type "%s" for version "%s". Valid types are: %s.', $type, $version, implode(', ', array_keys($validTypes)))); } - if (!in_array($method, $validTypes[$type], true)) { - throw new InvalidConfigurationException(sprintf( - 'Invalid method "%s" for extractor type "%s" and version "%s". Valid methods are: %s.', - $method, - $type, - $version, - implode(', ', $validTypes[$type]) - )); + if (!\in_array($method, $validTypes[$type], true)) { + throw new InvalidConfigurationException(sprintf('Invalid method "%s" for extractor type "%s" and version "%s". Valid methods are: %s.', $method, $type, $version, implode(', ', $validTypes[$type]))); } } }