Skip to content

Commit

Permalink
extract endpoints for capacity Create/Upsert/ListPerPage
Browse files Browse the repository at this point in the history
  • Loading branch information
JoMessina committed Oct 26, 2023
1 parent 3c3000c commit bc7fcbf
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 8 deletions.
45 changes: 43 additions & 2 deletions src/Capacity/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final class Create implements CapacityInterface
{
private static array $endpoints = [
private static array $endpointsLegacy = [
// Core Endpoints
'channels',
'countries',
Expand Down Expand Up @@ -40,10 +40,51 @@ final class Create implements CapacityInterface
'zones',
];

private static array $endpointsAdmin = [
// Core Endpoints
'administrator',
'avatarImage',
'catalogPromotion',
'channel',
'country',
'currency',
'customerGroup',
'exchangeRate',
'locale',
'product',
'productAssociationType',
'productOption',
'productVariant',
'promotion',
'resetPasswordRequest',
'shippingCategory',
'shippingMethod',
'taxCategory',
'taxon',
'verifyCustomerAccount',
'zone',
];

private static array $endpointsShop = [
// Core Endpoints
'address',
'customer',
'order',
'orderItem',
'productReview',
'resetPasswordRequest',
'verifyCustomerAccount',
];

public function applies(array $config): bool
{
$endpoints = match($config['api_type']) {

Check failure on line 81 in src/Capacity/Create.php

View workflow job for this annotation

GitHub Actions / phpstan

Match expression does not handle remaining value: mixed
'admin' => self::$endpointsAdmin,
'shop' =>self::$endpointsShop,
'legacy' => self::$endpointsLegacy,
};
return isset($config['type'])
&& \in_array($config['type'], self::$endpoints)
&& \in_array($config['type'], $endpoints)
&& isset($config['method'])
&& 'create' === $config['method'];
}
Expand Down
92 changes: 88 additions & 4 deletions src/Capacity/ListPerPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

final class ListPerPage implements CapacityInterface
{
private static array $endpoints = [
private static array $endpointsLegacy = [
// Simple resources Endpoints
'channels',
'countries',
Expand Down Expand Up @@ -41,26 +41,110 @@ final class ListPerPage implements CapacityInterface
'zones',
];

private static array $doubleEndpoints = [
private static array $endpointsAdmin = [
// Simple Ressource Endpoints
'adjustment',
'administrator',
'catalogPromotion',
'channel',
'country',
'currency',
'customerGroup',
'exchangeRate',
'locale',
'order',
'payment',
'product',
'productAssociationType',
'productImage',
'productOption',
'productOptionValue',
'productReview',
'productTaxon',
'productVariant',
'promotion',
'province',
'shipment',
'shippingCategory',
'shippingMethod',
'ShopBillingData',
'taxCategory',
'taxon',
'taxonTranslation',
'zone',
'zoneMember',
];

private static array $endpointsShop = [
// Simple Ressource Endpoints
'address',
'adjustment',
'country',
'currency',
'locale',
'order',
'orderItem',
'payment',
'paymentMethod',
'product',
'productReview',
'productVariant',
'shipment',
'shippingMethod',
'taxon',
];

private static array $doubleEndpointsLegacy = [
// Double resources Endpoints
'productReviews',
'productVariants',
'promotionCoupons',
];
private static array $doubleEndpointsAdmin = [
// Double resources Endpoints
'adjustment',
'province',
'shopBillingData',
'zoneMember',
];

private static array $doubleEndpointsShop = [
// Double resources Endpoints
'adjustment',
'order',
];

public function __construct(private readonly ExpressionLanguage $interpreter)
{
}

public function applies(array $config): bool
{
switch($config['api_type']) {
case 'admin':
$endpoints = self::$endpointsAdmin;
$doubleEndpoints = self::$doubleEndpointsAdmin;
break;
case 'shop':
$endpoints = self::$endpointsShop;
$doubleEndpoints = self::$doubleEndpointsShop;
break;
case 'legacy':
$endpoints = self::$endpointsLegacy;
$doubleEndpoints = self::$doubleEndpointsLegacy;
break;
default:
$endpoints = [];
$doubleEndpoints = [];
break;
}
return isset($config['type'])
&& (\in_array($config['type'], self::$endpoints) || \in_array($config['type'], self::$doubleEndpoints))
&& (\in_array($config['type'], $endpoints) || \in_array($config['type'], $doubleEndpoints))
&& isset($config['method'])
&& 'listPerPage' === $config['method'];
}

private function compileFilters(array ...$filters): Node
private function compileFilters(array ...$filters): Node\Expr
{
$builder = new Sylius\Builder\Search();
foreach ($filters as $filter) {
Expand Down
35 changes: 33 additions & 2 deletions src/Capacity/Upsert.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final class Upsert implements CapacityInterface
{
private static array $endpoints = [
private static array $endpointsLegacy = [
// Core Endpoints
'carts',
'channels',
Expand Down Expand Up @@ -42,10 +42,41 @@ final class Upsert implements CapacityInterface
'zones',
];

private static array $endpointsAdmin = [
// Core Endpoints
'administrator',
'catalogPromotion',
'customerGroup',
'exchangeRate',
'product',
'productAssociationType',
'productOption',
'productReview',
'productVariant',
'province',
'shippingCategory',
'shippingMethod',
'taxCategory',
'taxon',
'zone',
];

private static array $endpointsShop = [
// Core Endpoints
'address',
'customer',
'order',
];

public function applies(array $config): bool
{
$endpoints = match($config['api_type']) {

Check failure on line 73 in src/Capacity/Upsert.php

View workflow job for this annotation

GitHub Actions / phpstan

Match expression does not handle remaining value: mixed
'admin' => self::$endpointsAdmin,
'shop' =>self::$endpointsShop,
'legacy' => self::$endpointsLegacy,
};
return isset($config['type'])
&& \in_array($config['type'], self::$endpoints)
&& \in_array($config['type'], $endpoints)
&& isset($config['method'])
&& 'upsert' === $config['method'];
}
Expand Down

0 comments on commit bc7fcbf

Please sign in to comment.