Skip to content

Commit

Permalink
Small refactor (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Nov 20, 2023
1 parent 5149e04 commit e3ab03f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/ValueHandler/ProductOptionValueHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Akeneo\Pim\ApiClient\AkeneoPimClientInterface;
use Akeneo\Pim\ApiClient\Exception\HttpException;
use Akeneo\Pim\Structure\Component\AttributeTypes;
use InvalidArgumentException;
use LogicException;
use RuntimeException;
Expand All @@ -24,6 +25,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-type AkeneoAttribute array{code: string, type: string, labels: array<string, ?string>}
* @psalm-type AkeneoAttributeOption array{_links: array, code: string, attribute: string, sort_order: int, labels: array<string, ?string>}
*/
final class ProductOptionValueHandler implements ValueHandlerInterface
Expand Down Expand Up @@ -84,6 +86,7 @@ public function handle($productVariant, string $optionCode, array $akeneoValue):
}

try {
/** @var AkeneoAttribute $akeneoAttribute */
$akeneoAttribute = $this->apiClient->getAttributeApi()->get($optionCode);
} catch (HttpException $e) {
$response = $e->getResponse();
Expand All @@ -109,20 +112,22 @@ public function handle($productVariant, string $optionCode, array $akeneoValue):

$productOption = $this->getProductOption($optionCode, $productVariant, $product);

/** @var string $attributeType */
/**
* See https://help.akeneo.com/serenity-build-your-catalog/30-serenity-manage-your-families-and-variant-families?from_search=132874388#manage-family-variants:~:text=An%20attribute%20of%20the%20family%20could%20be%20a%C2%A0variant%20axis%C2%A0only%20if%20its%20attribute%20type%20is%20one%20of%20the%20following%3A
*/
$attributeType = $akeneoAttribute['type'];
switch ($attributeType) {
case 'pim_catalog_simpleselect':
case AttributeTypes::OPTION_SIMPLE_SELECT:

Check failure on line 120 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^6.3, MySQL 8.0

Access to constant OPTION_SIMPLE_SELECT on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 120 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^5.4, MySQL 8.0

Access to constant OPTION_SIMPLE_SELECT on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 120 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^6.3, MySQL 8.0

Access to constant OPTION_SIMPLE_SELECT on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 120 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.0, Symfony ^5.4, MySQL 8.0

Access to constant OPTION_SIMPLE_SELECT on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 120 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^5.4, MySQL 8.0

Access to constant OPTION_SIMPLE_SELECT on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 120 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^6.3, MySQL 8.0

Access to constant OPTION_SIMPLE_SELECT on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 120 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^5.4, MySQL 8.0

Access to constant OPTION_SIMPLE_SELECT on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 120 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^5.4, MySQL 8.0

Access to constant OPTION_SIMPLE_SELECT on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 120 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.0, Symfony ^5.4, MySQL 8.0

Access to constant OPTION_SIMPLE_SELECT on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 120 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^6.3, MySQL 8.0

Access to constant OPTION_SIMPLE_SELECT on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.
Assert::string($akeneoValueData);
$this->handleSelectOption($productOption, $optionCode, $akeneoValueData, $product, $productVariant);

break;
case 'pim_catalog_metric':
case AttributeTypes::METRIC:

Check failure on line 125 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^6.3, MySQL 8.0

Access to constant METRIC on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 125 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^5.4, MySQL 8.0

Access to constant METRIC on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 125 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^6.3, MySQL 8.0

Access to constant METRIC on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 125 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.0, Symfony ^5.4, MySQL 8.0

Access to constant METRIC on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 125 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^5.4, MySQL 8.0

Access to constant METRIC on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 125 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^6.3, MySQL 8.0

Access to constant METRIC on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 125 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^5.4, MySQL 8.0

Access to constant METRIC on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 125 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^5.4, MySQL 8.0

Access to constant METRIC on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 125 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.0, Symfony ^5.4, MySQL 8.0

Access to constant METRIC on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 125 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^6.3, MySQL 8.0

Access to constant METRIC on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.
Assert::isArray($akeneoValueData);
$this->handleMetricOption($productOption, $optionCode, $akeneoValueData, $productVariant);

break;
case 'pim_catalog_boolean':
case AttributeTypes::BOOLEAN:

Check failure on line 130 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^6.3, MySQL 8.0

Access to constant BOOLEAN on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 130 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^5.4, MySQL 8.0

Access to constant BOOLEAN on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 130 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^6.3, MySQL 8.0

Access to constant BOOLEAN on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 130 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.0, Symfony ^5.4, MySQL 8.0

Access to constant BOOLEAN on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 130 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^5.4, MySQL 8.0

Access to constant BOOLEAN on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 130 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^6.3, MySQL 8.0

Access to constant BOOLEAN on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 130 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^5.4, MySQL 8.0

Access to constant BOOLEAN on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 130 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^5.4, MySQL 8.0

Access to constant BOOLEAN on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 130 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.0, Symfony ^5.4, MySQL 8.0

Access to constant BOOLEAN on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.

Check failure on line 130 in src/ValueHandler/ProductOptionValueHandler.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^6.3, MySQL 8.0

Access to constant BOOLEAN on an unknown class Akeneo\Pim\Structure\Component\AttributeTypes.
Assert::boolean($akeneoValueData);
$this->handleBooleanOption($productOption, $optionCode, $akeneoValueData, $productVariant);

Expand Down

0 comments on commit e3ab03f

Please sign in to comment.