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 #18124

Merged
merged 9 commits into from
Dec 12, 2018
Merged
Show file tree
Hide file tree
Changes from 8 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
18 changes: 14 additions & 4 deletions app/code/Magento/Catalog/Ui/Component/ColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace Magento\Catalog\Ui\Component;

/**
* Column Factory
*
* @api
* @since 100.0.2
*/
Expand Down Expand Up @@ -47,10 +49,14 @@ public function __construct(\Magento\Framework\View\Element\UiComponentFactory $
}

/**
* Create Factory
*
* @param \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute
* @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context
* @param array $config
*
* @return \Magento\Ui\Component\Listing\Columns\ColumnInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function create($attribute, $context, array $config = [])
{
Expand Down Expand Up @@ -82,7 +88,10 @@ public function create($attribute, $context, array $config = [])
}

/**
* Get Js Component
*
* @param string $dataType
*
* @return string
*/
protected function getJsComponent($dataType)
Expand All @@ -91,14 +100,15 @@ protected function getJsComponent($dataType)
}

/**
* Get Data Type
*
* @param \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute
*
* @return string
*/
protected function getDataType($attribute)
{
return isset($this->dataTypeMap[$attribute->getFrontendInput()])
? $this->dataTypeMap[$attribute->getFrontendInput()]
: $this->dataTypeMap['default'];
return $this->dataTypeMap[$attribute->getFrontendInput()] ?? $this->dataTypeMap['default'];
}

/**
Expand All @@ -111,6 +121,6 @@ protected function getFilterType($frontendInput)
{
$filtersMap = ['date' => 'dateRange'];
$result = array_replace_recursive($this->dataTypeMap, $filtersMap);
return isset($result[$frontendInput]) ? $result[$frontendInput] : $result['default'];
return $result[$frontendInput] ?? $result['default'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Magento\Framework\View\Element\UiComponent\ContextInterface;

/**
* Class Thumbnail
*
* @api
* @since 100.0.2
*/
Expand Down Expand Up @@ -67,13 +69,15 @@ public function prepareDataSource(array $dataSource)
}

/**
* Get Alt
*
* @param array $row
*
* @return null|string
*/
protected function getAlt($row)
{
$altField = $this->getData('config/altField') ?: self::ALT_FIELD;
return isset($row[$altField]) ? $row[$altField] : null;
return $row[$altField] ?? null;
}
}
9 changes: 8 additions & 1 deletion app/code/Magento/CatalogUrlRewrite/Model/ObjectRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*/
namespace Magento\CatalogUrlRewrite\Model;

/**
* Class ObjectRegistry
*/
class ObjectRegistry
{
/**
Expand All @@ -26,15 +29,19 @@ public function __construct($entities)
}

/**
* Get Entity
*
* @param int $entityId
* @return \Magento\Framework\DataObject|null
*/
public function get($entityId)
{
return isset($this->entitiesMap[$entityId]) ? $this->entitiesMap[$entityId] : null;
return $this->entitiesMap[$entityId] ?? null;
}

/**
* List Entities
*
* @return \Magento\Framework\DataObject[]
*/
public function getList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ public function _beforeToHtml()
*/
public function getWebsiteCount($websiteId)
{
return isset($this->_websiteCounts[$websiteId]) ? $this->_websiteCounts[$websiteId] : 0;
return $this->_websiteCounts[$websiteId] ?? 0;
}

/**
* Returns Grouped Collection Rows
*
* @return array
*/
public function getRows()
Expand All @@ -159,6 +161,8 @@ public function getRows()
}

/**
* Return totals data
*
* @return \Magento\Framework\DataObject
*/
public function getTotals()
Expand All @@ -171,7 +175,9 @@ public function getTotals()
*
* @param float $price
* @param null|int $websiteId
*
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function formatCurrency($price, $websiteId = null)
{
Expand Down
16 changes: 11 additions & 5 deletions app/code/Magento/Customer/Model/Address/AbstractAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public function getStreet()
public function getStreetLine($number)
{
$lines = $this->getStreet();
return isset($lines[$number - 1]) ? $lines[$number - 1] : '';
return $lines[$number - 1] ?? '';
}

/**
Expand Down Expand Up @@ -271,8 +271,9 @@ public function setStreet($street)
* Enforce format of the street field or other multiline custom attributes
*
* @param array|string $key
* @param mixed $value
* @return $this
* @param array|string|null $value
*
* @return \Magento\Framework\DataObject
*/
public function setData($key, $value = null)
{
Expand Down Expand Up @@ -404,7 +405,7 @@ public function getRegionCode()
}

/**
* Get region id
* Return Region ID
*
* @return int
*/
Expand Down Expand Up @@ -507,7 +508,7 @@ public function getConfig()
}

