Skip to content

Commit

Permalink
Merge pull request #63 from synolia/fix/ecs
Browse files Browse the repository at this point in the history
fix ecs
  • Loading branch information
TheGrimmChester authored Apr 24, 2021
2 parents a954888 + fd135de commit 1bb2d0c
Show file tree
Hide file tree
Showing 61 changed files with 216 additions and 120 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
}
},
"scripts": {
"fix-ecs": "ecs check -c ruleset/easy-coding-standard.yml --fix --ansi --clear-cache .",
"fix-ecs": "ecs check -c ruleset/ecs.php --fix --ansi --clear-cache",
"patch" : "php bin/patch"
}
}
14 changes: 13 additions & 1 deletion ruleset/ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(dirname(__DIR__) . '/vendor/sylius-labs/coding-standard/ecs.php');
Expand All @@ -13,6 +14,17 @@
dirname(__DIR__, 1) . '/src',
dirname(__DIR__, 1) . '/tests/Behat',
dirname(__DIR__, 1) . '/tests/PHPUnit',
dirname(__DIR__, 1) . '/spec'
dirname(__DIR__, 1) . '/spec',
]);

$parameters->set(Option::SETS, [
SetList::SYMFONY,
SetList::PHP_73_MIGRATION,
SetList::PHP_CS_FIXER,
]);
$parameters->set(Option::SKIP, [
PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer::class => [
dirname(__DIR__, 1) . '/src/*/*Configuration*.php',
]
]);
};
2 changes: 1 addition & 1 deletion src/Configuration/SettingConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Symfony\Component\Config\Definition\Exception\InvalidTypeException;

/**
* Class SettingConfiguration
* Class SettingConfiguration.
*/
final class SettingConfiguration implements ConfigurationInterface
{
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __invoke(Request $request): Response
if ($this->categoriesConfigurationRepository instanceof CategoryConfigurationRepository) {
$categoriesConfigurations = $this->categoriesConfigurationRepository->getCategoriesConfiguration();
}
if ($categoriesConfigurations === null) {
if (null === $categoriesConfigurations) {
$categoriesConfigurations = new CategoryConfiguration();
}

Expand All @@ -75,8 +75,8 @@ public function __invoke(Request $request): Response
}

return $this->render('@SynoliaSyliusAkeneoPlugin/Admin/AkeneoConnector/categories.html.twig', [
'form' => $form->createView(),
]
'form' => $form->createView(),
]
);
}
}
2 changes: 1 addition & 1 deletion src/Controller/ProductFilterRulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __invoke(Request $request): Response
}

$productFiltersRules = $this->productFiltersRulesRepository->getProductFiltersRules();
if ($productFiltersRules === null) {
if (null === $productFiltersRules) {
$productFiltersRules = new ProductFiltersRules();
}

Expand Down
6 changes: 3 additions & 3 deletions src/Controller/ProductsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ public function __invoke(Request $request): Response
}

return $this->render('@SynoliaSyliusAkeneoPlugin/Admin/AkeneoConnector/products_configuration.html.twig', [
'form' => $form->createView(),
]
'form' => $form->createView(),
]
);
}

