Skip to content

Clean up 'isset' coding style #26772

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

Merged
Merged
2 changes: 1 addition & 1 deletion app/code/Magento/Bundle/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public function getAllowedSelectionTypes()
{
$configData = $this->config->getType(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE);

return isset($configData['allowed_selection_types']) ? $configData['allowed_selection_types'] : [];
return $configData['allowed_selection_types'] ?? [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function getCustomerGroups($groupId = null)
}

if ($groupId !== null) {
return isset($this->_customerGroups[$groupId]) ? $this->_customerGroups[$groupId] : [];
return $this->_customerGroups[$groupId] ?? [];
}

return $this->_customerGroups;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public function getVisibleStatusIds()
}

/**
* Retrieve Saleable Status Ids
* Default Product Enable status
* Retrieve Saleable Status Ids, default Product Enable status
*
* @return int[]
*/
Expand All @@ -51,6 +50,7 @@ public function getSaleableStatusIds()
* Retrieve option array
*
* @return string[]
* phpcs:disable Magento2.Functions.StaticFunction
*/
public static function getOptionArray()
{
Expand Down Expand Up @@ -83,7 +83,7 @@ public function getOptionText($optionId)
{
$options = self::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 @@ -9,6 +9,9 @@

use Magento\Catalog\Model\Product;

/**
* Manage entryes
*/
class EntryResolver
{
/**
Expand All @@ -27,7 +30,7 @@ public function getEntryFilePathById(Product $product, $entryId)

foreach ($mediaGalleryData['images'] as $image) {
if (isset($image['value_id']) && $image['value_id'] == $entryId) {
return isset($image['file']) ? $image['file'] : null;
return $image['file'] ?? null;
}
}
return null;
Expand All @@ -49,7 +52,7 @@ public function getEntryIdByFilePath(Product $product, $filePath)

foreach ($mediaGalleryData['images'] as $image) {
if (isset($image['file']) && $image['file'] == $filePath) {
return isset($image['value_id']) ? $image['value_id'] : null;
return $image['value_id'] ?? null;
}
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Model/Product/Visibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static function getAllOptions()
public static function getOptionText($optionId)
{
$options = self::getOptionArray();
return isset($options[$optionId]) ? $options[$optionId] : null;
return $options[$optionId] ?? null;
}
//phpcs:enable Magento2.Functions.StaticFunction

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace Magento\Catalog\Model\ProductLink\Converter;

/**
* Return converter by link type
*/
class ConverterPool
{
/**
Expand Down Expand Up @@ -34,8 +37,6 @@ public function __construct(array $converters)
*/
public function getConverter($linkType)
{
return isset($this->converters[$linkType])
? $this->converters[$linkType]
: $this->converters[$this->defaultConverterCode];
return $this->converters[$linkType] ?? $this->converters[$this->defaultConverterCode];
}
}
10 changes: 7 additions & 3 deletions app/code/Magento/Catalog/Model/ProductLink/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
namespace Magento\Catalog\Model\ProductLink;

/**
* @inheritdoc
*
* @codeCoverageIgnore
*/
class Link extends \Magento\Framework\Model\AbstractExtensibleModel implements
Expand All @@ -30,17 +32,19 @@ class Link extends \Magento\Framework\Model\AbstractExtensibleModel implements
*/
protected function _get($key)
{
return isset($this->_data[$key]) ? $this->_data[$key] : null;
return $this->_data[$key] ?? null;
}

/**
* Return Data Object data in array format.
*
* @return array
* @todo refactor with converter for AbstractExtensibleModel
* phpcs:disable
*/
public function __toArray()
{
//phpcs:enable
$data = $this->_data;
$hasToArray = function ($model) {
return is_object($model) && method_exists($model, '__toArray') && is_callable([$model, '__toArray']);
Expand Down Expand Up @@ -169,7 +173,7 @@ public function setPosition($position)
}

/**
* {@inheritdoc}
* @inheritdoc
*
* @return \Magento\Catalog\Api\Data\ProductLinkExtensionInterface|null
*/
Expand All @@ -184,7 +188,7 @@ public function getExtensionAttributes()
}

/**
* {@inheritdoc}
* @inheritdoc
*
* @param \Magento\Catalog\Api\Data\ProductLinkExtensionInterface $extensionAttributes
* @return $this
Expand Down
5 changes: 3 additions & 2 deletions app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ protected function getMultilineFieldConfig($attributeCode, array $attributeConfi
'dataScope' => $lineIndex,
'provider' => $providerName,
'validation' => $isFirstLine
//phpcs:ignore Magento2.Performance.ForeachArrayMerge
? array_merge(
['required-entry' => (bool)$attributeConfig['required']],
$attributeConfig['validation']
Expand Down Expand Up @@ -381,14 +382,14 @@ protected function getCustomer(): ?CustomerInterface
/**
* Retrieve field options from attribute configuration
*
* @param string $attributeCode
* @param mixed $attributeCode
* @param array $attributeConfig
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function getFieldOptions($attributeCode, array $attributeConfig)
{
return isset($attributeConfig['options']) ? $attributeConfig['options'] : [];
return $attributeConfig['options'] ?? [];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function getData()
*/
public function getId()
{
return isset($this->_data['id']) ? $this->_data['id'] : '';
return $this->_data['id'] ?? '';
}

/**
Expand Down Expand Up @@ -133,7 +133,7 @@ public function getComment()
*/
public function getFrontendModel()
{
return isset($this->_data['frontend_model']) ? $this->_data['frontend_model'] : '';
return $this->_data['frontend_model'] ?? '';
}

/**
Expand Down Expand Up @@ -194,7 +194,7 @@ protected function _hasVisibilityValue($key)
*/
public function getClass()
{
return isset($this->_data['class']) ? $this->_data['class'] : '';
return $this->_data['class'] ?? '';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function getTooltip()
*/
public function getType()
{
return isset($this->_data['type']) ? $this->_data['type'] : 'text';
return $this->_data['type'] ?? 'text';
}

/**
Expand Down Expand Up @@ -204,7 +204,7 @@ public function getRequiredFields($fieldPrefix = '')
*/
public function getFrontendClass()
{
return isset($this->_data['frontend_class']) ? $this->_data['frontend_class'] : '';
return $this->_data['frontend_class'] ?? '';
}

/**
Expand Down Expand Up @@ -256,7 +256,7 @@ public function getGroupPath()
*/
public function getConfigPath()
{
return isset($this->_data['config_path']) ? $this->_data['config_path'] : null;
return $this->_data['config_path'] ?? null;
}

/**
Expand Down Expand Up @@ -334,7 +334,7 @@ public function hasValidation()
*/
public function getValidation()
{
return isset($this->_data['validate']) ? $this->_data['validate'] : null;
return $this->_data['validate'] ?? null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Magento\Config\Model\Config\Structure\Element;

/**
* Section
* Element section
*
* @api
* @since 100.0.2
Expand Down Expand Up @@ -43,7 +43,7 @@ public function __construct(
*/
public function getHeaderCss()
{
return isset($this->_data['header_css']) ? $this->_data['header_css'] : '';
return $this->_data['header_css'] ?? '';
}

/**
Expand Down
4 changes: 1 addition & 3 deletions app/code/Magento/Customer/Ui/Component/ColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ protected function getJsComponent($dataType)
*/
protected function getDataType($frontendType)
{
return isset($this->dataTypeMap[$frontendType])
? $this->dataTypeMap[$frontendType]
: $this->dataTypeMap['default'];
return $this->dataTypeMap[$frontendType] ?? $this->dataTypeMap['default'];
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Customer/Ui/Component/FilterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ public function create(array $attributeData, $context)
*/
protected function getFilterType($frontendInput)
{
return isset($this->filterMap[$frontendInput]) ? $this->filterMap[$frontendInput] : $this->filterMap['default'];
return $this->filterMap[$frontendInput] ?? $this->filterMap['default'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Magento\Customer\Model\Indexer\Attribute\Filter;

/**
* Class AttributeRepository
* Attribute Repository Managment
*/
class AttributeRepository
{
Expand Down Expand Up @@ -156,10 +156,10 @@ protected function getOptionArray(array $options)
* Return customer group's metadata by given group code
*
* @param string $code
* @return []
* @return array | null
*/
public function getMetadataByCode($code)
{
return isset($this->getList()[$code]) ? $this->getList()[$code] : null;
return $this->getList()[$code] ?? null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ public function getValidationRules($isRequired, $validationRules)
protected function getValidationClass(ValidationRuleInterface $rule)
{
$key = $rule->getName() == 'input_validation' ? $rule->getValue() : $rule->getName();
return isset($this->inputValidationMap[$key])
? $this->inputValidationMap[$key]
: $key;
return $this->inputValidationMap[$key] ?? $key;
}

/**
Expand Down
18 changes: 16 additions & 2 deletions app/code/Magento/Customer/Ui/Component/Listing/Columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
use Magento\Customer\Ui\Component\Listing\Column\InlineEditUpdater;
use Magento\Customer\Api\CustomerMetadataInterface;

/**
* Columns component
*/
class Columns extends \Magento\Ui\Component\Listing\Columns
{
/**
Expand All @@ -29,6 +32,11 @@ class Columns extends \Magento\Ui\Component\Listing\Columns
*/
protected $inlineEditUpdater;

/**
* @var ColumnFactory
*/
private $columnFactory;

/**
* @var array
*/
Expand Down Expand Up @@ -63,6 +71,8 @@ public function __construct(
}

/**
* Return default sort order
*
* @return int
*/
protected function getDefaultSortOrder()
Expand Down Expand Up @@ -94,7 +104,7 @@ protected function updateActionColumnSortOrder()
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function prepare()
{
Expand All @@ -113,6 +123,8 @@ public function prepare()
}

/**
* Add column to the component
*
* @param array $attributeData
* @param string $columnName
* @return void
Expand All @@ -129,6 +141,8 @@ public function addColumn(array $attributeData, $columnName)
}

/**
* Update column in component
*
* @param array $attributeData
* @param string $newAttributeCode
* @return void
Expand Down Expand Up @@ -200,6 +214,6 @@ public function addOptions(UiComponentInterface $component, array $attributeData
*/
protected function getFilterType($frontendInput)
{
return isset($this->filterMap[$frontendInput]) ? $this->filterMap[$frontendInput] : $this->filterMap['default'];
return $this->filterMap[$frontendInput] ?? $this->filterMap['default'];
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Deploy/Model/Mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function enableDefaultMode()
public function getMode()
{
$env = $this->reader->load();
return isset($env[State::PARAM_MODE]) ? $env[State::PARAM_MODE] : null;
return $env[State::PARAM_MODE] ?? null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Deploy/Package/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function isVirtual()
*/
public function getParam($name)
{
return isset($this->params[$name]) ? $this->params[$name] : null;
return $this->params[$name] ?? null;
}

/**
Expand Down Expand Up @@ -253,7 +253,7 @@ public function getThemeModel()
*/
public function getFile($fileId)
{
return isset($this->files[$fileId]) ? $this->files[$fileId] : false;
return $this->files[$fileId] ?? false;
}

/**
Expand Down
Loading