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

Support for Sylius 1.10 and PHP 8 #107

Merged
merged 15 commits into from
Oct 21, 2021
14 changes: 7 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [7.4, 7.3]
symfony: [^4.4, ^5.2]
sylius: [~1.8.0, ~1.9.0]
node: [10.x]
mysql: [5.7]
php: ["8.0", "7.4"]
symfony: ["^4.4", "^5.2"]
sylius: ["~1.9.0", "~1.10.0@alpha"]
LucaGallinari marked this conversation as resolved.
Show resolved Hide resolved
node: ["10.x"]
mysql: ["8.0"]

exclude:
-
sylius: ~1.8.0
symfony: ^5.2
php: "8.0"
sylius: "~1.9.0"

env:
APP_ENV: test
Expand Down
22 changes: 12 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
"description": "Plugin allowing to import products data from Akeneo PIM to your Sylius store.",
"license": "MIT",
"require": {
"php": "^7.3",
"php": "^7.4 || ^8.0",
"cocur/slugify": "^4.0",
"guzzlehttp/guzzle": "^6.5",
"sylius/sylius": "~1.8.0 || ~1.9.0",
"sylius/sylius": "~1.9.0 || ~1.10.0@alpha",
LucaGallinari marked this conversation as resolved.
Show resolved Hide resolved
"symfony/deprecation-contracts": "^2.2",
"symfony/lock": "^4.4|^5.0"
},
"conflict": {
"api-platform/core": "^2.6"
"doctrine/dbal": "^3.0",
"doctrine/orm": "^2.10.0"
},
"require-dev": {
"ext-json": "*",
Expand All @@ -26,37 +27,38 @@
"dmore/chrome-mink-driver": "^2.7",
"friends-of-behat/mink": "^1.8",
"friends-of-behat/mink-browserkit-driver": "^1.4",
"friends-of-behat/mink-debug-extension": "^2.0.0",
"friends-of-behat/mink-extension": "^2.4",
"friends-of-behat/page-object-extension": "^0.3",
"friends-of-behat/suite-settings-extension": "^1.0",
"friends-of-behat/symfony-extension": "^2.1",
"friends-of-behat/variadic-extension": "^1.3",
"friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev",
"lakion/mink-debug-extension": "^2.0.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.2",
"matthiasnoback/symfony-dependency-injection-test": "^4.3",
"mikey179/vfsstream": "^1.6",
"phpspec/phpspec": "^7.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "0.12.74",
"phpstan/phpstan-doctrine": "0.12.31",
"phpstan/phpstan": "0.12.85",
"phpstan/phpstan-doctrine": "0.12.33",
"phpstan/phpstan-strict-rules": "^0.12.0",
"phpstan/phpstan-webmozart-assert": "0.12.12",
"phpunit/phpunit": "^9.5",
"sensiolabs/security-checker": "^6.0",
"sylius-labs/coding-standard": "^3.1",
"sylius-labs/coding-standard": "^4.0",
"symfony/browser-kit": "^4.4 || ^5.2",
"symfony/debug-bundle": "^4.4 || ^5.2",
"symfony/dotenv": "^4.4 || ^5.2",
"symfony/intl": "^4.4 || ^5.2",
"symfony/web-profiler-bundle": "^4.4 || ^5.2",
"theofidry/alice-data-fixtures": "^1.1",
"vimeo/psalm": "4.4.1"
"vimeo/psalm": "4.7.1"
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "1.9-dev"
"dev-master": "1.10-dev"
}
},
"autoload": {
Expand Down
9 changes: 0 additions & 9 deletions easy-coding-standard.yml

This file was deleted.

14 changes: 14 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer;
use SlevomatCodingStandard\Sniffs\Commenting\InlineDocCommentDeclarationSniff;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import('vendor/sylius-labs/coding-standard/ecs.php');

$containerConfigurator->parameters()->set(Option::SKIP, [
VisibilityRequiredFixer::class => ['*Spec.php'],
]);
};
5 changes: 3 additions & 2 deletions src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Webgriffe\SyliusAkeneoPlugin;

