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

Add php-cs-fixer & PHPCompatibility check to workflow #2744

Merged
merged 35 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0f9da77
PHP-CS-Fixer fixes
sreichel Nov 18, 2022
1192d3a
Updated workflow
sreichel Nov 18, 2022
19a76cb
Added php-cs-fixer workflow
sreichel Nov 18, 2022
60bfbf1
Added PHPCompatibility check
sreichel Nov 19, 2022
bc189c2
PHPCompatibility check can fail
sreichel Nov 19, 2022
5429738
Fixes: Node.js 12 actions are deprecated
sreichel Nov 19, 2022
4fc5340
Fixes: PSR12.ControlStructures.ControlStructureSpacing.LineIndent
sreichel Nov 20, 2022
aa0283d
Fixes: PSR12.ControlStructures.ControlStructureSpacing.CloseParenthes…
sreichel Nov 20, 2022
5cca27f
Dond check CM_Redis every time
sreichel Nov 20, 2022
57cf7f0
Add .php-cs-fixer.cache to .gitignore
sreichel Nov 20, 2022
c8daec3
Fixes class name (wrong place ... i know)
sreichel Nov 20, 2022
b118da3
Minor fixes
sreichel Nov 20, 2022
ffd56f8
Merge branch '1.9.4.x' into php-cs-fixer
sreichel Nov 20, 2022
484bbeb
Merge branch '1.9.4.x' into php-cs-fixer
sreichel Nov 23, 2022
7973e5a
Combined workflows
sreichel Nov 23, 2022
2d8ab7a
Added app/Mage.php and files from root to rulesets
sreichel Nov 25, 2022
ec95fda
Remove unused phpstan_experimental_level.neon
sreichel Nov 25, 2022
6a23b1e
Updated phpstan.neon (for upcoming commits)
sreichel Nov 25, 2022
9f7b01c
Set PhpStan level to 5 (from 3)
sreichel Nov 25, 2022
eb9423a
Update phpstan to v1.9.2
sreichel Nov 25, 2022
c4a328f
Updated phpstan-baseline.neon
sreichel Nov 25, 2022
004869a
Merge branch '1.9.4.x' into php-cs-fixer
sreichel Nov 25, 2022
fcec648
Updated phpstan-baseline.neon
sreichel Nov 25, 2022
0379bad
Update app/code/core/Mage/Tag/Model/Resource/Tag.php
sreichel Nov 26, 2022
a52d86a
Update lib/Varien/Db/Adapter/Pdo/Mysql.php
sreichel Nov 26, 2022
9ad96c0
Set workflow include paths (skip other files)
sreichel Nov 26, 2022
71d4721
Updated labeler.yml
sreichel Nov 26, 2022
64e649d
Removed travis label
sreichel Nov 26, 2022
851799b
Improved workflow (#26)
sreichel Nov 26, 2022
e3ca32d
Fixed grep modifier to get correct count
sreichel Nov 26, 2022
a58e507
Updated ECG sniff baseline
sreichel Nov 28, 2022
29a3890
Merge branch '1.9.4.x' into php-cs-fixer
sreichel Nov 28, 2022
6e0c3ea
Added Mage_Centinal to PhpStan checks
sreichel Nov 28, 2022
d1e1a3b
Added Mage_PaypalUk to PhpStan checks
sreichel Nov 28, 2022
b4ab751
Update app/code/core/Mage/Paypal/Model/Config.php
sreichel Nov 29, 2022
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
106 changes: 106 additions & 0 deletions .github/php-cs-fixer-ruleset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
/*
* This document has been generated with
* https://mlocati.github.io/php-cs-fixer-configurator/#version:3.4.0|configurator
* you can change this configuration by importing this file.
*/
$config = new PhpCsFixer\Config();
return $config
->setRules([
// There MUST be one blank line after the namespace declaration.
'blank_line_after_namespace' => true,
// Ensure there is no code on the same line as the PHP open tag and it is followed by a blank line.
'blank_line_after_opening_tag' => true,
// The body of each structure MUST be enclosed by braces. Braces should be properly placed. Body of braces should be properly indented.
'braces' => true,
// Whitespace around the keywords of a class, trait or interfaces definition should be one space.
'class_definition' => true,
// Remove extra spaces in a nullable typehint.
'compact_nullable_typehint' => true,
// The PHP constants `true`, `false`, and `null` MUST be written using the correct casing.
'constant_case' => true,
// Equal sign in declare statement should be surrounded by spaces or not following configuration.
'declare_equal_normalize' => true,
// The keyword `elseif` should be used instead of `else if` so that all control keywords look like single words.
'elseif' => true,
// PHP code MUST use only UTF-8 without BOM (remove BOM).
'encoding' => true,
// PHP code must use the long `<?php` tags or short-echo `<?=` tags and not other tag variations.
'full_opening_tag' => true,
// Spaces should be properly placed in a function declaration.
'function_declaration' => true,
// Code MUST use configured indentation type.
'indentation_type' => true,
// All PHP files must use same line ending.
'line_ending' => true,
// Cast should be written in lower case.
'lowercase_cast' => true,
// PHP keywords MUST be in lower case.
'lowercase_keywords' => true,
// Class static references `self`, `static` and `parent` MUST be in lower case.
'lowercase_static_reference' => true,
// In method arguments and method call, there MUST NOT be a space before each comma and there MUST be one space after each comma. Argument lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one argument per line.
'method_argument_space' => true,
// All instances created with new keyword must be followed by braces.
'new_with_braces' => true,
// There should be no empty lines after class opening brace.
'no_blank_lines_after_class_opening' => true,
// There must be a comment when fall-through is intentional in a non-empty case body.
'no_break_comment' => true,
// The closing `? >` tag MUST be omitted from files containing only PHP.
'no_closing_tag' => true,
// Remove leading slashes in `use` clauses.
'no_leading_import_slash' => true,
// There must be no space around double colons (also called Scope Resolution Operator or Paamayim Nekudotayim).
'no_space_around_double_colon' => true,
// When making a method or function call, there MUST NOT be a space between the method or function name and the opening parenthesis.
'no_spaces_after_function_name' => true,
// There MUST NOT be a space after the opening parenthesis. There MUST NOT be a space before the closing parenthesis.
'no_spaces_inside_parenthesis' => true,
// Remove trailing whitespace at the end of non-blank lines.
'no_trailing_whitespace' => true,
// There MUST be no trailing spaces inside comment or PHPDoc.
'no_trailing_whitespace_in_comment' => true,
// Remove trailing whitespace at the end of blank lines.
'no_whitespace_in_blank_line' => true,
// Orders the elements of classes/interfaces/traits.
'ordered_class_elements' => false,
// Ordering `use` statements.
'ordered_imports' => true,
// There should be one or no space before colon, and one space after it in return type declarations, according to configuration.
'return_type_declaration' => true,
// Cast `(boolean)` and `(integer)` should be written as `(bool)` and `(int)`, `(double)` and `(real)` as `(float)`, `(binary)` as `(string)`.
'short_scalar_cast' => true,
// A PHP file without end tag must always end with a single empty line feed.
'single_blank_line_at_eof' => true,
// There should be exactly one blank line before a namespace declaration.
'single_blank_line_before_namespace' => true,
// There MUST NOT be more than one property or constant declared per statement.
'single_class_element_per_statement' => true,
// There MUST be one use keyword per declaration.
'single_import_per_statement' => true,
// Each namespace use MUST go on its own line and there MUST be one blank line after the use statements block.
'single_line_after_imports' => true,
// Each trait `use` must be done as single statement.
'single_trait_insert_per_statement' => true,
// A case should be followed by a colon and not a semicolon.
'switch_case_semicolon_to_colon' => true,
// Removes extra spaces between colon and case value.
'switch_case_space' => true,
// Standardize spaces around ternary operator.
'ternary_operator_spaces' => true,
// Visibility MUST be declared on all properties and methods; `abstract` and `final` MUST be declared before the visibility; `static` MUST be declared after the visibility.
'visibility_required' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->in([
'app/code/core/Mage/',
'lib/Mage/',
'lib/Magento/',
'lib/Varien/'
])
->name('*.php')
->ignoreDotFiles(true)
->ignoreVCS(true)
);
23 changes: 23 additions & 0 deletions .github/phpcs-ruleset-external.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<ruleset name="OpenMageExternal" namespace="OpenMage\CS\Standard">
<file>./../app/code/community/</file>
<file>./../app/code/local/</file>
<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" />
<rule ref="PHPCompatibility" />
</ruleset>
18 changes: 5 additions & 13 deletions .github/phpcs-ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?xml version="1.0"?>
<ruleset name="OpenMage Standard" namespace="OpenMage\CS\Standard">
<ruleset name="OpenMage" namespace="OpenMage\CS\Standard">
<file>./../app/code/core/Mage/</file>
<file>./../lib/Mage/</file>
<file>./../lib/Magento/</file>
<file>./../lib/Varien/</file>
<rule ref="PSR2">
<exclude name="Generic.Files.LineLength.TooLong"/>
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace"/>
Expand All @@ -16,16 +20,4 @@
<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>
47 changes: 47 additions & 0 deletions .github/workflows/phpcs-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "PHP-CS-Fixer 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/php-cs-fixer*'
- '.github/workflows/php-cs-fixer*'
pull_request:
paths:
- '**.php'
- '.github/php-cs-fixer*'
- '.github/workflows/php-cs-fixer*'
# Allow manually triggering the workflow.
workflow_dispatch:

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

name: PHP-CS-Fixer

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: PHP-CS-Fixer
run: php vendor/bin/php-cs-fixer fix --config=.github/php-cs-fixer-ruleset.php --diff --dry-run
18 changes: 9 additions & 9 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@ jobs:

strategy:
matrix:
paths: [
'app/code/core/Mage/',
'lib/Mage/',
'lib/Magento/',
'lib/Varien/',
'app/code/community/'
rules: [
'.github/phpcs-ruleset.xml',
'.github/phpcs-ruleset-external.xml'
]

name: PHPCodeSniffer ${{ matrix.paths }}
name: PHPCodeSniffer ${{ matrix.rules }}

steps:
- name: Checkout code
Expand All @@ -53,6 +50,9 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress --ignore-platform-req=ext-*

- name: Ensure existence of ./app/code/local
run: mkdir -p app/code/local

- 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/' }}
run: php vendor/bin/phpcs -s --report=full --standard=${{ matrix.rules }}
continue-on-error: ${{ matrix.rules != '.github/phpcs-ruleset.xml' }}
3 changes: 0 additions & 3 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress --ignore-platform-req=ext-*

- name: ensure existance of ./app/code/local
run: mkdir -p app/code/local

- name: PHPStan Static Analysis
run: php vendor/bin/phpstan.phar analyze -c ${{ matrix.config_files }}
continue-on-error: ${{ matrix.config_files == '.github/phpstan_experimental_level.neon' }}
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public function addColumn($name, $params)
{
$this->_columns[$name] = [
'label' => empty($params['label']) ? 'Column' : $params['label'],
'size' => empty($params['size']) ? false : $params['size'],
'style' => empty($params['style']) ? null : $params['style'],
'class' => empty($params['class']) ? null : $params['class'],
'size' => empty($params['size']) ? false : $params['size'],
'style' => empty($params['style']) ? null : $params['style'],
'class' => empty($params['class']) ? null : $params['class'],
'renderer' => false,
];
if ((!empty($params['renderer'])) && ($params['renderer'] instanceof Mage_Core_Block_Abstract)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function editAction()
Mage::register('checkout_agreement', $agreementModel);

$this->_initAction()
->_addBreadcrumb($id ? Mage::helper('checkout')->__('Edit Condition') : Mage::helper('checkout')->__('New Condition'), $id ? Mage::helper('checkout')->__('Edit Condition') : Mage::helper('checkout')->__('New Condition'))
->_addBreadcrumb($id ? Mage::helper('checkout')->__('Edit Condition') : Mage::helper('checkout')->__('New Condition'), $id ? Mage::helper('checkout')->__('Edit Condition') : Mage::helper('checkout')->__('New Condition'))
->_addContent($this->getLayout()->createBlock('adminhtml/checkout_agreement_edit')->setData('action', $this->getUrl('*/*/save')))
->renderLayout();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public function editAction()

$this->_initAction()
->_addBreadcrumb(
$classId ? Mage::helper('tax')->__('Edit Class') : Mage::helper('tax')->__('New Class'),
$classId ? Mage::helper('tax')->__('Edit Class') : Mage::helper('tax')->__('New Class')
$classId ? Mage::helper('tax')->__('Edit Class') : Mage::helper('tax')->__('New Class'),
$classId ? Mage::helper('tax')->__('Edit Class') : Mage::helper('tax')->__('New Class')
)
->_addContent(
$this->getLayout()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public function editAction()

$this->_initAction()
->_addBreadcrumb(
$classId ? Mage::helper('tax')->__('Edit Class') : Mage::helper('tax')->__('New Class'),
$classId ? Mage::helper('tax')->__('Edit Class') : Mage::helper('tax')->__('New Class')
$classId ? Mage::helper('tax')->__('Edit Class') : Mage::helper('tax')->__('New Class'),
$classId ? Mage::helper('tax')->__('Edit Class') : Mage::helper('tax')->__('New Class')
)
->_addContent(
$this->getLayout()->createBlock('adminhtml/tax_class_edit')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public function editAction()

$this->_initAction()
->_addBreadcrumb(
$taxRuleId ? Mage::helper('tax')->__('Edit Rule') : Mage::helper('tax')->__('New Rule'),
$taxRuleId ? Mage::helper('tax')->__('Edit Rule') : Mage::helper('tax')->__('New Rule')
$taxRuleId ? Mage::helper('tax')->__('Edit Rule') : Mage::helper('tax')->__('New Rule'),
$taxRuleId ? Mage::helper('tax')->__('Edit Rule') : Mage::helper('tax')->__('New Rule')
)
->_addContent($this->getLayout()->createBlock('adminhtml/tax_rule_edit')
->setData('action', $this->getUrl('*/tax_rule/save')))
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Api/Model/Server/Adapter/Soap.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ protected function _instantiateServer()
if (strpos(
$e->getMessage(),
"can't import schema from 'http://schemas.xmlsoap.org/soap/encoding/'"
) !== false
) !== false
) {
$retry = true;
sleep(1);
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Bundle/Model/Resource/Price/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ public function _calculateSpecialPrice($finalPrice, array $priceData, Mage_Core_
$store,
$priceData['special_from_date'],
$priceData['special_to_date']
)) {
)) {
$specialPrice = ($finalPrice * $specialPrice) / 100;
$finalPrice = min($finalPrice, $specialPrice);
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Model/Category/Indexer/Flat.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function matchEvent(Mage_Index_Model_Event $event)
$store->isObjectNew()
|| $store->dataHasChangedFor('group_id')
|| $store->dataHasChangedFor('root_category_id')
)) {
)) {
$result = true;
} else {
$result = false;
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Catalog/Model/Product/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ public function setBaseFile($file)

// add misc params as a hash
$miscParams = [
($this->_keepAspectRatio ? '' : 'non') . 'proportional',
($this->_keepFrame ? '' : 'no') . 'frame',
($this->_keepAspectRatio ? '' : 'non') . 'proportional',
($this->_keepFrame ? '' : 'no') . 'frame',
($this->_keepTransparency ? '' : 'no') . 'transparency',
($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
$this->_rgbToString($this->_backgroundColor),
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/CatalogSearch/Model/Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function addFilters($values)
$attribute,
$value,
$rate
)
)
) {
$hasConditions = true;
$this->_addSearchCriteria($attribute, $value);
Expand All @@ -188,7 +188,7 @@ public function addFilters($values)
$this->getProductCollection(),
$attribute,
$value
)) {
)) {
$hasConditions = true;
$this->_addSearchCriteria($attribute, $value);
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public function getOptionWeekdays($preserveCodes = false, $ucFirstCode = false)
{
$options = [];
$days = $this->getTranslationList('days');
$days = $preserveCodes ? $days['format']['wide'] : array_values($days['format']['wide']);
$days = $preserveCodes ? $days['format']['wide'] : array_values($days['format']['wide']);
foreach ($days as $code => $name) {
$options[] = [
'label' => $name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ protected function _loginPostRedirect()
if ($session->isLoggedIn()) {
if (!Mage::getStoreConfigFlag(
Mage_Customer_Helper_Data::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD
)) {
)) {
$referer = $this->getRequest()->getParam(Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME);
if ($referer) {
// Rebuild referer URL to handle the case when SID was changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function decorateUserType($value, $row, $column, $isExport)
{
$options = $column->getOptions();

$value = ($row->getCustomerId()) ? $options[1] : $options[0];
$value = ($row->getCustomerId()) ? $options[1] : $options[0];
return $value;
}

Expand Down
Loading