From ca53679c2876074243861c1158aeec0a54921b9c Mon Sep 17 00:00:00 2001 From: Alexander Shkurko Date: Thu, 29 Mar 2018 15:10:33 +0200 Subject: [PATCH] [FIX] Simplify ternary operators for catalog module --- .../FilterProcessor/ProductCategoryFilter.php | 2 +- app/code/Magento/Catalog/Model/CategoryRepository.php | 2 +- app/code/Magento/Catalog/Model/Product.php | 2 +- app/code/Magento/Catalog/Model/Product/Option/Type/File.php | 2 +- app/code/Magento/Catalog/Model/Product/ProductList/Toolbar.php | 2 +- app/code/Magento/Catalog/Model/Product/Type/Price.php | 2 +- app/code/Magento/Catalog/Model/ProductRepository.php | 2 +- .../FilterProcessor/ProductCategoryFilterTest.php | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Api/SearchCriteria/CollectionProcessor/FilterProcessor/ProductCategoryFilter.php b/app/code/Magento/Catalog/Model/Api/SearchCriteria/CollectionProcessor/FilterProcessor/ProductCategoryFilter.php index e0fbc16421f55..f8cf810ffb570 100644 --- a/app/code/Magento/Catalog/Model/Api/SearchCriteria/CollectionProcessor/FilterProcessor/ProductCategoryFilter.php +++ b/app/code/Magento/Catalog/Model/Api/SearchCriteria/CollectionProcessor/FilterProcessor/ProductCategoryFilter.php @@ -21,7 +21,7 @@ class ProductCategoryFilter implements CustomFilterInterface */ public function apply(Filter $filter, AbstractDb $collection) { - $conditionType = $filter->getConditionType() ? $filter->getConditionType() : 'eq'; + $conditionType = $filter->getConditionType() ?: 'eq'; $categoryFilter = [$conditionType => [$filter->getValue()]]; /** @var Collection $collection */ diff --git a/app/code/Magento/Catalog/Model/CategoryRepository.php b/app/code/Magento/Catalog/Model/CategoryRepository.php index 505c729ac1001..3739b91d2348e 100644 --- a/app/code/Magento/Catalog/Model/CategoryRepository.php +++ b/app/code/Magento/Catalog/Model/CategoryRepository.php @@ -129,7 +129,7 @@ public function save(\Magento\Catalog\Api\Data\CategoryInterface $category) */ public function get($categoryId, $storeId = null) { - $cacheKey = null !== $storeId ? $storeId : 'all'; + $cacheKey = $storeId ?? 'all'; if (!isset($this->instances[$categoryId][$cacheKey])) { /** @var Category $category */ $category = $this->categoryFactory->create(); diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index 75e5f9df23a70..237ac96e56ec6 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -1994,7 +1994,7 @@ public function getIsVirtual() */ public function addCustomOption($code, $value, $product = null) { - $product = $product ? $product : $this; + $product = $product ?: $this; $option = $this->_itemOptionFactory->create()->addData( ['product_id' => $product->getId(), 'product' => $product, 'code' => $code, 'value' => $value] ); diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php index a7304c9b67bb2..26e6a92852720 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php @@ -126,7 +126,7 @@ public function __construct( $this->mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA); $this->validatorInfo = $validatorInfo; $this->validatorFile = $validatorFile; - $this->serializer = $serializer ? $serializer : ObjectManager::getInstance()->get(Json::class); + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); parent::__construct($checkoutSession, $scopeConfig, $data); } diff --git a/app/code/Magento/Catalog/Model/Product/ProductList/Toolbar.php b/app/code/Magento/Catalog/Model/Product/ProductList/Toolbar.php index c2046bea550e6..af0772251e235 100644 --- a/app/code/Magento/Catalog/Model/Product/ProductList/Toolbar.php +++ b/app/code/Magento/Catalog/Model/Product/ProductList/Toolbar.php @@ -102,6 +102,6 @@ public function getLimit() public function getCurrentPage() { $page = (int) $this->request->getParam(self::PAGE_PARM_NAME); - return $page ? $page : 1; + return $page ?: 1; } } diff --git a/app/code/Magento/Catalog/Model/Product/Type/Price.php b/app/code/Magento/Catalog/Model/Product/Type/Price.php index aa28a3478ebf7..7eaedf77eb859 100644 --- a/app/code/Magento/Catalog/Model/Product/Type/Price.php +++ b/app/code/Magento/Catalog/Model/Product/Type/Price.php @@ -341,7 +341,7 @@ public function getTierPrice($qty, $product) } } - return $prices ? $prices : []; + return $prices ?: []; } /** diff --git a/app/code/Magento/Catalog/Model/ProductRepository.php b/app/code/Magento/Catalog/Model/ProductRepository.php index 57b7c8cc53478..b34f7761f9c25 100644 --- a/app/code/Magento/Catalog/Model/ProductRepository.php +++ b/app/code/Magento/Catalog/Model/ProductRepository.php @@ -619,7 +619,7 @@ protected function addFilterGroupToCollection( $fields = []; $categoryFilter = []; foreach ($filterGroup->getFilters() as $filter) { - $conditionType = $filter->getConditionType() ? $filter->getConditionType() : 'eq'; + $conditionType = $filter->getConditionType() ?: 'eq'; if ($filter->getField() == 'category_id') { $categoryFilter[$conditionType][] = $filter->getValue(); diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Api/SearchCriteria/CollectionProcessor/FilterProcessor/ProductCategoryFilterTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Api/SearchCriteria/CollectionProcessor/FilterProcessor/ProductCategoryFilterTest.php index f667638cc4da8..942a87ce3414f 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Api/SearchCriteria/CollectionProcessor/FilterProcessor/ProductCategoryFilterTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Api/SearchCriteria/CollectionProcessor/FilterProcessor/ProductCategoryFilterTest.php @@ -31,7 +31,7 @@ public function testApply() ->disableOriginalConstructor() ->getMock(); - $filterMock->expects($this->exactly(2)) + $filterMock->expects($this->exactly(1)) ->method('getConditionType') ->willReturn('condition'); $filterMock->expects($this->once())