Skip to content

Commit

Permalink
[rector] Rector fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jul 8, 2024
1 parent 09e8740 commit f028844
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 36 deletions.
9 changes: 3 additions & 6 deletions src/Capacity/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions src/Capacity/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions src/Capacity/ListPerPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions src/Capacity/Upsert.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 3 additions & 9 deletions src/Configuration/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
)
);
Expand Down
4 changes: 2 additions & 2 deletions src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Validator/ExtractorConfigurationValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class ExtractorConfigurationValidator
{
public const ADMIN_VALID_TYPES = [
final public const ADMIN_VALID_TYPES = [
'address' => [
'get',
],
Expand Down Expand Up @@ -167,7 +167,7 @@ class ExtractorConfigurationValidator
],
];

public const SHOP_VALID_TYPES = [
final public const SHOP_VALID_TYPES = [
'address' => [
'all',
'get',
Expand Down
4 changes: 2 additions & 2 deletions src/Validator/LoaderConfigurationValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class LoaderConfigurationValidator
{
public const ADMIN_VALID_TYPES = [
final public const ADMIN_VALID_TYPES = [
'address' => [
'create',
'delete',
Expand Down Expand Up @@ -157,7 +157,7 @@ class LoaderConfigurationValidator
],
];

public const SHOP_VALID_TYPES = [
final public const SHOP_VALID_TYPES = [
'address' => [
'create',
'delete',
Expand Down

0 comments on commit f028844

Please sign in to comment.