Skip to content

Commit

Permalink
Simplify ternary operators for catalog module
Browse files Browse the repository at this point in the history
  • Loading branch information
coderimus authored and Mastiuhin Oleksandr committed Apr 3, 2018
1 parent 5a7c3bd commit a9e4308
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Model/CategoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,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]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Model/Product/Type/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public function getTierPrice($qty, $product)
}
}

return $prices ? $prices : [];
return $prices ?: [];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Model/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit a9e4308

Please sign in to comment.