Skip to content

Commit a264cde

Browse files
sreichelfballiano
authored andcommitted
rector: automatic code refactoring (part 1) (#2879)
* Add "never" return-type for methods that never return anything - see https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#returnnevertyperector * Updated phpstan.dist.baseline.neon * Added ddev rector command shortcut * Change array_push() to direct variable assign - see https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#changearraypushtoarrayassignrector * Replace array_keys() and in_array() to array_key_exists() - see https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#arraykeysandinarraytoarraykeyexistsrector * Use common != instead of less known <> with same meaning - see https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#commonnotequalrector * Issue in rector found ...reverted - see rectorphp/rector#7699 * Updated phpstan.dist.baseline.neon * Change compact() call to own array - see https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#compacttovariablesrector * Change OR, AND to ||, && with more common understanding - see https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#logicaltobooleanrector * Replace the Double not operator (!!) by type-casting to boolean - see https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#replacemultiplebooleannotrector * Simplify array_search to in_array - see https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#simplifyarraysearchrector * Changes compared to value and return of expr to direct return - see https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#simplifyifexactvaluereturnvaluerector * Updated phpstan.dist.baseline.neon This error goes and comes ... * Changes strlen comparison to 0 to direct empty string compare - see https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#strlenzerotoidenticalemptystringrector * Simplify conditions - see https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#simplifyconditionsrector * Simplify tautology ternary to value - see https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#simplifytautologyternaryrector * Splits [$a, $b] = [5, 10] scalar assign to standalone lines - see https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#splitlistassigntoseparatelinerector
1 parent 06475bf commit a264cde

File tree

34 files changed

+62
-78
lines changed

34 files changed

+62
-78
lines changed

.ddev/commands/web/rector

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
## Description: run rector
4+
## Usage: rector
5+
## Example: ddev rector <path-to-files>
6+
7+
cp -n vendor/sreichel/openmage-rector/rector.php rector.php
8+
php vendor/bin/rector process "$@"

app/code/core/Mage/Adminhtml/Block/Sales/Totals.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function _initTotals()
7878
/**
7979
* Add discount
8080
*/
81-
if (((float)$this->getSource()->getDiscountAmount()) != 0) {
81+
if ((float)$this->getSource()->getDiscountAmount() != 0) {
8282
if ($this->getSource()->getDiscountDescription()) {
8383
$discountLabel = $this->helper('sales')->__(
8484
'Discount (%s)',

app/code/core/Mage/Adminhtml/Block/Widget/Grid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public function sortColumnsByOrder()
423423
$values = array_values($this->_columns);
424424

425425
foreach ($this->getColumnsOrder() as $columnId => $after) {
426-
if (array_search($after, $keys) !== false) {
426+
if (in_array($after, $keys)) {
427427
// Moving grid column
428428
$positionCurrent = array_search($columnId, $keys);
429429

app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ protected function _processActionData($action = null)
216216
/**
217217
* Adding products to quote from special grid
218218
*/
219-
if ($this->getRequest()->has('item') && !$this->getRequest()->getPost('update_items') && !($action == 'save')) {
219+
if ($this->getRequest()->has('item') && !$this->getRequest()->getPost('update_items') && $action != 'save') {
220220
$items = $this->getRequest()->getPost('item');
221221
$items = $this->_processFiles($items);
222222
$this->_getOrderCreateModel()->addProducts($items);

app/code/core/Mage/Api/Helper/Data.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ protected function _parseComplexFilter($complexFilter)
307307
if (!isset($filter->key) || !isset($filter->value)) {
308308
continue;
309309
}
310-
311-
list($fieldName, $condition) = [$filter->key, $filter->value];
310+
$fieldName = $filter->key;
311+
$condition = $filter->value;
312312
$conditionName = $condition->key;
313313
$conditionValue = $condition->value;
314314
$this->formatFilterConditionValue($conditionName, $conditionValue);

app/code/core/Mage/Api/Model/Resource/Abstract.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ protected function _getServer()
9393
* @param string $code
9494
* @param string|null $customMessage
9595
* @throws Mage_Api_Exception
96+
* @return never
9697
*/
9798
protected function _fault($code, $customMessage = null)
9899
{

app/code/core/Mage/Api/Model/Server/Adapter/Xmlrpc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public function run()
112112
*
113113
* @param int $code
114114
* @param string $message
115+
* @return never
115116
*/
116117
public function fault($code, $message)
117118
{

app/code/core/Mage/Catalog/Model/Api2/Product/Validator/Product.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ protected function _isConfigValueUsed($data, $field)
628628
* @param string $message
629629
* @param int $code
630630
* @throws Mage_Api2_Exception
631+
* @return never
631632
*/
632633
protected function _critical($message, $code)
633634
{

app/code/core/Mage/Catalog/Model/Api2/Product/Website/Validator/Admin/Website.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ protected function _checkStoreTo($website, $storeData)
176176
*/
177177
public function isWebsiteAssignedToProduct(Mage_Core_Model_Website $website, Mage_Catalog_Model_Product $product)
178178
{
179-
if (array_search($website->getId(), $product->getWebsiteIds()) === false) {
179+
if (!in_array($website->getId(), $product->getWebsiteIds())) {
180180
$this->_addError(sprintf(
181181
'Product #%d isn\'t assigned to website #%d',
182182
$product->getId(),

app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Startdate.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ protected function _getValueForSave($object)
3939
{
4040
$attributeName = $this->getAttribute()->getName();
4141
$startDate = $object->getData($attributeName);
42-
if ($startDate === false) {
43-
return false;
44-
}
4542
return $startDate;
4643
}
4744

0 commit comments

Comments
 (0)