Skip to content

Commit

Permalink
PHPMD: remove unused private methods/fields (#4397)
Browse files Browse the repository at this point in the history
* remove unused private methods/fields

* fixes - but one

* baseline

- see phpmd/phpmd#1218
  • Loading branch information
sreichel authored Nov 30, 2024
1 parent bcf0e84 commit e47aa19
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 142 deletions.
6 changes: 0 additions & 6 deletions .phpmd.dist.baseline.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0"?>
<phpmd-baseline>
<violation rule="PHPMD\Rule\UnusedPrivateMethod" file="app/code/core/Mage/Admin/Model/Resource/User.php" method="_encryptPassword"/>
<violation rule="PHPMD\Rule\Design\EmptyCatchBlock" file="app/code/core/Mage/Admin/Model/Session.php"/>
<violation rule="PHPMD\Rule\Design\EmptyCatchBlock" file="app/code/core/Mage/Adminhtml/Block/Report/Sales/Grid/Column/Renderer/Date.php"/>
<violation rule="PHPMD\Rule\UnusedPrivateMethod" file="app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/History.php" method="_sortHistoryByTimestamp"/>
Expand All @@ -9,16 +8,11 @@
<violation rule="PHPMD\Rule\Design\CountInLoopExpression" file="app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php"/>
<violation rule="PHPMD\Rule\Design\EmptyCatchBlock" file="app/code/core/Mage/Catalog/Model/Product/Api.php"/>
<violation rule="PHPMD\Rule\Design\EmptyCatchBlock" file="app/code/core/Mage/Catalog/Model/Product/Api/V2.php"/>
<violation rule="PHPMD\Rule\UnusedPrivateMethod" file="app/code/core/Mage/Checkout/Block/Cart/Sidebar.php" method="_addTax"/>
<violation rule="PHPMD\Rule\UnusedPrivateField" file="app/code/core/Mage/Checkout/Block/Onepage/Success.php"/>
<violation rule="PHPMD\Rule\Design\EmptyCatchBlock" file="app/code/core/Mage/Core/Model/Cache.php"/>
<violation rule="PHPMD\Rule\Design\CountInLoopExpression" file="app/code/core/Mage/Core/Model/Layout.php"/>
<violation rule="PHPMD\Rule\Design\EmptyCatchBlock" file="app/code/core/Mage/GiftMessage/Model/Observer.php"/>
<violation rule="PHPMD\Rule\Design\EmptyCatchBlock" file="app/code/core/Mage/GiftMessage/controllers/IndexController.php"/>
<violation rule="PHPMD\Rule\Design\EmptyCatchBlock" file="app/code/core/Mage/ImportExport/Model/Resource/Helper/Mysql4.php"/>
<violation rule="PHPMD\Rule\UnusedPrivateMethod" file="app/code/core/Mage/Log/Model/Aggregation.php" method="_removeEmpty"/>
<violation rule="PHPMD\Rule\UnusedPrivateMethod" file="app/code/core/Mage/Paypal/Model/Config.php" method="_matchBnCountryCode"/>
<violation rule="PHPMD\Rule\Design\CountInLoopExpression" file="app/code/core/Mage/Paypal/Model/Report/Settlement.php"/>
<violation rule="PHPMD\Rule\UnusedPrivateField" file="app/code/core/Mage/Sales/Model/Order/Status/History.php"/>
<violation rule="PHPMD\Rule\Design\CountInLoopExpression" file="app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php"/>
</phpmd-baseline>
20 changes: 10 additions & 10 deletions .phpmd.dist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,25 @@

<!-- NAMING
[-] BooleanGetMethodName
[ ] ConstantNamingConventions
[ ] ConstructorWithNameAsEnclosingClass
[x] ConstantNamingConventions
[x] ConstructorWithNameAsEnclosingClass
[-] LongClassName
[ ] ShortClassName
[x] ShortClassName
[-] LongVariable
[?] ShortVariable - TMP disabled
[ ] ShortMethodName
[x] ShortVariable
[x] ShortMethodName - TMP disabled
-->
<!-- <rule ref="rulesets/naming.xml/ShortVariable">-->
<!-- <properties>-->
<!-- <property name="exceptions" value="a,b,e,id,idx,io,ip,to,x,y,x1,x2,y1,y2" />-->
<!-- </properties>-->
<!-- </rule>-->
<rule ref="rulesets/naming.xml">
<exclude name="BooleanGetMethodName" />
<exclude name="LongClassName" />
<exclude name="LongVariable" />
<exclude name="ShortVariable" />
</rule>
<!-- <rule ref="rulesets/naming.xml/ShortVariable">-->
<!-- <properties>-->
<!-- <property name="exceptions" value="a,b,x,y,x1,x2,y1,y2" />-->
<!-- </properties>-->
<!-- </rule>-->
<rule ref="rulesets/naming.xml/ShortMethodName" />

<!-- DESIGN
Expand Down
35 changes: 0 additions & 35 deletions .phpstan.dist.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ parameters:
count: 1
path: app/code/core/Mage/Admin/Model/Resource/Roles.php

-
message: "#^Method Mage_Admin_Model_Resource_User\\:\\:_encryptPassword\\(\\) is unused\\.$#"
count: 1
path: app/code/core/Mage/Admin/Model/Resource/User.php

-
message: "#^Call to an undefined method Mage_Admin_Model_Resource_Roles\\:\\:update\\(\\)\\.$#"
count: 1
Expand Down Expand Up @@ -2385,11 +2380,6 @@ parameters:
count: 1
path: app/code/core/Mage/Checkout/Block/Cart/Shipping.php

-
message: "#^Method Mage_Checkout_Block_Cart_Sidebar\\:\\:_addTax\\(\\) is unused\\.$#"
count: 1
path: app/code/core/Mage/Checkout/Block/Cart/Sidebar.php

-
message: "#^Method Mage_Checkout_Block_Onepage_Billing\\:\\:_getTaxvat\\(\\) should return Mage_Customer_Block_Widget_Taxvat but returns Mage_Core_Block_Abstract\\|false\\.$#"
count: 1
Expand All @@ -2405,11 +2395,6 @@ parameters:
count: 1
path: app/code/core/Mage/Checkout/Block/Onepage/Progress.php

-
message: "#^Property Mage_Checkout_Block_Onepage_Success\\:\\:\\$_order is unused\\.$#"
count: 1
path: app/code/core/Mage/Checkout/Block/Onepage/Success.php

-
message: "#^PHPDoc tag @var with type Mage_Sales_Model_Quote_Item is not subtype of native type null\\.$#"
count: 1
Expand Down Expand Up @@ -4070,11 +4055,6 @@ parameters:
count: 1
path: app/code/core/Mage/Log/Model/Aggregation.php

-
message: "#^Method Mage_Log_Model_Aggregation\\:\\:_removeEmpty\\(\\) is unused\\.$#"
count: 1
path: app/code/core/Mage/Log/Model/Aggregation.php

-
message: "#^Parameter \\#1 \\$id of method Mage_Log_Model_Aggregation\\:\\:_update\\(\\) expects int, string given\\.$#"
count: 1
Expand Down Expand Up @@ -4225,11 +4205,6 @@ parameters:
count: 1
path: app/code/core/Mage/Paypal/Model/Cart.php

-
message: "#^Method Mage_Paypal_Model_Config\\:\\:_matchBnCountryCode\\(\\) is unused\\.$#"
count: 1
path: app/code/core/Mage/Paypal/Model/Config.php

-
message: "#^Negated boolean expression is always true\\.$#"
count: 1
Expand Down Expand Up @@ -4955,16 +4930,6 @@ parameters:
count: 1
path: app/code/core/Mage/Sales/Model/Order/Shipment/Api/V2.php

-
message: "#^Method Mage_Sales_Model_Order_Status_History\\:\\:getStatusLabel\\(\\) should return string but return statement is missing\\.$#"
count: 1
path: app/code/core/Mage/Sales/Model/Order/Status/History.php

-
message: "#^Property Mage_Sales_Model_Order_Status_History\\:\\:\\$_shouldSetOrderBeforeSave is never read, only written\\.$#"
count: 1
path: app/code/core/Mage/Sales/Model/Order/Status/History.php

-
message: "#^Parameter \\#2 \\$totalConfig of method Mage_Sales_Model_Config_Ordered\\:\\:_prepareConfigArray\\(\\) expects Mage_Core_Model_Config_Element, array given\\.$#"
count: 1
Expand Down
11 changes: 0 additions & 11 deletions app/code/core/Mage/Admin/Model/Resource/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,6 @@ public function hasAssigned2Role($user)
}
}

