Skip to content

Commit

Permalink
Add PHPCodeSniffer to workflow (#2708)
Browse files Browse the repository at this point in the history
* Mage: CS fixes

* lib: CS fixes

* Added PHPCS workflow

* lib: CS fixes

* lib\Varien: CS fixes

* Added PSR12

* Fixes linefeed in docblock

* Updated: workflow

* Remove Eaccelerator.php

* Removed empty line

* CS fixes
  • Loading branch information
sreichel committed Nov 18, 2022
1 parent 278270d commit 2afbba9
Show file tree
Hide file tree
Showing 1,991 changed files with 14,980 additions and 14,620 deletions.
31 changes: 31 additions & 0 deletions .github/phpcs-ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0"?>
<ruleset name="OpenMage Standard" namespace="OpenMage\CS\Standard">
<rule ref="PSR2">
<exclude name="Generic.Files.LineLength.TooLong"/>
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace"/>
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols"/>
<exclude name="PSR2.Classes.ClassDeclaration.ExtendsLine"/>
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/>
<exclude name="PSR2.Methods.FunctionCallSignature.Indent"/>
<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps"/>
</rule>
<rule ref="PSR12">
<exclude name="PSR12.ControlStructures.ControlStructureSpacing.CloseParenthesisLine"/>
<exclude name="PSR12.ControlStructures.ControlStructureSpacing.FirstExpressionLine"/>
<exclude name="PSR12.ControlStructures.ControlStructureSpacing.LineIndent"/>
<exclude name="PSR12.Files.FileHeader.SpacingAfterBlock"/>
</rule>
<!--
<rule ref="Ecg">
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed"/>
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed"/>
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.Found"/>
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass"/>
<exclude name="Generic.Commenting.Todo.TaskFound"/>
<exclude name="Generic.Metrics.CyclomaticComplexity.TooHigh"/>
<exclude name="Ecg.Classes.Mysql4.Found"/>
<exclude name="Ecg.PHP.PrivateClassMember.PrivateClassMemberError"/>
</rule>
-->
</ruleset>
58 changes: 58 additions & 0 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: "PHPCodeSniffer Code Style Analyses"

on:
# Run on all pushes and on all pull requests.
# Prevent the build from running when there are only irrelevant changes.
push:
paths:
- '**.php'
- '.github/phpcs*'
- '.github/workflows/phpcs*'
pull_request:
paths:
- '**.php'
- '.github/phpcs*'
- '.github/workflows/phpcs*'
# Allow manually triggering the workflow.
workflow_dispatch:

jobs:
phpcs:
runs-on: [ubuntu-latest]

strategy:
matrix:
paths: [
'app/code/core/Mage/',
'lib/Mage/',
'lib/Magento/',
'lib/Varien/',
'app/code/community/'
]

name: PHPCodeSniffer ${{ matrix.paths }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Validate composer
run: composer validate --strict

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-progress --ignore-platform-req=ext-*

- name: PHPCodeSniffer
run: php vendor/bin/phpcs -s --report=full --standard=.github/phpcs-ruleset.xml ${{ matrix.paths }}
continue-on-error: ${{ matrix.paths == 'app/code/community/' }}
2 changes: 1 addition & 1 deletion app/code/core/Mage/Admin/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Mage_Admin_Helper_Data extends Mage_Core_Helper_Abstract
/**
* Configuration path to expiration period of reset password link
*/
const XML_PATH_ADMIN_RESET_PASSWORD_LINK_EXPIRATION_PERIOD
public const XML_PATH_ADMIN_RESET_PASSWORD_LINK_EXPIRATION_PERIOD
= 'default/admin/emails/password_reset_link_expiration_period';

/**
Expand Down
10 changes: 5 additions & 5 deletions app/code/core/Mage/Admin/Model/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,31 @@ class Mage_Admin_Model_Acl extends Zend_Acl
* All the group roles are prepended by G
*
*/
const ROLE_TYPE_GROUP = 'G';
public const ROLE_TYPE_GROUP = 'G';

/**
* All the user roles are prepended by U
*
*/
const ROLE_TYPE_USER = 'U';
public const ROLE_TYPE_USER = 'U';

/**
* Permission level to deny access
*
*/
const RULE_PERM_DENY = 0;
public const RULE_PERM_DENY = 0;

/**
* Permission level to inheric access from parent role
*
*/
const RULE_PERM_INHERIT = 1;
public const RULE_PERM_INHERIT = 1;

/**
* Permission level to allow access
*
*/
const RULE_PERM_ALLOW = 2;
public const RULE_PERM_ALLOW = 2;

/**
* Get role registry object or create one
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Admin/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct()
if ($adminhtmlConfig) {
$this->_adminhtmlConfig = new Varien_Simplexml_Config($adminhtmlConfig);
} else {
$adminhtmlConfig = new Varien_Simplexml_Config;
$adminhtmlConfig = new Varien_Simplexml_Config();
$adminhtmlConfig->loadString('<?xml version="1.0"?><config></config>');
Mage::getConfig()->loadModulesConfiguration('adminhtml.xml', $adminhtmlConfig);
$this->_adminhtmlConfig = $adminhtmlConfig;
Expand Down
5 changes: 2 additions & 3 deletions app/code/core/Mage/Admin/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
class Mage_Admin_Model_Observer
{
const FLAG_NO_LOGIN = 'no-login';
public const FLAG_NO_LOGIN = 'no-login';

/**
* Handler for controller_action_predispatch event
Expand Down Expand Up @@ -132,8 +132,7 @@ public function actionAdminAuthenticate($observer)
return;
}

if (
!(bool) $user->getPasswordUpgraded()
if (!(bool) $user->getPasswordUpgraded()
&& !Mage::helper('core')->getEncryptor()->validateHashByVersion(
$password,
$user->getPassword(),
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Admin/Model/Resource/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
class Mage_Admin_Model_Resource_Acl extends Mage_Core_Model_Resource_Db_Abstract
{
const ACL_ALL_RULES = 'all';
public const ACL_ALL_RULES = 'all';

/**
* Initialize resource
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Admin/Model/Resource/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Mage_Admin_Model_Resource_Block extends Mage_Core_Model_Resource_Db_Abstra
/**
* Cache id
*/
const CACHE_ID = 'permission_block';
public const CACHE_ID = 'permission_block';

/**
* Disallowed names for block
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Admin/Model/Resource/Variable.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
class Mage_Admin_Model_Resource_Variable extends Mage_Core_Model_Resource_Db_Abstract
{
const CACHE_ID = 'permission_variable';
public const CACHE_ID = 'permission_variable';

protected function _construct()
{
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Admin/Model/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class Mage_Admin_Model_Rules extends Mage_Core_Model_Abstract
/**
* Allowed permission code
*/
const RULE_PERMISSION_ALLOWED = 'allow';
public const RULE_PERMISSION_ALLOWED = 'allow';

/**
* Denied permission code
*/
const RULE_PERMISSION_DENIED = 'deny';
public const RULE_PERMISSION_DENIED = 'deny';

protected function _construct()
{
Expand Down
5 changes: 2 additions & 3 deletions app/code/core/Mage/Admin/Model/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Mage_Admin_Model_Session extends Mage_Core_Model_Session_Abstract
*
* @const
*/
const XML_PATH_ALLOW_SID_FOR_ADMIN_AREA = 'web/session/use_admin_sid';
public const XML_PATH_ALLOW_SID_FOR_ADMIN_AREA = 'web/session/use_admin_sid';

/**
* Whether it is the first page after successfull login
Expand Down Expand Up @@ -129,8 +129,7 @@ protected function logoutIndirect()
$user = $this->getUser();
if ($user) {
$extraData = $user->getExtra();
if (
!is_null(Mage::app()->getRequest()->getParam('SID'))
if (!is_null(Mage::app()->getRequest()->getParam('SID'))
&& !$this->allowAdminSid()
|| isset($extraData['indirect_login'])
&& $this->getIndirectLogin()
Expand Down
18 changes: 9 additions & 9 deletions app/code/core/Mage/Admin/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,35 +80,35 @@ class Mage_Admin_Model_User extends Mage_Core_Model_Abstract
/**#@+
* Configuration paths for email templates and identities
*/
const XML_PATH_FORGOT_EMAIL_TEMPLATE = 'admin/emails/forgot_email_template';
const XML_PATH_FORGOT_EMAIL_IDENTITY = 'admin/emails/forgot_email_identity';
const XML_PATH_STARTUP_PAGE = 'admin/startup/page';
public const XML_PATH_FORGOT_EMAIL_TEMPLATE = 'admin/emails/forgot_email_template';
public const XML_PATH_FORGOT_EMAIL_IDENTITY = 'admin/emails/forgot_email_identity';
public const XML_PATH_STARTUP_PAGE = 'admin/startup/page';

/** Configuration paths for notifications */
const XML_PATH_ADDITIONAL_EMAILS = 'general/additional_notification_emails/admin_user_create';
const XML_PATH_NOTIFICATION_EMAILS_TEMPLATE = 'admin/emails/admin_notification_email_template';
public const XML_PATH_ADDITIONAL_EMAILS = 'general/additional_notification_emails/admin_user_create';
public const XML_PATH_NOTIFICATION_EMAILS_TEMPLATE = 'admin/emails/admin_notification_email_template';
/**#@-*/

/**
* Minimum length of admin password
* @deprecated Use getMinAdminPasswordLength() method instead
*/
const MIN_PASSWORD_LENGTH = 14;
public const MIN_PASSWORD_LENGTH = 14;

/**
* Configuration path for minimum length of admin password
*/
const XML_PATH_MIN_ADMIN_PASSWORD_LENGTH = 'admin/security/min_admin_password_length';
public const XML_PATH_MIN_ADMIN_PASSWORD_LENGTH = 'admin/security/min_admin_password_length';

/**
* Length of salt
*/
const HASH_SALT_LENGTH = 32;
public const HASH_SALT_LENGTH = 32;

/**
* Empty hash salt
*/
const HASH_SALT_EMPTY = null;
public const HASH_SALT_EMPTY = null;

/**
* Model event prefix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
'admin/xmlconnect/templates'
];


$installer->getConnection()->delete(
$installer->getTable('admin/rule'),
['resource_id IN (?)' => $obsoleteAcl]
Expand Down
8 changes: 4 additions & 4 deletions app/code/core/Mage/AdminNotification/Model/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
*/
class Mage_AdminNotification_Model_Feed extends Mage_Core_Model_Abstract
{
const XML_USE_HTTPS_PATH = 'system/adminnotification/use_https';
const XML_FEED_URL_PATH = 'system/adminnotification/feed_url';
const XML_FREQUENCY_PATH = 'system/adminnotification/frequency';
const XML_LAST_UPDATE_PATH = 'system/adminnotification/last_update';
public const XML_USE_HTTPS_PATH = 'system/adminnotification/use_https';
public const XML_FEED_URL_PATH = 'system/adminnotification/feed_url';
public const XML_FREQUENCY_PATH = 'system/adminnotification/frequency';
public const XML_LAST_UPDATE_PATH = 'system/adminnotification/last_update';

/**
* Feed url
Expand Down
8 changes: 4 additions & 4 deletions app/code/core/Mage/AdminNotification/Model/Inbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
*/
class Mage_AdminNotification_Model_Inbox extends Mage_Core_Model_Abstract
{
const SEVERITY_CRITICAL = 1;
const SEVERITY_MAJOR = 2;
const SEVERITY_MINOR = 3;
const SEVERITY_NOTICE = 4;
public const SEVERITY_CRITICAL = 1;
public const SEVERITY_MAJOR = 2;
public const SEVERITY_MINOR = 3;
public const SEVERITY_NOTICE = 4;

protected function _construct()
{
Expand Down
20 changes: 12 additions & 8 deletions app/code/core/Mage/Adminhtml/Block/Api/Buttons.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,27 @@ public function __construct()

protected function _prepareLayout()
{
$this->setChild('backButton',
$this->setChild(
'backButton',
$this->getLayout()->createBlock('adminhtml/widget_button')
->setData([
'label' => Mage::helper('adminhtml')->__('Back'),
'onclick' => 'window.location.href=\''.$this->getUrl('*/*/').'\'',
'onclick' => 'window.location.href=\'' . $this->getUrl('*/*/') . '\'',
'class' => 'back'
])
);

$this->setChild('resetButton',
$this->setChild(
'resetButton',
$this->getLayout()->createBlock('adminhtml/widget_button')
->setData([
'label' => Mage::helper('adminhtml')->__('Reset'),
'onclick' => 'window.location.reload()'
])
);

$this->setChild('saveButton',
$this->setChild(
'saveButton',
$this->getLayout()->createBlock('adminhtml/widget_button')
->setData([
'label' => Mage::helper('adminhtml')->__('Save Role'),
Expand All @@ -60,13 +63,14 @@ protected function _prepareLayout()
])
);

$this->setChild('deleteButton',
$this->setChild(
'deleteButton',
$this->getLayout()->createBlock('adminhtml/widget_button')
->setData([
'label' => Mage::helper('adminhtml')->__('Delete Role'),
'onclick' => 'if(confirm(\'' . Mage::helper('core')->jsQuoteEscape(
Mage::helper('adminhtml')->__('Are you sure you want to do this?')
) . '\')) roleForm.submit(\'' . $this->getUrl('*/*/delete') . '\'); return false;',
Mage::helper('adminhtml')->__('Are you sure you want to do this?')
) . '\')) roleForm.submit(\'' . $this->getUrl('*/*/delete') . '\'); return false;',
'class' => 'delete'
])
);
Expand All @@ -90,7 +94,7 @@ public function getSaveButtonHtml()

public function getDeleteButtonHtml()
{
if( intval($this->getRequest()->getParam('rid')) == 0 ) {
if (intval($this->getRequest()->getParam('rid')) == 0) {
return;
}
return $this->getChildHtml('deleteButton');
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Api/Editroles.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function _beforeToHtml()
'content' => $this->getLayout()->createBlock('adminhtml/api_tab_rolesedit')->toHtml(),
]);

if( intval($roleId) > 0 ) {
if (intval($roleId) > 0) {
$this->addTab('roles', [
'label' => Mage::helper('adminhtml')->__('Role Users'),
'title' => Mage::helper('adminhtml')->__('Role Users'),
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Api/Edituser.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function _beforeToHtml()
'content' => $this->getLayout()->createBlock('adminhtml/api_tab_useredit')->toHtml(),
'active' => true
]);
if( $this->getUser()->getUserId() ) {
if ($this->getUser()->getUserId()) {
$this->addTab('roles', [
'label' => Mage::helper('adminhtml')->__('Roles'),
'title' => Mage::helper('adminhtml')->__('Roles'),
Expand Down
Loading

0 comments on commit 2afbba9

Please sign in to comment.