Skip to content

Commit

Permalink
Analyse code style with phpmd command
Browse files Browse the repository at this point in the history
  • Loading branch information
cemag44 authored and cemag44300 committed Oct 19, 2022
1 parent 7a8696d commit debdf0c
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Block/Entity/Attribute/CustomEntity/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class Renderer extends Template
*/
public function getTemplate(): string
{
return parent::getTemplate() ?? 'Smile_CustomEntityProductLink::entity/attribute/custom_entity/renderer.phtml';
return 'Smile_CustomEntityProductLink::entity/attribute/custom_entity/renderer.phtml';
}
}
12 changes: 7 additions & 5 deletions Helper/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ public function __construct(
public function getCustomEntities(ProductInterface $product, string $attributeCode): array
{
$result = [];
$customEntities = $product->getExtensionAttributes()->getCustomEntities() ?? [];
foreach ($customEntities as $customEntity) {
if ($customEntity->getProductAttributeCode() !== $attributeCode || !$customEntity->getIsActive()) {
continue;
$customEntities = $product->getExtensionAttributes()->getCustomEntities();
if ($customEntities) {
foreach ($customEntities as $customEntity) {
if ($customEntity->getProductAttributeCode() !== $attributeCode || !$customEntity->getIsActive()) {
continue;
}
$result[] = $customEntity;
}
$result[] = $customEntity;
}

return $result;
Expand Down
11 changes: 3 additions & 8 deletions Model/Layer/CustomEntity/CollectionFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
use Magento\Catalog\Model\Layer\Category\CollectionFilter as BaseCollectionFilter;
use Magento\Catalog\Model\Layer\CollectionFilterInterface;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Framework\Registry;
use Smile\CustomEntity\Api\Data\CustomEntityInterface;
use Smile\CustomEntityProductLink\Helper\Product as ProductHelper;
use Smile\ElasticsuiteCore\Helper\Mapping;
use Smile\ElasticsuiteCore\Search\Request\Query\QueryFactory;
use Smile\ElasticsuiteCore\Search\Request\QueryInterface;

Expand All @@ -35,7 +33,7 @@ class CollectionFilter extends BaseCollectionFilter implements CollectionFilterI
* @param Config $catalogConfig Catalog config.
* @param ProductHelper $productHelper Product helper.
* @param Registry $registry Registry.
* @param Mapping $mappingHelper Mapping helper.
* @param QueryFactory $queryFactory Query factory.
*/
public function __construct(
Visibility $productVisibility,
Expand All @@ -51,12 +49,9 @@ public function __construct(
}

/**
* Filter product collection.
*
* @param Collection $collection Collection.
* @param Category $category Category.
* @inheritdoc
*/
public function filter(Collection $collection, Category $category): void
public function filter($collection, Category $category): void
{
parent::filter($collection, $category);
$currentCustomEntity = $this->getCurrentCustomEntity();
Expand Down
10 changes: 3 additions & 7 deletions Model/Product/Indexer/Fulltext/Datasource/CustomEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,9 @@ public function __construct(
}

/**
* Append data to a list of documents.
*
* @param int $storeId Store id.
* @param array $indexData List of documents to get enriched by the datasources.
* @return array
* @inheritdoc
*/
public function addData(int $storeId, array $indexData): array
public function addData($storeId, array $indexData): array
{
$productIds = array_keys($indexData);
$customEntitiesData = $this->loadCustomEntityRowData($storeId, $productIds, array_keys($this->attributeById));
Expand Down Expand Up @@ -150,7 +146,7 @@ private function addField(AttributeInterface $attribute): self
$fieldConfig['is_used_in_spellcheck'] = false;
$fieldConfig['is_searchable'] = false;

$fieldType = $this->attributeHelper->getFieldType($attribute);
$fieldType = $this->attributeHelper->getFieldType($attribute);
$fieldOptions = ['name' => $fieldName, 'type' => $fieldType, 'fieldConfig' => $fieldConfig];

$this->fields[$fieldName] = $this->fieldFactory->create($fieldOptions);
Expand Down
2 changes: 1 addition & 1 deletion Model/ResourceModel/CustomEntityProductLinkManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Custom entity product link management resource model.
*/
class CustomEntityProductLinkManagement extends AbstractDb
abstract class CustomEntityProductLinkManagement extends AbstractDb
{
public const RELATION_TABLE_NAME = 'catalog_product_custom_entity_link';

Expand Down
9 changes: 3 additions & 6 deletions Model/ResourceModel/Search/CustomCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ protected function _getAttributesCollection(): AbstractDb
}

/**
* Add the smile custom entities sql request
*
* @param mixed $query Query
* @param bool $searchOnlyInCurrentStore Search only in current store or in all stores
* @inheritdoc
*/
protected function _getSearchEntityIdsSql($query, bool $searchOnlyInCurrentStore = true): string
protected function _getSearchEntityIdsSql($query, $searchOnlyInCurrentStore = true)
{
$sql = parent::_getSearchEntityIdsSql($query, $searchOnlyInCurrentStore);

Expand Down Expand Up @@ -71,8 +68,8 @@ protected function _getSmileCustomSql($query): ?array
$smileCustomEntityAttributeIds[] = $attribute->getId();
}

$selects = [];
if ($smileCustomEntityAttributeIds) {
$selects = [];
$selects[] = $this->getConnection()->select()->from(
['cpe' => 'catalog_product_entity'],
$this->getEntity()->getLinkField()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function execute(Observer $observer): void
/**
* Return attribute codes.
*
* @return array|null
* @return array
*/
private function getCustomEntityAttributeCodes(): ?array
private function getCustomEntityAttributeCodes(): array
{
return array_map(function ($attribute) {
return $attribute->getAttributeCode();
Expand Down
13 changes: 7 additions & 6 deletions Plugin/Block/Product/ListProductPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Block\Product\ListProduct;
use Smile\CustomEntity\Api\Data\CustomEntityInterface;

/**
* List product block plugin.
Expand All @@ -24,11 +23,13 @@ public function afterGetIdentities(ListProduct $source, array $identities): ?arr
{
/** @var ProductInterface $product */
foreach ($source->getLoadedProductCollection() as $product) {
$customEntities = $product->getExtensionAttributes()->getCustomEntities() ?? [];
/** @var CustomEntityInterface $customEntity */
foreach ($customEntities as $customEntity) {
// @codingStandardsIgnoreLine
$identities = array_merge($identities, $customEntity->getIdentities());
$customEntities = $product->getExtensionAttributes()->getCustomEntities();
$identities = [];
if ($customEntities) {
foreach ($customEntities as $customEntity) {
// @codingStandardsIgnoreLine
$identities = array_merge($identities, $customEntity->getIdentities());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public function __construct(EntityCollectionFactory $entityCollectionFactory, Ar
/**
* Fix custom entity field meta.
*
* @param EavModifier $subject Object.
* @param callable $proceed Original method.
* @param EavModifier $subject Object.
* @param callable $proceed Original method.
* @param ProductAttributeInterface $attribute Attribute.
* @param string $groupCode Group code.
* @param int $sortOrder Sort order.
* @param string $groupCode Group code.
* @param int $sortOrder Sort order.
* @return array|null
*/
public function aroundSetupAttributeMeta(
Expand Down Expand Up @@ -77,9 +77,9 @@ public function aroundSetupAttributeMeta(
* List of custom entities.
*
* @param ProductAttributeInterface $attribute Attribute.
* @return array|null
* @return array
*/
private function getOptions(ProductAttributeInterface $attribute): ?array
private function getOptions(ProductAttributeInterface $attribute): array
{
$attributeSetId = $attribute->getCustomEntityAttributeSetId();

Expand Down
3 changes: 2 additions & 1 deletion Plugin/Helper/AbstractAttributePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Smile\CustomEntityProductLink\Plugin\Helper;

use Magento\Eav\Model\Entity\Attribute\AttributeInterface;
use Smile\CustomEntity\Model\CustomEntity;
use Smile\ElasticsuiteCatalog\Helper\ProductAttribute;

/**
Expand All @@ -21,7 +22,7 @@ class AbstractAttributePlugin
*/
public function afterGetFilterField(ProductAttribute $source, string $field, AttributeInterface $attribute): ?string
{
if ($attribute->getFrontendInput() == 'smile_custom_entity') {
if ($attribute->getFrontendInput() == CustomEntity::CACHE_TAG) {
$field = $source->getOptionTextFieldName($field);
}

Expand Down
4 changes: 2 additions & 2 deletions Plugin/Model/ProductPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public function __construct(Data $helper)
/**
* Append custom entity identities when update product attributes.
*
* @param Product $source Product model.
* @param array $identities Identities.
* @param Product $source Product model.
* @param array $identities Identities.
* @return array|null
*/
public function afterGetIdentities(Product $source, array $identities): ?array
Expand Down

0 comments on commit debdf0c

Please sign in to comment.