/**
* Encrypt password
*
* @param string $pwStr
* @return string
*/
private function _encryptPassword($pwStr)
{
return Mage::helper('core')->getHash($pwStr, Mage_Admin_Model_User::HASH_SALT_LENGTH);
}

/**
* Set created/modified values before user save
*
Expand Down
20 changes: 0 additions & 20 deletions app/code/core/Mage/Checkout/Block/Cart/Sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,6 @@ public function getSubtotalInclTax()
return $this->getSubtotal(false);
}

/**
* Add tax to amount
*
* @param float $price
* @param bool $exclShippingTax
* @return float
*/
private function _addTax($price, $exclShippingTax = true)
{
$totals = $this->getTotals();
if (isset($totals['tax'])) {
if ($exclShippingTax) {
$price += $totals['tax']->getValue() - $this->_getShippingTaxAmount();
} else {
$price += $totals['tax']->getValue();
}
}
return $price;
}

/**
* Get shipping tax amount
*
Expand Down
5 changes: 0 additions & 5 deletions app/code/core/Mage/Checkout/Block/Onepage/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
*/
class Mage_Checkout_Block_Onepage_Success extends Mage_Core_Block_Template
{
/**
* @deprecated after 1.4.0.1
*/
private $_order;

/**
* Check order print availability
*
Expand Down
11 changes: 0 additions & 11 deletions app/code/core/Mage/Log/Model/Aggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,6 @@ public function run()
}
}

/**
* Remove empty records before $lastDate
*
* @param string $lastDate
* @return Mage_Log_Model_Resource_Aggregation
*/
private function _removeEmpty($lastDate)
{
return $this->_getResource()->removeEmpty($lastDate);
}

/**
* Process
*
Expand Down
37 changes: 0 additions & 37 deletions app/code/core/Mage/Paypal/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1654,43 +1654,6 @@ protected function _getSpecificConfigPath($fieldName)
return $path;
}

/**
* Check whether specified country code is supported by build notation codes for specific countries
*
* @param string $code
* @return string|null
*/
private function _matchBnCountryCode($code)
{
switch ($code) {
// GB == UK
case 'GB':
return 'UK';
// Australia, Austria, Belgium, Canada, China, France, Germany, Hong Kong, Italy
case 'AU':
case 'AT':
case 'BE':
case 'CA':
case 'CN':
case 'FR':
case 'DE':
case 'HK':
case 'IT':
// Japan, Mexico, Netherlands, Poland, Singapore, Spain, Switzerland, United Kingdom, United States
case 'JP':
case 'MX':
case 'NL':
case 'PL':
case 'SG':
case 'ES':
case 'CH':
case 'UK':
case 'US':
return $code;
}
return null;
}

/**
* Map PayPal Standard config fields
*
Expand Down
8 changes: 1 addition & 7 deletions app/code/core/Mage/Sales/Model/Order/Status/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ class Mage_Sales_Model_Order_Status_History extends Mage_Sales_Model_Abstract
*/
protected $_order;

/**
* Whether setting order again is required (for example when setting non-saved yet order)
* @deprecated after 1.4, wrong logic of setting order id
* @var bool
*/
private $_shouldSetOrderBeforeSave = false;

protected $_eventPrefix = 'sales_order_status_history';
protected $_eventObject = 'status_history';

Expand Down Expand Up @@ -127,6 +120,7 @@ public function getStatusLabel()
if ($this->getOrder()) {
return $this->getOrder()->getConfig()->getStatusLabel($this->getStatus());
}
return '';
}

/**
Expand Down

0 comments on commit e47aa19

Please sign in to comment.