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

Clean code #16841

Merged
merged 5 commits into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/code/Magento/Analytics/ReportXml/ReportProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(
private function getIteratorName(Query $query)
{
$config = $query->getConfig();
return isset($config['iterator']) ? $config['iterator'] : null;
return $config['iterator'] ?? null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/App/DefaultPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public function __construct(\Magento\Backend\App\ConfigInterface $config)
*/
public function getPart($code)
{
return isset($this->_parts[$code]) ? $this->_parts[$code] : null;
return $this->_parts[$code] ?? null;
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Model/Menu/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ public function getResult(\Magento\Backend\Model\Menu $menu)
*/
protected function _getParam($params, $paramName, $defaultValue = null)
{
return isset($params[$paramName]) ? $params[$paramName] : $defaultValue;
return $params[$paramName]?? $defaultValue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add space before ??

}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Backup/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function getBackupsDir()
public function getExtensionByType($type)
{
$extensions = $this->getExtensions();
return isset($extensions[$type]) ? $extensions[$type] : '';
return $extensions[$type] ?? '';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ function ($title, $storeName) {
*/
protected function getTypeValue($type)
{
return isset($this->typeMapping[$type]) ? $this->typeMapping[$type] : self::VALUE_DYNAMIC;
return $this->typeMapping[$type]?? self::VALUE_DYNAMIC;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Please add space before ??
  2. Remove 2nd space after ??

}

/**
Expand All @@ -332,7 +332,7 @@ protected function getTypeValue($type)
*/
protected function getPriceViewValue($type)
{
return isset($this->priceViewMapping[$type]) ? $this->priceViewMapping[$type] : self::VALUE_PRICE_RANGE;
return $this->priceViewMapping[$type] ?? self::VALUE_PRICE_RANGE;
}

/**
Expand All @@ -343,7 +343,7 @@ protected function getPriceViewValue($type)
*/
protected function getPriceTypeValue($type)
{
return isset($this->priceTypeMapping[$type]) ? $this->priceTypeMapping[$type] : null;
return $this->priceTypeMapping[$type] ?? null;
}

/**
Expand All @@ -354,7 +354,7 @@ protected function getPriceTypeValue($type)
*/
private function getShipmentTypeValue($type)
{
return isset($this->shipmentTypeMapping[$type]) ? $this->shipmentTypeMapping[$type] : null;
return $this->shipmentTypeMapping[$type] ?? null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public function resolve(\Magento\Framework\App\RequestInterface $request, $formI
{
$captchaParams = $request->getPost(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE);

return isset($captchaParams[$formId]) ? $captchaParams[$formId] : '';
return $captchaParams[$formId] ?? '';
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Block/Product/View/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function getImageAttribute($imageId, $attributeName, $default = null)
{
$attributes =
$this->getConfigView()->getMediaAttributes('Magento_Catalog', Image::MEDIA_TYPE_CONFIG_NODE, $imageId);
return isset($attributes[$attributeName]) ? $attributes[$attributeName] : $default;
return $attributes[$attributeName] ?? $default;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions app/code/Magento/Catalog/Cron/FrontendActionsFlush.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ private function getLifeTimeByNamespace($namespace)
];
}

return isset($configuration['lifetime']) ?
(int) $configuration['lifetime'] : FrontendStorageConfigurationInterface::DEFAULT_LIFETIME;
return (int)$configuration['lifetime'] ?? FrontendStorageConfigurationInterface::DEFAULT_LIFETIME;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Helper/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ public function getFrame()
*/
protected function getAttribute($name)
{
return isset($this->attributes[$name]) ? $this->attributes[$name] : null;
return $this->attributes[$name]?? : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Please add space there before ??
  2. Looks like there should not be :

}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Helper/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function addHandler($method, $handler)
public function getHandlers($method)
{
$method = strtolower($method);
return isset($this->_handlers[$method]) ? $this->_handlers[$method] : [];
return $this->_handlers[$method] ?? : [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove : (and space hear it)

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private function mapConditionType(string $conditionType, string $field): string
];
}

return isset($conditionsMap[$conditionType]) ? $conditionsMap[$conditionType] : $conditionType;
return $conditionsMap[$conditionType] ?? $conditionType;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public function getProductTypeName($id)

$this->loadProductTypes();

return isset($this->_productTypesById[$id]) ? $this->_productTypesById[$id] : false;
return $this->_productTypesById[$id] ?? false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Model/Product/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public function getGroupByType($type = null)
self::OPTION_TYPE_TIME => self::OPTION_GROUP_DATE,
];

return isset($optionGroupsToTypes[$type]) ? $optionGroupsToTypes[$type] : '';
return $optionGroupsToTypes[$type] ?? : '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove : (and space near it)

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public function getFormattedOptionValue($optionValue)
*/
public function getCustomizedView($optionInfo)
{
return isset($optionInfo['value']) ? $optionInfo['value'] : $optionInfo;
return $optionInfo['value'] ?? $optionInfo;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public function __construct(array $validators)
*/
public function get($type)
{
return isset($this->validators[$type]) ? $this->validators[$type] : $this->validators['default'];
return $this->validators[$type] ?? $this->validators['default'];
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Model/Product/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function getOptions()
public function getOptionText($optionId)
{
$options = $this->getOptionArray();
return isset($options[$optionId]) ? $options[$optionId] : null;
return $options[$optionId] ?? null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ private function mapConditionType($conditionType)
'eq' => 'in',
'neq' => 'nin'
];
return isset($conditionsMap[$conditionType]) ? $conditionsMap[$conditionType] : $conditionType;
return $conditionsMap[$conditionType] ?? $conditionType;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove 2nd space after ??

}

/**
Expand Down
4 changes: 1 addition & 3 deletions app/code/Magento/Catalog/Ui/Component/FilterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ public function create($attribute, $context, $config = [])
*/
protected function getFilterType($attribute)
{
return isset($this->filterMap[$attribute->getFrontendInput()])
? $this->filterMap[$attribute->getFrontendInput()]
: $this->filterMap['default'];
return $this->filterMap[$attribute->getFrontendInput()] ?? $this->filterMap['default'];
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Ui/Component/Listing/Columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ public function prepare()
*/
protected function getFilterType($frontendInput)
{
return isset($this->filterMap[$frontendInput]) ? $this->filterMap[$frontendInput] : $this->filterMap['default'];
return $this->filterMap[$frontendInput] ?? $this->filterMap['default'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove 2nd space after ??

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ private function getFormElementsMapValue($value)
{
$valueMap = $this->formElementMapper->getMappings();

return isset($valueMap[$value]) ? $valueMap[$value] : $value;
return $valueMap[$value] ?? $value;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function clearFailedCategories()
*/
public function getCategoryById($categoryId)
{
return isset($this->categoriesCache[$categoryId]) ? $this->categoriesCache[$categoryId] : null;
return $this->categoriesCache[$categoryId] ?? null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function getNewSku($sku = null)
{
if ($sku !== null) {
$sku = strtolower($sku);
return isset($this->newSkus[$sku]) ? $this->newSkus[$sku] : null;
return $this->newSkus[$sku] ?? null;
}
return $this->newSkus;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function getWebsiteCodeToId($code = null)
$this->_initWebsites();
}
if ($code) {
return isset($this->websiteCodeToId[$code]) ? $this->websiteCodeToId[$code] : null;
return $this->websiteCodeToId[$code] ?? null;
}
return $this->websiteCodeToId;
}
Expand All @@ -90,7 +90,7 @@ public function getWebsiteCodeToStoreIds($code = null)
$this->_initWebsites();
}
if ($code) {
return isset($this->websiteCodeToStoreIds[$code]) ? $this->websiteCodeToStoreIds[$code] : null;
return $this->websiteCodeToStoreIds[$code] ?? null;
}
return $this->websiteCodeToStoreIds;
}
Expand Down Expand Up @@ -119,7 +119,7 @@ public function getStoreCodeToId($code = null)
$this->_initStores();
}
if ($code) {
return isset($this->storeCodeToId[$code]) ? $this->storeCodeToId[$code] : null;
return $this->storeCodeToId[$code] ?? null;
}
return $this->storeCodeToId;
}
Expand All @@ -134,7 +134,7 @@ public function getStoreIdToWebsiteStoreIds($code = null)
$this->_initStores();
}
if ($code) {
return isset($this->storeIdToWebsiteStoreIds[$code]) ? $this->storeIdToWebsiteStoreIds[$code] : null;
return $this->storeIdToWebsiteStoreIds[$code] ?? null;
}
return $this->storeIdToWebsiteStoreIds;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function _getCustomerGroups($groupId = null)
$this->_customerGroups[$notLoggedInGroup->getId()] = $notLoggedInGroup->getCode();
}
if ($groupId !== null) {
return isset($this->_customerGroups[$groupId]) ? $this->_customerGroups[$groupId] : null;
return $this->_customerGroups[$groupId] ?? null;
}
return $this->_customerGroups;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function removeStock($scopeId = null)
*/
public function getStockItem($productId, $scopeId)
{
return isset($this->stockItems[$productId][$scopeId]) ? $this->stockItems[$productId][$scopeId] : null;
return $this->stockItems[$productId][$scopeId] ?? null;
}

/**
Expand Down Expand Up @@ -103,7 +103,7 @@ public function removeStockItem($productId, $scopeId = null)
*/
public function getStockStatus($productId, $scopeId)
{
return isset($this->stockStatuses[$productId][$scopeId]) ? $this->stockStatuses[$productId][$scopeId] : null;
return $this->stockStatuses[$productId][$scopeId] ?? null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RulePricesStorage
*/
public function getRulePrice($id)
{
return isset($this->rulePrices[$id]) ? $this->rulePrices[$id] : false;
return $this->rulePrices[$id]) ?? false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/Magento/Framework/DataObject/Copy/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public function getFieldset($name, $root = 'global')
if (empty($fieldsets)) {
return null;
}
return isset($fieldsets[$name]) ? $fieldsets[$name] : null;
return $fieldsets[$name] ?? null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove 2nd space after ??

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,6 @@ public function populateWithArray(array $data)
*/
private function getArrayValueByKey($key, array $array)
{
return isset($array[$key]) ? $array[$key] : [];
return $array[$key] ?? [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove 2nd space after ??

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function postprocessing($content)
return preg_replace_callback(
'#' . $patternTag . '(.+?)' . $patternTag . '#',
function ($match) {
return isset($this->data[$match[1]]) ? $this->data[$match[1]] : '';
return $this->data[$match[1]] ?? '';
},
$content
);
Expand Down
4 changes: 2 additions & 2 deletions setup/src/Magento/Setup/Fixtures/ImagesFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ private function getImagesToGenerate()
{
$config = $this->fixtureModel->getValue('product-images', []);

return isset($config['images-count']) ? $config['images-count'] : null;
return $config['images-count'] ?? null;
}

/**
Expand All @@ -429,7 +429,7 @@ private function getImagesPerProduct()
{
$config = $this->fixtureModel->getValue('product-images', []);

return isset($config['images-per-product']) ? $config['images-per-product'] : null;
return $config['images-per-product'] ?? null;
}

/**
Expand Down
8 changes: 2 additions & 6 deletions setup/src/Magento/Setup/Module/Setup/SetupCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,9 @@ public function setField($table, $parentId, $rowId, $field, $value)
public function get($table, $parentId, $rowId, $field = null)
{
if (null === $field) {
return isset($this->data[$table][$parentId][$rowId]) ?
$this->data[$table][$parentId][$rowId] :
false;
return $this->data[$table][$parentId][$rowId]) ?? false;
} else {
return isset($this->data[$table][$parentId][$rowId][$field]) ?
$this->data[$table][$parentId][$rowId][$field] :
false;
return $this->data[$table][$parentId][$rowId][$field] ?? false;
}
}

Expand Down