Skip to content

Commit 31ff920

Browse files
authored
Follow coding-standard PER-CS2.0 (#4372)
* Php-CS-Fixer: use PER-CS2.0 * Updated copyright * added files to php-cs-fixer * updated workflow * updated dev-meta-package * updated workflow * updated dev-meta-package * last fixes * clean config * clean config * updated composer.json * mark tests as incomplete * added badge * apply changes to new files * starting docs entry * cs * cs * cs * updated config * cs
1 parent 67d8042 commit 31ff920

File tree

2,892 files changed

+19219
-20812
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,892 files changed

+19219
-20812
lines changed

.github/workflows/phpcs.yml

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ jobs:
1313
strategy:
1414
matrix:
1515
rules:
16-
- label: Default
17-
path: .phpcs.dist.xml
1816
- label: Ecg
1917
path: .phpcs.dist.ecg.xml
2018
- label: PhpCompatibility

.github/workflows/workflow.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ jobs:
121121

122122
rector:
123123
name: Rector
124-
needs: [check, phpcs, php-cs-fixer]
124+
needs: [check, php-cs-fixer]
125125
if: |
126126
needs.check.outputs.php > 0 ||
127127
needs.check.outputs.workflow > 0

.php-cs-fixer.dist.php

+15-98
Original file line numberDiff line numberDiff line change
@@ -8,113 +8,30 @@
88
return $config
99
->setRiskyAllowed(true)
1010
->setRules([
11-
// PHP arrays should be declared using the configured syntax.
12-
'array_syntax' => ['syntax' => 'short'],
13-
// There MUST be one blank line after the namespace declaration.
14-
'blank_line_after_namespace' => true,
15-
// Ensure there is no code on the same line as the PHP open tag and it is followed by a blank line.
16-
'blank_line_after_opening_tag' => true,
17-
// The body of each structure MUST be enclosed by braces. Braces should be properly placed. Body of braces should be properly indented.
18-
'braces' => true,
19-
// Whitespace around the keywords of a class, trait or interfaces definition should be one space.
20-
'class_definition' => true,
21-
// Remove extra spaces in a nullable typehint.
22-
'compact_nullable_typehint' => true,
23-
// Concatenation should be spaced according to configuration.
24-
'concat_space' => ['spacing' => 'one'],
25-
// The PHP constants `true`, `false`, and `null` MUST be written using the correct casing.
26-
'constant_case' => true,
27-
// Equal sign in declare statement should be surrounded by spaces or not following configuration.
28-
'declare_equal_normalize' => true,
29-
// The keyword `elseif` should be used instead of `else if` so that all control keywords look like single words.
30-
'elseif' => true,
31-
// PHP code MUST use only UTF-8 without BOM (remove BOM).
32-
'encoding' => true,
33-
// PHP code must use the long `<?php` tags or short-echo `<?=` tags and not other tag variations.
34-
'full_opening_tag' => true,
35-
// Spaces should be properly placed in a function declaration.
36-
'function_declaration' => true,
37-
// Code MUST use configured indentation type.
38-
'indentation_type' => true,
39-
// All PHP files must use same line ending.
40-
'line_ending' => true,
41-
// Use && and || logical operators instead of and and or.
11+
// see https://cs.symfony.com/doc/ruleSets/PER-CS2.0.html
12+
'@PER-CS2.0' => true,
13+
// RISKY: Use && and || logical operators instead of and and or.
4214
'logical_operators' => true,
43-
// Cast should be written in lower case.
44-
'lowercase_cast' => true,
45-
// PHP keywords MUST be in lower case.
46-
'lowercase_keywords' => true,
47-
// Class static references `self`, `static` and `parent` MUST be in lower case.
48-
'lowercase_static_reference' => true,
49-
// 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.
50-
'method_argument_space' => true,
51-
// Replaces intval, floatval, doubleval, strval and boolval function calls with according type casting operator.
15+
// RISKY: Replaces intval, floatval, doubleval, strval and boolval function calls with according type casting operator.
5216
'modernize_types_casting' => true,
53-
// All instances created with new keyword must be followed by braces.
54-
'new_with_braces' => true,
55-
// There should be no empty lines after class opening brace.
56-
'no_blank_lines_after_class_opening' => true,
57-
// There must be a comment when fall-through is intentional in a non-empty case body.
58-
'no_break_comment' => true,
59-
// The closing `? >` tag MUST be omitted from files containing only PHP.
60-
'no_closing_tag' => true,
61-
// Remove leading slashes in `use` clauses.
62-
'no_leading_import_slash' => true,
63-
// There must be no space around double colons (also called Scope Resolution Operator or Paamayim Nekudotayim).
64-
'no_space_around_double_colon' => true,
65-
// When making a method or function call, there MUST NOT be a space between the method or function name and the opening parenthesis.
66-
'no_spaces_after_function_name' => true,
67-
// There MUST NOT be a space after the opening parenthesis. There MUST NOT be a space before the closing parenthesis.
68-
'no_spaces_inside_parenthesis' => true,
69-
// Remove trailing whitespace at the end of non-blank lines.
70-
'no_trailing_whitespace' => true,
71-
// There MUST be no trailing spaces inside comment or PHPDoc.
72-
'no_trailing_whitespace_in_comment' => true,
73-
// Remove trailing whitespace at the end of blank lines.
74-
'no_whitespace_in_blank_line' => true,
75-
// Adds or removes ? before single type declarations or |null at the end of union types when parameters have a default null value.
17+
// PHP84: Adds or removes ? before single type declarations or |null at the end of union types when parameters have a default null value.
7618
'nullable_type_declaration_for_default_null_value' => true,
77-
// Orders the elements of classes/interfaces/traits.
78-
'ordered_class_elements' => false,
79-
// Ordering `use` statements.
80-
'ordered_imports' => true,
81-
// There should be one or no space before colon, and one space after it in return type declarations, according to configuration.
82-
'return_type_declaration' => true,
83-
// Cast `(boolean)` and `(integer)` should be written as `(bool)` and `(int)`, `(double)` and `(real)` as `(float)`, `(binary)` as `(string)`.
84-
'short_scalar_cast' => true,
85-
// A PHP file without end tag must always end with a single empty line feed.
86-
'single_blank_line_at_eof' => true,
87-
// There should be exactly one blank line before a namespace declaration.
88-
'single_blank_line_before_namespace' => true,
89-
// There MUST NOT be more than one property or constant declared per statement.
90-
'single_class_element_per_statement' => true,
91-
// There MUST be one use keyword per declaration.
92-
'single_import_per_statement' => true,
93-
// Each namespace use MUST go on its own line and there MUST be one blank line after the use statements block.
94-
'single_line_after_imports' => true,
9519
// Convert double quotes to single quotes for simple strings.
9620
'single_quote' => true,
97-
// Each trait `use` must be done as single statement.
98-
'single_trait_insert_per_statement' => true,
99-
// A case should be followed by a colon and not a semicolon.
100-
'switch_case_semicolon_to_colon' => true,
101-
// Removes extra spaces between colon and case value.
102-
'switch_case_space' => true,
103-
// Standardize spaces around ternary operator.
104-
'ternary_operator_spaces' => true,
105-
// 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.
106-
'visibility_required' => true,
21+
// Arguments lists, array destructuring lists, arrays that are multi-line, match-lines and parameters lists must have a trailing comma.
22+
// removed "match" and "parameters" for PHP7
23+
// see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/8308
24+
'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays']],
10725
])
10826
->setFinder(
10927
PhpCsFixer\Finder::create()
11028
->in([
111-
'app/code/core/Mage/',
112-
'errors/',
113-
'lib/Mage/',
114-
'lib/Magento/',
115-
'lib/Varien/',
116-
'shell/',
117-
'tests/unit/',
29+
__DIR__,
30+
])
31+
->exclude([
32+
'lib/3Dsecure/',
33+
'lib/LinLibertineFont/',
34+
'lib/Unserialize/',
11835
])
11936
->name('*.php')
12037
->ignoreDotFiles(true)

.phpcs.dist.xml

-62
This file was deleted.

.phpcs.xml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0"?>
22
<ruleset name="OpenMage All" namespace="OpenMage\CS\Standard">
3-
<rule ref=".phpcs.dist.xml" />
43
<rule ref=".phpcs.dist.php.xml" />
54
<rule ref=".phpcs.dist.ecg.xml" />
65
</ruleset>

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
[![All Contributors](https://img.shields.io/github/all-contributors/openmage/magento-lts?color=ee8449)](#contributors)
2-
<a href="https://packagist.org/packages/openmage/magento-lts"><img src="https://poser.pugx.org/openmage/magento-lts/d/total.svg" alt="Total Downloads"></a>
3-
<a href="https://packagist.org/packages/openmage/magento-lts"><img src="https://poser.pugx.org/openmage/magento-lts/license.svg" alt="License"></a>
4-
<a href="https://github.com/openmage/magento-lts/actions/workflows/security-php.yml"><img src="https://github.com/openmage/magento-lts/actions/workflows/security-php.yml/badge.svg" alt="PHP Security workflow Badge" /></a>
5-
<a href="https://github.com/OpenMage/magento-lts/actions/workflows/workflow.yml"><img src="https://github.com/OpenMage/magento-lts/actions/workflows/workflow.yml/badge.svg" alt="CI workflow Badge" /></a>
2+
[![Version](http://poser.pugx.org/openmage/magento-lts/version)](https://packagist.org/packages/openmage/magento-lts)
3+
![https://packagist.org/packages/openmage/magento-lts](https://poser.pugx.org/openmage/magento-lts/license.svg)
4+
![https://packagist.org/packages/openmage/magento-lts](https://poser.pugx.org/openmage/magento-lts/d/total.svg)
5+
![https://github.com/openmage/magento-lts/actions/workflows/security-php.yml](https://github.com/openmage/magento-lts/actions/workflows/security-php.yml/badge.svg)
6+
![https://github.com/OpenMage/magento-lts/actions/workflows/workflow.yml](https://github.com/OpenMage/magento-lts/actions/workflows/workflow.yml/badge.svg)
7+
![https://www.php-fig.org/per/coding-style/](https://img.shields.io/badge/Coding%20standard-PER2.0-white.svg)
68

79
# Magento - Long Term Support
810

api.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* OpenMage
45
*

app/Mage.php

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* OpenMage
45
*
@@ -37,15 +38,15 @@
3738

3839
$appPath = implode(PS, $paths);
3940
set_include_path($appPath . PS . Mage::registry('original_include_path'));
40-
include_once "Mage/Core/functions.php";
41-
include_once "Varien/Autoload.php";
41+
include_once 'Mage/Core/functions.php';
42+
include_once 'Varien/Autoload.php';
4243

4344
Varien_Autoload::register();
4445

4546
/** AUTOLOADER PATCH **/
4647
$autoloaderPath = getenv('COMPOSER_VENDOR_PATH');
4748
if (!$autoloaderPath) {
48-
$autoloaderPath = dirname(BP) . DS . 'vendor';
49+
$autoloaderPath = dirname(BP) . DS . 'vendor';
4950
if (!is_dir($autoloaderPath)) {
5051
$autoloaderPath = BP . DS . 'vendor';
5152
}
@@ -150,7 +151,7 @@ final class Mage
150151
public static function getVersion()
151152
{
152153
$i = self::getVersionInfo();
153-
return trim("{$i['major']}.{$i['minor']}.{$i['revision']}" . ($i['patch'] != '' ? ".{$i['patch']}" : "")
154+
return trim("{$i['major']}.{$i['minor']}.{$i['revision']}" . ($i['patch'] != '' ? ".{$i['patch']}" : '')
154155
. "-{$i['stability']}{$i['number']}", '.-');
155156
}
156157

@@ -835,7 +836,7 @@ public static function isInstalled($options = [])
835836
if (is_readable($localConfigFile)) {
836837
$localConfig = simplexml_load_file($localConfigFile);
837838
date_default_timezone_set('UTC');
838-
if (($date = $localConfig->global->install->date) && strtotime((string)$date)) {
839+
if (($date = $localConfig->global->install->date) && strtotime((string) $date)) {
839840
self::$_isInstalled = true;
840841
}
841842
}
@@ -892,7 +893,7 @@ public static function log($message, $level = null, $file = '', $forceLog = fals
892893
// Validate file extension before save. Allowed file extensions: log, txt, html, csv
893894
$_allowedFileExtensions = explode(
894895
',',
895-
(string) self::getConfig()->getNode('dev/log/allowedFileExtensions', Mage_Core_Model_Store::DEFAULT_CODE)
896+
(string) self::getConfig()->getNode('dev/log/allowedFileExtensions', Mage_Core_Model_Store::DEFAULT_CODE),
896897
);
897898
if (! ($extension = pathinfo($file, PATHINFO_EXTENSION)) || ! in_array($extension, $_allowedFileExtensions)) {
898899
return;
@@ -913,7 +914,7 @@ public static function log($message, $level = null, $file = '', $forceLog = fals
913914

914915
$format = '%timestamp% %priorityName% (%priority%): %message%' . PHP_EOL;
915916
$formatter = new Zend_Log_Formatter_Simple($format);
916-
$writerModel = (string)self::getConfig()->getNode('global/log/core/writer_model');
917+
$writerModel = (string) self::getConfig()->getNode('global/log/core/writer_model');
917918
if (!self::$_app || !$writerModel) {
918919
$writer = new Zend_Log_Writer_Stream($logFile);
919920
} else {
@@ -953,7 +954,7 @@ public static function logException(Throwable $e)
953954
*/
954955
public static function setIsDeveloperMode($mode)
955956
{
956-
self::$_isDeveloperMode = (bool)$mode;
957+
self::$_isDeveloperMode = (bool) $mode;
957958
return self::$_isDeveloperMode;
958959
}
959960

@@ -985,7 +986,7 @@ public static function printException(Throwable $e, $extra = '')
985986
} else {
986987
$reportData = [
987988
(!empty($extra) ? $extra . "\n\n" : '') . $e->getMessage(),
988-
$e->getTraceAsString()
989+
$e->getTraceAsString(),
989990
];
990991

991992
// retrieve server data

app/bootstrap.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* OpenMage
45
*

app/code/core/Mage/Admin/Model/Acl/Resource.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,4 @@
2020
* @category Mage
2121
* @package Mage_Admin
2222
*/
23-
class Mage_Admin_Model_Acl_Resource extends Zend_Acl_Resource
24-
{
25-
}
23+
class Mage_Admin_Model_Acl_Resource extends Zend_Acl_Resource {}

app/code/core/Mage/Admin/Model/Acl/Role/Generic.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,4 @@
2020
* @category Mage
2121
* @package Mage_Admin
2222
*/
23-
class Mage_Admin_Model_Acl_Role_Generic extends Zend_Acl_Role
24-
{
25-
}
23+
class Mage_Admin_Model_Acl_Role_Generic extends Zend_Acl_Role {}

app/code/core/Mage/Admin/Model/Acl/Role/Group.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,4 @@
2020
* @category Mage
2121
* @package Mage_Admin
2222
*/
23-
class Mage_Admin_Model_Acl_Role_Group extends Mage_Admin_Model_Acl_Role_Generic
24-
{
25-
}
23+
class Mage_Admin_Model_Acl_Role_Group extends Mage_Admin_Model_Acl_Role_Generic {}

app/code/core/Mage/Admin/Model/Acl/Role/User.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,4 @@
2020
* @category Mage
2121
* @package Mage_Admin
2222
*/
23-
class Mage_Admin_Model_Acl_Role_User extends Mage_Admin_Model_Acl_Role_Generic
24-
{
25-
}
23+
class Mage_Admin_Model_Acl_Role_User extends Mage_Admin_Model_Acl_Role_Generic {}

app/code/core/Mage/Admin/Model/Config.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function __construct()
6363
Mage::app()->saveCache(
6464
$adminhtmlConfig->getXmlString(),
6565
$this->getCacheId(),
66-
[Mage_Core_Model_Config::CACHE_TAG]
66+
[Mage_Core_Model_Config::CACHE_TAG],
6767
);
6868
}
6969
}
@@ -162,8 +162,8 @@ public function getMenuItemLabel($path)
162162
$moduleName = 'adminhtml';
163163
$menuNode = $this->getAdminhtmlConfig()->getNode('menu/' . str_replace('/', '/children/', trim($path, '/')));
164164
if ($menuNode->getAttribute('module')) {
165-
$moduleName = (string)$menuNode->getAttribute('module');
165+
$moduleName = (string) $menuNode->getAttribute('module');
166166
}
167-
return Mage::helper($moduleName)->__((string)$menuNode->title);
167+
return Mage::helper($moduleName)->__((string) $menuNode->title);
168168
}
169169
}

app/code/core/Mage/Admin/Model/Mysql4/Acl.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,4 @@
2121
* @package Mage_Admin
2222
* @deprecated
2323
*/
24-
class Mage_Admin_Model_Mysql4_Acl extends Mage_Admin_Model_Resource_Acl
25-
{
26-
}
24+
class Mage_Admin_Model_Mysql4_Acl extends Mage_Admin_Model_Resource_Acl {}

app/code/core/Mage/Admin/Model/Mysql4/Acl/Role.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,4 @@
2121
* @package Mage_Admin
2222
* @deprecated
2323
*/
24-
class Mage_Admin_Model_Mysql4_Acl_Role extends Mage_Admin_Model_Resource_Acl_Role
25-
{
26-
}
24+
class Mage_Admin_Model_Mysql4_Acl_Role extends Mage_Admin_Model_Resource_Acl_Role {}

app/code/core/Mage/Admin/Model/Mysql4/Acl/Role/Collection.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,4 @@
2121
* @package Mage_Admin
2222
* @deprecated
2323
*/
24-
class Mage_Admin_Model_Mysql4_Acl_Role_Collection extends Mage_Admin_Model_Resource_Acl_Role_Collection
25-
{
26-
}
24+
class Mage_Admin_Model_Mysql4_Acl_Role_Collection extends Mage_Admin_Model_Resource_Acl_Role_Collection {}

0 commit comments

Comments
 (0)