Skip to content

Commit

Permalink
Ran php-cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
sebprt committed Jul 8, 2024
1 parent f028844 commit 9d0ccf1
Show file tree
Hide file tree
Showing 26 changed files with 116 additions and 118 deletions.
2 changes: 2 additions & 0 deletions src/ApiType.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Kiboko\Plugin\Sylius;

enum ApiType: string
Expand Down
8 changes: 3 additions & 5 deletions src/Builder/Capacity/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@

final class All implements Builder
{
private null|Node\Expr|Node\Identifier $endpoint = null;
private null|Node\Expr $search = null;
private null|Node\Expr $code = null;

public function __construct() {}
private Node\Expr|Node\Identifier|null $endpoint = null;
private ?Node\Expr $search = null;
private ?Node\Expr $code = null;

public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self
{
Expand Down
8 changes: 3 additions & 5 deletions src/Builder/Capacity/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@

final class Create implements Builder
{
private null|Node\Expr|Node\Identifier $endpoint = null;
private null|Node\Expr $code = null;
private null|Node\Expr $data = null;

public function __construct() {}
private Node\Expr|Node\Identifier|null $endpoint = null;
private ?Node\Expr $code = null;
private ?Node\Expr $data = null;

public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self
{
Expand Down
8 changes: 3 additions & 5 deletions src/Builder/Capacity/ListPerPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@

final class ListPerPage implements Builder
{
private null|Node\Expr|Node\Identifier $endpoint = null;
private null|Node\Expr $search = null;
private null|Node\Expr $code = null;

public function __construct() {}
private Node\Expr|Node\Identifier|null $endpoint = null;
private ?Node\Expr $search = null;
private ?Node\Expr $code = null;

public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self
{
Expand Down
8 changes: 3 additions & 5 deletions src/Builder/Capacity/Upsert.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@

final class Upsert implements Builder
{
private null|Node\Expr|Node\Identifier $endpoint = null;
private null|Node\Expr $code = null;
private null|Node\Expr $data = null;

public function __construct() {}
private Node\Expr|Node\Identifier|null $endpoint = null;
private ?Node\Expr $code = null;
private ?Node\Expr $data = null;

public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self
{
Expand Down
7 changes: 4 additions & 3 deletions src/Builder/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Kiboko\Plugin\Sylius\Builder;

use Diglin\Sylius\ApiClient\SyliusAdminClientBuilder;
use Diglin\Sylius\ApiClient\SyliusShopClientBuilder;
use Kiboko\Plugin\Sylius\ApiType;
use Kiboko\Plugin\Sylius\MissingAuthenticationMethodException;
use PhpParser\Builder;
Expand All @@ -25,7 +23,10 @@ final class Client implements Builder
private ?Node\Expr $fileSystem = null;
private ?Node\Expr $client = null;

public function __construct(private readonly Node\Expr $baseUrl) {}
public function __construct(
private readonly Node\Expr $baseUrl,
) {
}

public function withSecret(Node\Expr $clientId, Node\Expr $secret): self
{
Expand Down
3 changes: 2 additions & 1 deletion src/Builder/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ final class Extractor implements StepBuilderInterface

public function __construct(
private readonly Builder $capacity,
) {}
) {
}

public function withClient(Node\Expr $client): self
{
Expand Down
5 changes: 4 additions & 1 deletion src/Builder/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ final class Loader implements StepBuilderInterface
private ?Node\Expr $client = null;
private ?Node $type = null;

public function __construct(private readonly Builder $capacity) {}
public function __construct(
private readonly Builder $capacity
) {
}

public function withClient(Node\Expr $client): self
{
Expand Down
9 changes: 5 additions & 4 deletions src/Builder/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ final class Search implements Builder
{
public function __construct(
private array $filters = []
) {}
) {
}

public function addFilter(
Node\Expr $field,
Node\Expr $operator,
Node\Expr $value = null,
Node\Expr $scope = null,
Node\Expr $locale = null
?Node\Expr $value = null,
?Node\Expr $scope = null,
?Node\Expr $locale = null
): self {
$arguments = [
new Node\Arg(
Expand Down
10 changes: 8 additions & 2 deletions src/Capacity/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@

final readonly class All implements CapacityInterface
{
public function __construct(private ExpressionLanguage $interpreter) {}
public function __construct(
private readonly ExpressionLanguage $interpreter
) {
}

public function applies(array $config): bool
{
$endpoints = [...Sylius\Validator\ExtractorConfigurationValidator::ADMIN_VALID_TYPES, ...Sylius\Validator\ExtractorConfigurationValidator::SHOP_VALID_TYPES];
$endpoints = array_merge(
Sylius\Validator\ExtractorConfigurationValidator::ADMIN_VALID_TYPES,
Sylius\Validator\ExtractorConfigurationValidator::SHOP_VALID_TYPES,
);

return isset($config['type'])
&& \array_key_exists($config['type'], $endpoints)
Expand Down
1 change: 0 additions & 1 deletion src/Capacity/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Kiboko\Plugin\Sylius\Capacity;

use Kiboko\Contract\Configurator\InvalidConfigurationException;
use Kiboko\Plugin\Sylius;
use PhpParser\Builder;
use PhpParser\Node;
Expand Down
10 changes: 8 additions & 2 deletions src/Capacity/ListPerPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@

final readonly class ListPerPage implements CapacityInterface
{
public function __construct(private ExpressionLanguage $interpreter) {}
public function __construct(
private readonly ExpressionLanguage $interpreter
) {
}

public function applies(array $config): bool
{
$endpoints = [...Sylius\Validator\ExtractorConfigurationValidator::ADMIN_VALID_TYPES, ...Sylius\Validator\ExtractorConfigurationValidator::SHOP_VALID_TYPES];
$endpoints = array_merge(
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: 4 additions & 1 deletion src/Capacity/Upsert.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ final class Upsert implements CapacityInterface
{
public function applies(array $config): bool
{
$endpoints = [...Sylius\Validator\ExtractorConfigurationValidator::ADMIN_VALID_TYPES, ...Sylius\Validator\ExtractorConfigurationValidator::SHOP_VALID_TYPES];
$endpoints = array_merge(
Sylius\Validator\ExtractorConfigurationValidator::ADMIN_VALID_TYPES,
Sylius\Validator\ExtractorConfigurationValidator::SHOP_VALID_TYPES,
);

return isset($config['type'])
&& \array_key_exists($config['type'], $endpoints)
Expand Down
1 change: 0 additions & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Kiboko\Plugin\Sylius;

use Kiboko\Contract\Configurator\InvalidConfigurationException;
use Kiboko\Contract\Configurator\PluginConfigurationInterface;
use Kiboko\Plugin\Sylius\Validator\ExtractorConfigurationValidator;
use Kiboko\Plugin\Sylius\Validator\LoaderConfigurationValidator;
Expand Down
8 changes: 4 additions & 4 deletions src/Configuration/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@

final class Client 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('client');

/* @phpstan-ignore-next-line */
$builder->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()
Expand Down
3 changes: 1 addition & 2 deletions src/Configuration/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

namespace Kiboko\Plugin\Sylius\Configuration;

use Kiboko\Plugin\Sylius\Validator\ExtractorConfigurationValidator;
use Symfony\Component\Config;

use function Kiboko\Component\SatelliteToolbox\Configuration\asExpression;
use function Kiboko\Component\SatelliteToolbox\Configuration\isExpression;

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();

Expand Down
3 changes: 1 addition & 2 deletions src/Configuration/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
48 changes: 24 additions & 24 deletions src/Factory/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
Expand Down
4 changes: 3 additions & 1 deletion src/Factory/NoApplicableCapacityException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

namespace Kiboko\Plugin\Sylius\Factory;

final class NoApplicableCapacityException extends \OutOfRangeException {}
final class NoApplicableCapacityException extends \OutOfRangeException
{
}
4 changes: 3 additions & 1 deletion src/MissingAuthenticationMethodException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

namespace Kiboko\Plugin\Sylius;

final class MissingAuthenticationMethodException extends \RuntimeException {}
final class MissingAuthenticationMethodException extends \RuntimeException
{
}
4 changes: 3 additions & 1 deletion src/MissingEndpointException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

namespace Kiboko\Plugin\Sylius;

final class MissingEndpointException extends \RuntimeException {}
final class MissingEndpointException extends \RuntimeException
{
}
4 changes: 3 additions & 1 deletion src/MissingParameterException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

namespace Kiboko\Plugin\Sylius;

final class MissingParameterException extends \UnexpectedValueException {}
final class MissingParameterException extends \UnexpectedValueException
{
}
12 changes: 7 additions & 5 deletions src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down
Loading

0 comments on commit 9d0ccf1

Please sign in to comment.