Skip to content

Commit

Permalink
PHPMD: added basic config (OpenMage#2771)
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel authored and fballiano committed Dec 30, 2022
1 parent e9ae9c8 commit cce33d0
Show file tree
Hide file tree
Showing 50 changed files with 375 additions and 1 deletion.
125 changes: 125 additions & 0 deletions .phpmd.dist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?xml version="1.0"?>
<ruleset name="Custom ruleset"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
OpenMage ruleset
</description>

<!-- UNUSEDCODE
UnusedFormalParameter [fixed]
UnusedLocalVariable
UnusedPrivateField
UnusedPrivateMethod
-->
<rule ref="rulesets/unusedcode.xml" />

<!-- CLEANCODE
BooleanArgumentFlag
ElseExpression
ErrorControlOperator
DuplicatedArrayKey
IfStatementAssignment
MissingImport
StaticAccess
UndefinedVariable
-->
<rule ref="rulesets/cleancode.xml">
<exclude name="BooleanArgumentFlag" />
<exclude name="ElseExpression" /> <!-- can be fixed in some cases -->
<exclude name="IfStatementAssignment" /> <!-- can be fixed -->
<exclude name="MissingImport" /> <!-- can be fixed -->
<exclude name="StaticAccess" />
<exclude name="UndefinedVariable" /> <!-- can be fixed -->
</rule>
<rule ref="rulesets/cleancode.xml/MissingImport">
<properties>
<property name="ignore-global" value="true" />
</properties>
</rule>

<!-- CONTROVERSIAL
CamelCaseClassName
CamelCaseMethodName
CamelCaseParameterName
CamelCasePropertyName
CamelCaseVariableName
Superglobals
-->
<rule ref="rulesets/controversial.xml/CamelCaseMethodName">
<properties>
<property name="allow-underscore" value="true" />
</properties>
</rule>
<rule ref="rulesets/controversial.xml/CamelCaseParameterName" />
<rule ref="rulesets/controversial.xml/CamelCasePropertyName">
<properties>
<property name="allow-underscore" value="true" />
</properties>
</rule>
<rule ref="rulesets/controversial.xml/CamelCaseVariableName">
<properties>
<property name="allow-underscore" value="true" />
</properties>
</rule>
<rule ref="rulesets/controversial.xml/Superglobals" />

<!-- NAMEING
BooleanGetMethodName
ConstantNamingConventions
ConstructorWithNameAsEnclosingClass
LongClassName
ShortClassName
LongVariable
ShortVariable
ShortMethodName
-->
<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>

<!-- DESIGN
CountInLoopExpression
CouplingBetweenObjects
DepthOfInheritance
DevelopmentCodeFragment
EmptyCatchBlock
EvalExpression
ExitExpression
GotoStatement
NumberOfChildren
-->
<rule ref="rulesets/design.xml">
<exclude name="CouplingBetweenObjects" />
<exclude name="DepthOfInheritance" />
<exclude name="NumberOfChildren" />
</rule>

<!-- CODESIZE
ExcessiveClassComplexity
ExcessiveClassLength
ExcessiveMethodLength
ExcessiveParameterList
ExcessivePublicCount
CyclomaticComplexity
NPathComplexity
TooManyFields
TooManyMethods
TooManyPublicMethods
-->
<rule ref="rulesets/codesize.xml">
<exclude name="CyclomaticComplexity" />
<exclude name="ExcessiveClassComplexity" />
<exclude name="ExcessiveClassLength" />
<exclude name="ExcessiveMethodLength" />
<exclude name="ExcessivePublicCount" />
<exclude name="NPathComplexity" />
<exclude name="TooManyFields" />
<exclude name="TooManyMethods" />
<exclude name="TooManyPublicMethods" />
</rule>
</ruleset>
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
*/
class Mage_Adminhtml_Block_Customer_Online_Grid_Renderer_Ip extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
/**
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function render(Varien_Object $row)
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Ip extends Mage_Adminhtml
*
* @param Varien_Object $row
* @return string
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function render(Varien_Object $row)
{
Expand Down
2 changes: 2 additions & 0 deletions app/code/core/Mage/Backup/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ public function turnOnMaintenanceMode()

/**
* Turn off store maintenance mode
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function turnOffMaintenanceMode()
{
Expand Down
6 changes: 6 additions & 0 deletions app/code/core/Mage/Backup/Model/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ public function setFile(&$content)
* @todo rewrite to Varien_IO, but there no possibility read part of files.
* @return string
* @throws Mage_Backup_Exception
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function &getFile()
{
Expand Down Expand Up @@ -227,6 +229,8 @@ public function deleteFile()
*
* @param bool $write
* @return $this
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function open($write = false)
{
Expand Down Expand Up @@ -312,6 +316,8 @@ public function write($string)
* Close open backup file
*
* @return $this
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function close()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Mage_Catalog_Model_Api2_Product_Image_Rest_Admin_V1 extends Mage_Catalog_M
* @throws Mage_Api2_Exception
* @param array $data
* @return string|void
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
protected function _create(array $data)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public function info($productId, $file, $store = null, $identifierType = null)
* @param string|null $identifierType
* @return string
* @throws Mage_Api_Exception
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function create($productId, $data, $store = null, $identifierType = null)
{
Expand Down Expand Up @@ -202,6 +204,8 @@ public function create($productId, $data, $store = null, $identifierType = null)
* @param string|null $identifierType
* @return bool
* @throws Mage_Api_Exception
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function update($productId, $file, $data, $store = null, $identifierType = null)
{
Expand Down
4 changes: 4 additions & 0 deletions app/code/core/Mage/Catalog/Model/Product/Option/Type/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,8 @@ public function prepareOptionValueForRequest($optionValue)
* Quote item to order item copy process
*
* @return $this
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function copyQuoteToOrder()
{
Expand Down Expand Up @@ -798,6 +800,8 @@ protected function _getUploadMaxFilesize()
*
* @param string $ini_key php.ini Var name
* @return int Setting value
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
protected function _getBytesIniValue($ini_key)
{
Expand Down
2 changes: 2 additions & 0 deletions app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public function getDirsCollection($path)
* @param string $path Parent directory path
* @param string $type Type of storage, e.g. image, media etc.
* @return Varien_Data_Collection_Filesystem
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function getFilesCollection($path, $type = null)
{
Expand Down
2 changes: 2 additions & 0 deletions app/code/core/Mage/Core/Controller/Varien/Front.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ protected function _processRewriteUrl($url)
* By default this feature is enabled in configuration.
*
* @param Mage_Core_Controller_Request_Http $request
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
protected function _checkBaseUrl($request)
{
Expand Down
4 changes: 4 additions & 0 deletions app/code/core/Mage/Core/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ public function getStoreId($store = null)
* @param string $string
* @param bool $german
* @return false|string
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function removeAccents($string, $german = false)
{
Expand Down Expand Up @@ -763,6 +765,8 @@ public function uniqHash($prefix = '')
* @param callable $beforeMergeCallback
* @param array|string $extensionsFilter
* @return bool|string
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function mergeFiles(
array $srcFiles,
Expand Down
2 changes: 2 additions & 0 deletions app/code/core/Mage/Core/Model/Config/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ public function getExportDir()
/**
* @param string $dir
* @return bool
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function createDirIfNotExists($dir)
{
Expand Down
2 changes: 2 additions & 0 deletions app/code/core/Mage/Core/Model/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ protected function _getConfigTimezone()
*
* @param string $timezone
* @return int offset between timezone and gmt
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function calculateOffset($timezone = null)
{
Expand Down
2 changes: 2 additions & 0 deletions app/code/core/Mage/Core/Model/Design/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ protected function _checkUserAgentAgainstRegexps($regexpsConfigPath)
* @param array $rules - design exception rules
* @param string $regexpsConfigPath
* @return bool|string
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public static function getPackageByUserAgent(array $rules, $regexpsConfigPath = 'path_mock')
{
Expand Down
2 changes: 2 additions & 0 deletions app/code/core/Mage/Core/Model/File/Storage/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public function getMediaBaseDirectory()
*
* @param string $path
* @return array
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function collectFileInfo($path)
{
Expand Down
2 changes: 2 additions & 0 deletions app/code/core/Mage/Core/Model/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ public function utcDate($store, $date, $includeTime = false, $format = null)
*
* @param mixed $store
* @return int
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function storeTimeStamp($store = null)
{
Expand Down
10 changes: 10 additions & 0 deletions app/code/core/Mage/Core/Model/Resource/File/Storage/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public function getStorageData($dir = '')
*
* @param string $dir
* @return $this
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function clear($dir = '')
{
Expand Down Expand Up @@ -161,6 +163,8 @@ protected function _getIgnoredFiles()
*
* @param array $dir
* @return bool
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function saveDir($dir)
{
Expand Down Expand Up @@ -192,6 +196,8 @@ public function saveDir($dir)
* @param bool $overwrite
* @return bool true if file written, otherwise false
* @throws Mage_Core_Exception
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function saveFile($filePath, $content, $overwrite = false)
{
Expand Down Expand Up @@ -236,6 +242,8 @@ public function saveFile($filePath, $content, $overwrite = false)
*
* @param string $filePath
* @return bool
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function lockCreateFile($filePath)
{
Expand Down Expand Up @@ -279,6 +287,8 @@ public function lockCreateFile($filePath)
* Unlock, close and remove a locked file (in case the file could not be read from remote storage)
*
* @param string $filePath
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function removeLockedFile($filePath)
{
Expand Down
6 changes: 6 additions & 0 deletions app/code/core/Mage/Core/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ function mageCoreErrorHandler($errno, $errstr, $errfile, $errline)
* @param bool $html
* @param bool $showFirst
* @return string|void
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
function mageDebugBacktrace($return = false, $html = true, $showFirst = false)
{
Expand Down Expand Up @@ -240,6 +242,8 @@ function mageSendErrorFooter()

/**
* @param string $path
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
function mageDelTree($path)
{
Expand Down Expand Up @@ -296,6 +300,8 @@ function mageParseCsv($string, $delimiter = ",", $enclosure = '"', $escape = '\\
/**
* @param string $dir
* @return bool
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
function is_dir_writeable($dir)
{
Expand Down
2 changes: 2 additions & 0 deletions app/code/core/Mage/Eav/Model/Attribute/Data/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Mage_Eav_Model_Attribute_Data_Image extends Mage_Eav_Model_Attribute_Data_
*
* @param array $value
* @return array
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
protected function _validateByRules($value)
{
Expand Down
2 changes: 2 additions & 0 deletions app/code/core/Mage/Install/Model/Installer/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ protected function _prepareData()
* Install Magento
*
* @return bool
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function install()
{
Expand Down

0 comments on commit cce33d0

Please sign in to comment.