private function removeElements(?Collection $productConfiguration, ?Collection $productConfigurationData): void
{
if ($productConfiguration === null || $productConfigurationData === null) {
if (null === $productConfiguration || null === $productConfigurationData) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Entity/CategoryConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* @ORM\Entity(repositoryClass="CategoryConfigurationRepository")
*
* @ORM\Table("akeneo_api_configuration_categories")
*/
class CategoryConfiguration implements ResourceInterface
Expand Down
30 changes: 15 additions & 15 deletions src/Filter/ProductFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public function getProductModelFilters(): array
}

$queryParameters = [];
if ($productFilterRules->getMode() === ProductFilterRuleSimpleType::MODE) {
if (ProductFilterRuleSimpleType::MODE === $productFilterRules->getMode()) {
$queryParameters = new SearchBuilder();

$queryParameters = $this->getUpdatedFilter($productFilterRules, $queryParameters);

$completeness = self::AT_LEAST_COMPLETE;
if ($productFilterRules->getCompletenessValue() === self::FULL_COMPLETE) {
if (self::FULL_COMPLETE === $productFilterRules->getCompletenessValue()) {
$completeness = self::ALL_COMPLETE;
}
$this->getCompletenessFilter($productFilterRules, $queryParameters, $completeness);
Expand All @@ -68,7 +68,7 @@ public function getProductModelFilters(): array
$queryParameters = ['search' => $queryParameters, 'scope' => $productFilterRules->getChannel()];
}

if ($productFilterRules->getMode() === ProductFilterRuleAdvancedType::MODE && !empty($productFilterRules->getAdvancedFilter())) {
if (ProductFilterRuleAdvancedType::MODE === $productFilterRules->getMode() && !empty($productFilterRules->getAdvancedFilter())) {
return $this->getAdvancedFilter($productFilterRules, true);
}

Expand All @@ -84,7 +84,7 @@ public function getProductFilters(): array
}

$queryParameters = [];
if ($productFilterRules->getMode() === ProductFilterRuleSimpleType::MODE) {
if (ProductFilterRuleSimpleType::MODE === $productFilterRules->getMode()) {
$queryParameters = new SearchBuilder();

$queryParameters = $this->getUpdatedFilter($productFilterRules, $queryParameters);
Expand All @@ -101,7 +101,7 @@ public function getProductFilters(): array
$queryParameters = ['search' => $queryParameters, 'scope' => $productFilterRules->getChannel()];
}

if ($productFilterRules->getMode() === ProductFilterRuleAdvancedType::MODE && !empty($productFilterRules->getAdvancedFilter())) {
if (ProductFilterRuleAdvancedType::MODE === $productFilterRules->getMode() && !empty($productFilterRules->getAdvancedFilter())) {
return $this->getAdvancedFilter($productFilterRules);
}

Expand All @@ -111,20 +111,20 @@ public function getProductFilters(): array
private function getStatus(ProductFiltersRules $productFilterRules, SearchBuilder $queryParameters): SearchBuilder
{
$status = $productFilterRules->getStatus();
if ($status === ProductFilterStatusEnum::NO_CONDITION) {
if (ProductFilterStatusEnum::NO_CONDITION === $status) {
return $queryParameters;
}

return $queryParameters->addFilter(
'enabled',
Operator::EQUAL,
$status === ProductFilterStatusEnum::ENABLED
ProductFilterStatusEnum::ENABLED === $status
);
}

private function getAdvancedFilter(ProductFiltersRules $productFilterRules, bool $isProductModelFilter = false): array
{
if ($productFilterRules->getAdvancedFilter() === null) {
if (null === $productFilterRules->getAdvancedFilter()) {
return [];
}

Expand All @@ -134,7 +134,7 @@ private function getAdvancedFilter(ProductFiltersRules $productFilterRules, bool
}

$advancedFilter['search'] = json_decode($advancedFilter['search'], true);
if ($isProductModelFilter === true) {
if (true === $isProductModelFilter) {
return $this->getProductModelAdvancedFilter($advancedFilter);
}

Expand All @@ -144,7 +144,7 @@ private function getAdvancedFilter(ProductFiltersRules $productFilterRules, bool
private function getProductModelCompletenessTypeAdvancedFilter(array $filter): array
{
$filter['search']['completeness'][0]['operator'] = self::AT_LEAST_COMPLETE;
if ($filter['search']['completeness'][0]['value'] === self::FULL_COMPLETE) {
if (self::FULL_COMPLETE === $filter['search']['completeness'][0]['value']) {
$filter['search']['completeness'][0]['operator'] = self::ALL_COMPLETE;
}
unset($filter['search']['completeness'][0]['value']);
Expand All @@ -168,21 +168,21 @@ private function getProductModelAdvancedFilter(array $advancedFilter): array
private function getUpdatedFilter(ProductFiltersRules $productFilterRules, SearchBuilder $queryParameters): SearchBuilder
{
$updatedMode = $productFilterRules->getUpdatedMode();
if ($updatedMode === Operator::GREATER_THAN) {
if (Operator::GREATER_THAN === $updatedMode) {
$queryParameters->addFilter(
'updated',
$updatedMode,
$productFilterRules->getUpdatedAfter()->format(self::API_DATETIME_FORMAT)
);
}
if ($updatedMode === Operator::LOWER_THAN) {
if (Operator::LOWER_THAN === $updatedMode) {
$queryParameters->addFilter(
'updated',
$updatedMode,
$productFilterRules->getUpdatedBefore()->format(self::API_DATETIME_FORMAT)
);
}
if ($updatedMode === Operator::BETWEEN) {
if (Operator::BETWEEN === $updatedMode) {
$queryParameters->addFilter(
'updated',
$updatedMode,
Expand All @@ -192,7 +192,7 @@ private function getUpdatedFilter(ProductFiltersRules $productFilterRules, Searc
]
);
}
if ($updatedMode === Operator::SINCE_LAST_N_DAYS) {
if (Operator::SINCE_LAST_N_DAYS === $updatedMode) {
$queryParameters->addFilter(
'updated',
$updatedMode,
Expand Down Expand Up @@ -237,7 +237,7 @@ private function getCompletenessFilter(
?int $completenessValue = null
): SearchBuilder {
$completenessType = $productFilterRules->getCompletenessType();
if ($completeness === null || $completenessType === null) {
if (null === $completeness || null === $completenessType) {
return $queryParameters;
}

Expand Down
7 changes: 2 additions & 5 deletions src/Manager/ProductOptionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ public function __construct(

public function getProductOptionFromAttribute(AttributeInterface $attribute): ?ProductOptionInterface
{
/** @var ProductOptionInterface|null $productOption */
$productOption = $this->productOptionRepository->findOneBy(['code' => $attribute->getCode()]);

return $productOption;
return $this->productOptionRepository->findOneBy(['code' => $attribute->getCode()]);
}

public function createProductOptionFromAttribute(AttributeInterface $attribute): ProductOptionInterface
Expand Down Expand Up @@ -156,7 +153,7 @@ private function getLocales(): iterable

private function updateProductOptionValues(ProductOptionInterface $productOption, AttributeInterface $attribute): void
{
if ($attribute->getType() !== SelectAttributeType::TYPE) {
if (SelectAttributeType::TYPE !== $attribute->getType()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Manager/SettingsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(EntityManagerInterface $entityManager)
}

/**
* Return setting value by its name
* Return setting value by its name.
*
* @param mixed|null $default Value to return if the setting is not set
*
Expand Down
4 changes: 2 additions & 2 deletions src/Manager/SettingsManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
interface SettingsManagerInterface
{
/**
* Return setting value by its name
* Return setting value by its name.
*
* @param mixed|null $default Value to return if the setting is not set
*
Expand All @@ -21,7 +21,7 @@ public function get(string $name, $default = null);
public function set(string $name, $value): self;

/**
* Clears setting value
* Clears setting value.
*/
public function clear(string $name): self;
}
20 changes: 10 additions & 10 deletions src/Menu/AdminMenuListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,40 @@ public function addAdminMenuItems(MenuBuilderEvent $event): void
$newSubmenu = $menu->addChild('akeneo');

$newSubmenu->addChild('sylius_admin_akeneo_api_configuration', [
'route' => 'sylius_akeneo_connector_api_configuration',
])
'route' => 'sylius_akeneo_connector_api_configuration',
])
->setAttribute('type', 'link')
->setLabel('sylius.ui.admin.akeneo.api_configuration.title')
->setLabelAttribute('icon', 'cogs')
;

$newSubmenu->addChild('sylius_admin_akeneo_product_filter_rules', [
'route' => 'sylius_akeneo_connector_product_filter_rules',
])
'route' => 'sylius_akeneo_connector_product_filter_rules',
])
->setAttribute('type', 'link')
->setLabel('sylius.ui.admin.akeneo.product_filter_rules.title')
->setLabelAttribute('icon', 'sync alternate')
;

$newSubmenu->addChild('sylius_admin_akeneo_categories', [
'route' => 'sylius_akeneo_connector_categories',
])
'route' => 'sylius_akeneo_connector_categories',
])
->setAttribute('type', 'link')
->setLabel('sylius.ui.admin.akeneo.categories.title')
->setLabelAttribute('icon', 'configure')
;

$newSubmenu->addChild('sylius_admin_akeneo_products', [
'route' => 'sylius_akeneo_connector_products',
])
'route' => 'sylius_akeneo_connector_products',
])
->setAttribute('type', 'link')
->setLabel('sylius.ui.admin.akeneo.products.title')
->setLabelAttribute('icon', 'configure')
;

$newSubmenu->addChild('sylius_admin_akeneo_attributes', [
'route' => 'sylius_akeneo_connector_attributes',
])
'route' => 'sylius_akeneo_connector_attributes',
])
->setAttribute('type', 'link')
->setLabel('sylius.ui.admin.akeneo.attributes.title')
->setLabelAttribute('icon', 'configure')
Expand Down
4 changes: 2 additions & 2 deletions src/Migrations/Version20200605081308.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function getDescription(): string
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('CREATE TABLE akeneo_api_configuration_product (
id INT AUTO_INCREMENT NOT NULL,
Expand Down Expand Up @@ -135,7 +135,7 @@ public function up(Schema $schema): void
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE
akeneo_api_configuration_product_images_mapping
Expand Down
4 changes: 2 additions & 2 deletions src/Migrations/Version20201028081617.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public function getDescription(): string
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE akeneo_api_configuration DROP token, DROP refreshToken');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE
akeneo_api_configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public function process(string $attributeCode, array $context = []): void
));

foreach ($context['data'] as $translation) {
if ($translation['locale'] !== null
&& $this->syliusAkeneoLocaleCodeProvider->isActiveLocale($translation['locale']) === false) {
if (null !== $translation['locale']
&& false === $this->syliusAkeneoLocaleCodeProvider->isActiveLocale($translation['locale'])) {
continue;
}

if ($translation['locale'] === null) {
if (null === $translation['locale']) {
foreach ($this->syliusAkeneoLocaleCodeProvider->getUsedLocalesOnBothPlatforms() as $locale) {
$this->setValueToMethod($context['model'], $attributeCode, $context['data'], $locale, $context['scope']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ public function process(string $attributeCode, array $context = []): void
$attribute = $this->productAttributeRepository->findOneBy(['code' => $transformedAttributeCode]);

foreach ($context['data'] as $translation) {
if ($translation['locale'] !== null && $this->syliusAkeneoLocaleCodeProvider->isActiveLocale($translation['locale']) === false) {
if (null !== $translation['locale'] && false === $this->syliusAkeneoLocaleCodeProvider->isActiveLocale($translation['locale'])) {
continue;
}

if ($translation['locale'] === null) {
if (null === $translation['locale']) {
foreach ($this->syliusAkeneoLocaleCodeProvider->getUsedLocalesOnBothPlatforms() as $locale) {
$this->setAttributeTranslation(
$context['model'],
Expand Down
Loading

0 comments on commit 1bb2d0c

Please sign in to comment.