/**
* Before save handler
* Processing object before save data
*
* @return $this
*/
Expand All @@ -523,10 +524,12 @@ public function beforeSave()
*
* @param int|null $defaultBillingAddressId
* @param int|null $defaultShippingAddressId
*
* @return AddressInterface
* Use Api/Data/AddressInterface as a result of service operations. Don't rely on the model to provide
* the instance of Api/Data/AddressInterface
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getDataModel($defaultBillingAddressId = null, $defaultShippingAddressId = null)
{
Expand Down Expand Up @@ -633,6 +636,7 @@ public function unsRegion()
*
* @return bool
* @since 100.2.0
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function isCompanyRequired()
{
Expand All @@ -644,6 +648,7 @@ protected function isCompanyRequired()
*
* @return bool
* @since 100.2.0
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function isTelephoneRequired()
{
Expand All @@ -655,6 +660,7 @@ protected function isTelephoneRequired()
*
* @return bool
* @since 100.2.0
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function isFaxRequired()
{
Expand Down
21 changes: 14 additions & 7 deletions app/code/Magento/Fedex/Model/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ public function getCode($type, $code = '')
* Return FeDex currency ISO code by Magento Base Currency Code
*
* @return string 3-digit currency code
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getCurrencyCode()
{
Expand All @@ -1008,7 +1009,7 @@ public function getCurrencyCode()
];
$currencyCode = $this->_storeManager->getStore()->getBaseCurrencyCode();

return isset($codes[$currencyCode]) ? $codes[$currencyCode] : $currencyCode;
return $codes[$currencyCode] ?? $currencyCode;
}

/**
Expand Down Expand Up @@ -1438,6 +1439,8 @@ protected function _doShipmentRequest(\Magento\Framework\DataObject $request)
}

/**
* Return Tracking Number
*
* @param array|object $trackingIds
* @return string
*/
Expand All @@ -1452,10 +1455,10 @@ function ($val) {
}

/**
* For multi package shipments. Delete requested shipments if the current shipment
* request is failed
* For multi package shipments. Delete requested shipments if the current shipment request is failed
*
* @param array $data
*
* @return bool
*/
public function rollBack($data)
Expand All @@ -1475,6 +1478,7 @@ public function rollBack($data)
* Return container types of carrier
*
* @param \Magento\Framework\DataObject|null $params
*
* @return array|bool
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
Expand Down Expand Up @@ -1542,6 +1546,7 @@ public function getContainerTypesFilter()
* Return delivery confirmation types of carrier
*
* @param \Magento\Framework\DataObject|null $params
*
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
Expand All @@ -1552,6 +1557,7 @@ public function getDeliveryConfirmationTypes(\Magento\Framework\DataObject $para

/**
* Recursive replace sensitive fields in debug data by the mask
*
* @param string $data
* @return string
*/
Expand All @@ -1569,6 +1575,7 @@ protected function filterDebugData($data)

/**
* Parse track details response from Fedex
*
* @param \stdClass $trackInfo
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
Expand Down Expand Up @@ -1639,6 +1646,7 @@ private function processTrackingDetails(\stdClass $trackInfo)

/**
* Parse delivery datetime from tracking details
*
* @param \stdClass $trackInfo
* @return \Datetime|null
*/
Expand All @@ -1655,8 +1663,7 @@ private function getDeliveryDateTime(\stdClass $trackInfo)
}

/**
* Get delivery address details in string representation
* Return City, State, Country Code
* Get delivery address details in string representation Return City, State, Country Code
*
* @param \stdClass $address
* @return \Magento\Framework\Phrase|string
Expand Down Expand Up @@ -1718,6 +1725,7 @@ private function processTrackDetailsEvents(array $events)

/**
* Append error message to rate result instance
*
* @param string $trackingValue
* @param string $errorMessage
*/
Expand Down Expand Up @@ -1759,8 +1767,7 @@ private function parseDate($timestamp)
}

/**
* Defines payment type by request.
* Two values are available: RECIPIENT or SENDER.
* Defines payment type by request. Two values are available: RECIPIENT or SENDER.
*
* @param DataObject $request
* @return string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ public function create(VaultPaymentInterface $paymentMethod, int $storeId): Inte
/**
* Reads value from config.
*
* @param $config
* @param array $config
* @param string $field
* @param string $default
* @return string
*/
private function extractFromConfig($config, string $field, string $default): string
{
return isset($config[$field]) ? $config[$field] : $default;
return $config[$field] ?? $default;
}
}
Loading