Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add api_type flag to build the right api client version #16

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6b0e402
add api_type flag to build the right api client version
JoMessina Oct 20, 2023
642db8a
[rector] Rector fixes
actions-user Oct 20, 2023
a9bfc43
move api_type in extractor/loader config, choose the right builder in…
JoMessina Oct 25, 2023
8e8ac77
remove api_type from Configuration, pass api_type to the client facto…
JoMessina Oct 25, 2023
28283e1
extract endpoints/methods from AdminApi on extractor/loader class
JoMessina Oct 25, 2023
ca7e08f
extract endpoints/methods from ShopApi on extractor/loader class
JoMessina Oct 26, 2023
3c3000c
extract endpoints for capacity All, fix a return type for filters on …
JoMessina Oct 26, 2023
bc7fcbf
extract endpoints for capacity Create/Upsert/ListPerPage
JoMessina Oct 26, 2023
87b5b69
create new validator classes for Loader and Extractor config
JoMessina Oct 27, 2023
189f06e
[rector] Rector fixes
actions-user Oct 27, 2023
3f412ac
add enum for api type values
JoMessina Oct 27, 2023
771836b
refacto to use the InvalidConfigurationException on the right node an…
JoMessina Nov 20, 2023
29e1b3f
fix tests, add a check on api_type parameter
JoMessina Nov 20, 2023
b39d262
cs-fixer
JoMessina Nov 20, 2023
0492d94
phpstan fixes
JoMessina Nov 20, 2023
bb64f43
cs-fixer
JoMessina Nov 20, 2023
53fa3b1
improve tests data for factory, add 2 check of wrong config
JoMessina Nov 20, 2023
67dacf9
manage exception for tests and infection, change xml version for vali…
JoMessina Nov 20, 2023
5eca1e4
improve tests and mutation percent, update phpunit config
JoMessina Nov 21, 2023
f22f4a7
fix infection version for accept phpunit 10.1.1 config (source tag re…
JoMessina Nov 21, 2023
0e7e2f2
use api_type to switch parameters for authentications methods
JoMessina Nov 22, 2023
27a7769
Add withSecret methods on the client to avoid clientId and secret par…
JoMessina Nov 23, 2023
65caa5f
code format commit
JoMessina May 23, 2024
09e8740
Improved the Sylius plugin for 1;9 or more recent version
sebprt Jul 8, 2024
f028844
[rector] Rector fixes
actions-user Jul 8, 2024
9d0ccf1
Ran php-cs-fixer
sebprt Jul 8, 2024
9c20916
[rector] Rector fixes
actions-user Jul 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/infection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:

- name: Infection
run: |
wget -q https://github.com/infection/infection/releases/download/0.26.18/infection.phar
wget -q https://github.com/infection/infection/releases/download/0.26.18/infection.phar.asc
wget -q https://github.com/infection/infection/releases/download/0.26.20/infection.phar
wget -q https://github.com/infection/infection/releases/download/0.26.20/infection.phar.asc
chmod +x infection.phar
./infection.phar

Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 27 additions & 22 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
backupGlobals="true"
colors="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
requireCoverageMetadata="false">
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
backupGlobals="true"
colors="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
requireCoverageMetadata="false"
bootstrap="vendor/autoload.php"
executionOrder="depends,defects"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="Functional tests">
<directory>tests/functional/</directory>
<directory>tests/functional</directory>
</testsuite>
</testsuites>
<coverage>
<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory suffix=".php">src</directory>
<directory>src</directory>
</include>
</coverage>
</source>
<php>
<ini name="allow_url_include" value="1" />
</php>
Expand Down
11 changes: 11 additions & 0 deletions src/ApiType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Kiboko\Plugin\Sylius;

enum ApiType: string
{
case ADMIN = 'admin';
case SHOP = 'shop';
}
10 changes: 3 additions & 7 deletions src/Builder/Capacity/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +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
10 changes: 3 additions & 7 deletions src/Builder/Capacity/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +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
10 changes: 3 additions & 7 deletions src/Builder/Capacity/ListPerPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +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
10 changes: 3 additions & 7 deletions src/Builder/Capacity/Upsert.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +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
57 changes: 42 additions & 15 deletions src/Builder/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

namespace Kiboko\Plugin\Sylius\Builder;

use Kiboko\Plugin\Sylius\ApiType;
use Kiboko\Plugin\Sylius\MissingAuthenticationMethodException;
use PhpParser\Builder;
use PhpParser\Node;

final class Client implements Builder
{
private ?Node\Expr $clientId = null;
private ?Node\Expr $secret = null;
private ?Node\Expr $username = null;
private ?Node\Expr $password = null;
private ?Node\Expr $token = null;
Expand All @@ -18,9 +21,19 @@ final class Client implements Builder
private ?Node\Expr $httpRequestFactory = null;
private ?Node\Expr $httpStreamFactory = null;
private ?Node\Expr $fileSystem = null;
private ?Node\Expr $client = null;

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

public function withSecret(Node\Expr $clientId, Node\Expr $secret): self
{
$this->clientId = $clientId;
$this->secret = $secret;

return $this;
}

public function withToken(Node\Expr $token, Node\Expr $refreshToken): self
Expand Down Expand Up @@ -67,17 +80,16 @@ public function withFileSystem(Node\Expr $fileSystem): self
return $this;
}

public function withClientBuilder(Node\Expr $client): self
{
$this->client = $client;

return $this;
}

public function getNode(): Node\Expr\MethodCall
{
$instance = new Node\Expr\MethodCall(
var: new Node\Expr\New_(
new Node\Name\FullyQualified('Diglin\\Sylius\\ApiClient\\SyliusClientBuilder'),
),
name: new Node\Identifier('setBaseUri'),
args: [
new Node\Arg($this->baseUrl),
],
);
$instance = $this->client;

if (null !== $this->httpClient) {
$instance = new Node\Expr\MethodCall(
Expand Down Expand Up @@ -126,6 +138,17 @@ public function getNode(): Node\Expr\MethodCall
);
}

private function getClientBuilderNode(): Node\Expr\MethodCall
{
return new Node\Expr\MethodCall(
var: $this->client,
name: new Node\Identifier('setBaseUri'),
args: [
new Node\Arg($this->baseUrl),
],
);
}

private function getFactoryMethod(): string
{
if (null !== $this->password) {
Expand All @@ -143,19 +166,23 @@ private function getFactoryArguments(): array
{
if (null !== $this->password) {
return [
$this->clientId,
$this->secret,
$this->username,
$this->password,
];
}

if (null !== $this->refreshToken) {
if ($this->apiType === ApiType::LEGACY->value) {
return [
$this->clientId,
$this->secret,
$this->token,
$this->refreshToken,
];
}

return [
$this->clientId,
$this->secret,
$this->token,
$this->refreshToken,
];
}

Expand Down
42 changes: 28 additions & 14 deletions src/Builder/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ final class Extractor implements StepBuilderInterface
{
private ?Node\Expr $logger = null;
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 All @@ -24,6 +26,13 @@ public function withClient(Node\Expr $client): self
return $this;
}

public function withClientType(Node $type): self
{
$this->type = $type;

return $this;
}

public function withLogger(Node\Expr $logger): self
{
$this->logger = $logger;
Expand Down Expand Up @@ -55,18 +64,7 @@ class: new Node\Stmt\Class_(
name: new Node\Identifier(name: '__construct'),
subNodes: [
'flags' => Node\Stmt\Class_::MODIFIER_PUBLIC,
'params' => [
new Node\Param(
var: new Node\Expr\Variable('client'),
type: new Node\Name\FullyQualified(name: \Diglin\Sylius\ApiClient\SyliusLegacyClientInterface::class),
flags: Node\Stmt\Class_::MODIFIER_PUBLIC,
),
new Node\Param(
var: new Node\Expr\Variable('logger'),
type: new Node\Name\FullyQualified(name: \Psr\Log\LoggerInterface::class),
flags: Node\Stmt\Class_::MODIFIER_PUBLIC,
),
],
'params' => $this->getParamsNode(),
],
),
new Node\Stmt\ClassMethod(
Expand Down Expand Up @@ -133,4 +131,20 @@ class: new Node\Stmt\Class_(
],
);
}

public function getParamsNode(): array
{
return [
new Node\Param(
var: new Node\Expr\Variable('client'),
type: $this->type,
flags: Node\Stmt\Class_::MODIFIER_PRIVATE,
),
new Node\Param(
var: new Node\Expr\Variable('logger'),
type: new Node\Name\FullyQualified(name: \Psr\Log\LoggerInterface::class),
flags: Node\Stmt\Class_::MODIFIER_PRIVATE,
),
];
}
}
Loading