use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Request;
Expand Down Expand Up @@ -90,7 +91,7 @@ public function authenticatedRequest(string $uri, string $method, array $headers
$headers,
[
'Content-Type' => 'application/json',
'Authorization' => sprintf('Bearer %s', $this->accessToken),
'Authorization' => sprintf('Bearer %s', (string) $this->accessToken),
]
);
$request = new Request($method, $uri, $headers);
Expand Down Expand Up @@ -255,7 +256,7 @@ private function getResourceOrNull(string $endpoint): ?array
{
try {
$response = $this->authenticatedRequest($endpoint, 'GET', []);
} catch (\HttpException $exception) {
} catch (ClientException $exception) {
if ($exception->getCode() !== 404) {
throw $exception;
}
Expand Down
2 changes: 1 addition & 1 deletion src/AttributeOptions/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getIdentifiersModifiedSince(\DateTime $sinceDate): array
$syliusSelectAttributes = $this->attributeRepository->findBy(['type' => SelectAttributeType::TYPE]);
$syliusSelectAttributes = array_filter(
array_map(
function (ProductAttributeInterface $attribute) {
static function (ProductAttributeInterface $attribute): ?string {
return $attribute->getCode();
},
$syliusSelectAttributes
Expand Down
14 changes: 7 additions & 7 deletions src/Command/EnqueueCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$sinceFilePath = null;
if ($sinceOptionValue = (string)$input->getOption(self::SINCE_OPTION_NAME)) {
if ('' !== $sinceOptionValue = (string)$input->getOption(self::SINCE_OPTION_NAME)) {
try {
$sinceDate = new \DateTime($sinceOptionValue);
} catch (\Throwable $t) {
throw new \InvalidArgumentException(
sprintf('The "%s" argument must be a valid date', self::SINCE_OPTION_NAME)
);
}
} elseif ($sinceFilePath = (string)$input->getOption(self::SINCE_FILE_OPTION_NAME)) {
} elseif ('' !== $sinceFilePath = (string)$input->getOption(self::SINCE_FILE_OPTION_NAME)) {
$sinceDate = $this->getSinceDateByFile($sinceFilePath);
} elseif ($input->getOption(self::ALL_OPTION_NAME) === true) {
$sinceDate = (new \DateTime())->setTimestamp(0);
Expand Down Expand Up @@ -139,7 +139,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
$queueItem = $this->queueItemFactory->createNew();
Assert::isInstanceOf($queueItem, QueueItemInterface::class);
/** @var QueueItemInterface $queueItem */
$queueItem->setAkeneoEntity($importer->getAkeneoEntity());
$queueItem->setAkeneoIdentifier($identifier);
$queueItem->setCreatedAt(new \DateTime());
Expand All @@ -154,7 +153,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

if ($sinceFilePath) {
if ($sinceFilePath !== null && $sinceFilePath !== '') {
$this->writeSinceDateFile($sinceFilePath, $runDate);
}

Expand Down Expand Up @@ -184,7 +183,6 @@ private function getSinceDateByFile(string $filepath): \DateTime
try {
$content = file_get_contents($filepath);
Assert::string($content);
/** @var string $content */
$sinceDate = new \DateTime(trim($content));
} catch (\Throwable $t) {
throw new \RuntimeException(sprintf('The file "%s" must contain a valid datetime', $filepath), 0, $t);
Expand All @@ -201,7 +199,7 @@ private function writeSinceDateFile(string $filepath, \DateTime $runDate): void
private function isEntityAlreadyQueuedToImport(string $akeneoEntity, string $akeneoIdentifier): bool
{
$queueItem = $this->queueItemRepository->findOneToImport($akeneoEntity, $akeneoIdentifier);
if ($queueItem) {
if ($queueItem !== null) {
return true;
}

Expand All @@ -218,7 +216,7 @@ private function getImporters(InputInterface $input): array
throw new \RuntimeException('There are no importers in registry.');
}
$importersCodes = array_map(
static function (ImporterInterface $importer) {
static function (ImporterInterface $importer): string {
return $importer->getAkeneoEntity();
},
$allImporters
Expand All @@ -232,9 +230,11 @@ static function (ImporterInterface $importer) {
return $allImporters;
}

/** @var ImporterInterface[]|array<string, ImporterInterface>|false $allImporters */
$allImporters = array_combine($importersCodes, $allImporters);
Assert::isArray($allImporters);

/** @var ImporterInterface[] $importers */
$importers = [];
foreach ($importersToUse as $importerToUse) {
if (!array_key_exists($importerToUse, $allImporters)) {
Expand Down
6 changes: 4 additions & 2 deletions src/Command/ReconcileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private function getReconcilers(InputInterface $input): array
return [];
}
$reconcilersCodes = array_map(
static function (ReconcilerInterface $reconciler) {
static function (ReconcilerInterface $reconciler): string {
return $reconciler->getAkeneoEntity();
},
$allReconcilers
Expand All @@ -100,9 +100,11 @@ static function (ReconcilerInterface $reconciler) {
return $allReconcilers;
}

/** @var ReconcilerInterface[]|array<string, ReconcilerInterface>|false $allReconcilers */
$allReconcilers = array_combine($reconcilersCodes, $allReconcilers);
Assert::isArray($allReconcilers);
Assert::notFalse($allReconcilers);

/** @var ReconcilerInterface[] $reconcilers */
$reconcilers = [];
foreach ($reconcilersToUse as $reconcilerToUse) {
if (!array_key_exists($reconcilerToUse, $allReconcilers)) {
Expand Down
2 changes: 0 additions & 2 deletions src/Controller/ProductEnqueueController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ public function enqueueAction(int $productId): Response
$alreadyEnqueued = [];
$enqueued = [];
foreach ($product->getVariants() as $productVariant) {
/** @var ?string $productVariantCode */
$productVariantCode = $productVariant->getCode();
Assert::notNull($productVariantCode);

/** @var array $productEnqueued */
$productEnqueued = $this->queueItemRepository->findBy([
'akeneoIdentifier' => $productVariantCode,
'akeneoEntity' => 'Product',
Expand Down
2 changes: 0 additions & 2 deletions src/Converter/UnitMeasurementValueConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public function convert(string $amount, string $sourceUnitMeasurementCode, ?stri
private function getUnitMeasurementFamilyByUnitMeasurementCode(string $unitMeasurementCode): array
{
$unitMeasurementFamilies = $this->apiClient->getMeasurementFamilies();
/** @var array{code: string, labels: array{localeCode: string}, standard_unit_code: string, units: array{unitCode: array{code: string, labels: array<string, string>, convert_from_standard: array{operator: string, value: string}, symbol: string}}} $unitMeasurementFamily */
foreach ($unitMeasurementFamilies as $unitMeasurementFamily) {
if (array_key_exists($unitMeasurementCode, $unitMeasurementFamily['units'])) {
return $unitMeasurementFamily;
Expand Down Expand Up @@ -144,7 +143,6 @@ private function doReverseOperations($operationsToDefaultUnitMeasurement, float
private function getOperationsForDefaultFromUnitMeasurement(array $units, string $unitMeasurementCode): array
{
$operationsToDefaultUnitMeasurement = [];
/** @var array{code: string, labels: array<string, string>, convert_from_standard: array{operator: string, value: string}, symbol: string} $unitMeasurement */
foreach ($units as $unitMeasurement) {
if ($unitMeasurement['code'] === $unitMeasurementCode) {
$operationsToDefaultUnitMeasurement = $unitMeasurement['convert_from_standard'];
Expand Down
2 changes: 1 addition & 1 deletion src/Converter/ValueConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function convert(AttributeInterface $attribute, $value, string $localeCod
$possibleOptionsCodes = array_map('strval', array_keys($choices));
$invalid = array_diff($value, $possibleOptionsCodes);

if (!empty($invalid)) {
if (count($invalid) > 0) {
throw new \InvalidArgumentException(
sprintf(
'This select attribute can only save existing attribute options. ' .
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/WebgriffeSyliusAkeneoExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private function addTaggedImportersToRegistry(ContainerBuilder $container): void
$importerRegistryDefinition = $container->findDefinition('webgriffe_sylius_akeneo.importer_registry');

$taggedImporters = $container->findTaggedServiceIds(self::IMPORTER_TAG);
foreach ($taggedImporters as $id => $tags) {
foreach ($taggedImporters as $id => $_tags) {
$importerRegistryDefinition->addMethodCall('add', [new Reference($id)]);
}
}
Expand All @@ -300,7 +300,7 @@ private function addTaggedReconcilersToRegistry(ContainerBuilder $container): vo

/** @var array<string, array> $taggedReconcilers */
$taggedReconcilers = $container->findTaggedServiceIds(self::RECONCILER_TAG);
foreach ($taggedReconcilers as $id => $tags) {
foreach ($taggedReconcilers as $id => $_tags) {
$importerRegistryDefinition->addMethodCall('add', [new Reference($id)]);
}
}
Expand Down
20 changes: 9 additions & 11 deletions src/Product/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function getAkeneoEntity(): string
public function import(string $identifier): void
{
$productVariantResponse = $this->apiClient->findProduct($identifier);
if (!$productVariantResponse) {
if ($productVariantResponse === null) {
throw new \RuntimeException(sprintf('Cannot find product "%s" on Akeneo.', $identifier));
}

Expand Down Expand Up @@ -195,19 +195,18 @@ private function getOrCreateProductFromVariantResponse(array $productVariantResp
$parentCode = $productVariantResponse['parent'];
if ($parentCode !== null) {
$product = $this->productRepository->findOneByCode($parentCode);
if (!$product) {
if ($product === null) {
$product = $this->createNewProductFromAkeneoProduct($productVariantResponse);
}

return $product;
}

$product = $this->productRepository->findOneByCode($identifier);
if (!$product) {
if ($product === null) {
$product = $this->productFactory->createNew();
}
Assert::isInstanceOf($product, ProductInterface::class);
/** @var ProductInterface $product */
$product->setCode($identifier);

return $product;
Expand Down Expand Up @@ -249,10 +248,10 @@ private function handleTaxons(ProductInterface $product, array $akeneoProduct):
{
$akeneoTaxons = new ArrayCollection($this->taxonsResolver->resolve($akeneoProduct));
$syliusTaxons = $product->getTaxons();
$akeneoTaxonsCodes = $akeneoTaxons->map(function (TaxonInterface $taxon) {return $taxon->getCode(); })->toArray();
$syliusTaxonsCodes = $syliusTaxons->map(function (TaxonInterface $taxon) {return $taxon->getCode(); })->toArray();
$akeneoTaxonsCodes = $akeneoTaxons->map(function (TaxonInterface $taxon): ?string {return $taxon->getCode(); })->toArray();
$syliusTaxonsCodes = $syliusTaxons->map(function (TaxonInterface $taxon): ?string {return $taxon->getCode(); })->toArray();
$toAddTaxons = $akeneoTaxons->filter(
function (TaxonInterface $taxon) use ($syliusTaxonsCodes) {
function (TaxonInterface $taxon) use ($syliusTaxonsCodes): bool {
return !in_array($taxon->getCode(), $syliusTaxonsCodes, true);
}
);
Expand Down Expand Up @@ -280,7 +279,6 @@ private function createNewProductFromAkeneoProduct(array $productVariantResponse
$parentCode = $productVariantResponse['parent'];
$product = $this->productFactory->createNew();
Assert::isInstanceOf($product, ProductInterface::class);
/** @var ProductInterface $product */
$product->setCode($parentCode);
foreach ($this->productOptionsResolver->resolve($productVariantResponse) as $productOption) {
$product->addOption($productOption);
Expand Down Expand Up @@ -325,7 +323,7 @@ public function reconcile(array $identifiersToReconcileWith): void
/** @var ProductVariantInterface[] $productVariantsToReconcile */
$productVariantsToReconcile = $this->productVariantRepository->findAll();
/** @var string[] $identifiersToReconcile */
$identifiersToReconcile = array_map(function ($productVariant) {
$identifiersToReconcile = array_map(static function ($productVariant): ?string {
return $productVariant->getCode();
}, $productVariantsToReconcile);

Expand All @@ -334,7 +332,7 @@ public function reconcile(array $identifiersToReconcileWith): void
foreach ($identifiersToDisable as $productVariantIdentifierToDisable) {
/** @var ?ProductVariantInterface $productVariantToDisable */
$productVariantToDisable = $this->productVariantRepository->findOneBy(['code' => $productVariantIdentifierToDisable]);
if (!$productVariantToDisable || !$productVariantToDisable->isEnabled()) {
if ($productVariantToDisable === null || !$productVariantToDisable->isEnabled()) {
continue;
}
$productVariantToDisable->setEnabled(false);
Expand All @@ -343,7 +341,7 @@ public function reconcile(array $identifiersToReconcileWith): void

/** @var ?ProductInterface $product */
$product = $productVariantToDisable->getProduct();
if (!$product || !$product->isEnabled() || count($product->getEnabledVariants()) > 0) {
if ($product === null || !$product->isEnabled() || count($product->getEnabledVariants()) > 0) {
continue;
}

Expand Down
Loading