Skip to content

Commit

Permalink
Follow coding-standard PER-CS2.0 (#4372)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sreichel authored Dec 9, 2024
1 parent 67d8042 commit 31ff920
Show file tree
Hide file tree
Showing 2,892 changed files with 19,219 additions and 20,812 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ jobs:
strategy:
matrix:
rules:
- label: Default
path: .phpcs.dist.xml
- label: Ecg
path: .phpcs.dist.ecg.xml
- label: PhpCompatibility
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ jobs:

rector:
name: Rector
needs: [check, phpcs, php-cs-fixer]
needs: [check, php-cs-fixer]
if: |
needs.check.outputs.php > 0 ||
needs.check.outputs.workflow > 0
Expand Down
113 changes: 15 additions & 98 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,113 +8,30 @@
return $config
->setRiskyAllowed(true)
->setRules([
// PHP arrays should be declared using the configured syntax.
'array_syntax' => ['syntax' => 'short'],
// 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,
// Concatenation should be spaced according to configuration.
'concat_space' => ['spacing' => 'one'],
// 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,
// Use && and || logical operators instead of and and or.
// see https://cs.symfony.com/doc/ruleSets/PER-CS2.0.html
'@PER-CS2.0' => true,
// RISKY: Use && and || logical operators instead of and and or.
'logical_operators' => 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,
// Replaces intval, floatval, doubleval, strval and boolval function calls with according type casting operator.
// RISKY: Replaces intval, floatval, doubleval, strval and boolval function calls with according type casting operator.
'modernize_types_casting' => 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,
// Adds or removes ? before single type declarations or |null at the end of union types when parameters have a default null value.
// PHP84: Adds or removes ? before single type declarations or |null at the end of union types when parameters have a default null value.
'nullable_type_declaration_for_default_null_value' => 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,
// Convert double quotes to single quotes for simple strings.
'single_quote' => 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,
// Arguments lists, array destructuring lists, arrays that are multi-line, match-lines and parameters lists must have a trailing comma.
// removed "match" and "parameters" for PHP7
// see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/8308
'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays']],
])
->setFinder(
PhpCsFixer\Finder::create()
->in([
'app/code/core/Mage/',
'errors/',
'lib/Mage/',
'lib/Magento/',
'lib/Varien/',
'shell/',
'tests/unit/',
__DIR__,
])
->exclude([
'lib/3Dsecure/',
'lib/LinLibertineFont/',
'lib/Unserialize/',
])
->name('*.php')
->ignoreDotFiles(true)
Expand Down
62 changes: 0 additions & 62 deletions .phpcs.dist.xml

This file was deleted.

1 change: 0 additions & 1 deletion .phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0"?>
<ruleset name="OpenMage All" namespace="OpenMage\CS\Standard">
<rule ref=".phpcs.dist.xml" />
<rule ref=".phpcs.dist.php.xml" />
<rule ref=".phpcs.dist.ecg.xml" />
</ruleset>
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[![All Contributors](https://img.shields.io/github/all-contributors/openmage/magento-lts?color=ee8449)](#contributors)
<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>
<a href="https://packagist.org/packages/openmage/magento-lts"><img src="https://poser.pugx.org/openmage/magento-lts/license.svg" alt="License"></a>
<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>
<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>
[![Version](http://poser.pugx.org/openmage/magento-lts/version)](https://packagist.org/packages/openmage/magento-lts)
![https://packagist.org/packages/openmage/magento-lts](https://poser.pugx.org/openmage/magento-lts/license.svg)
![https://packagist.org/packages/openmage/magento-lts](https://poser.pugx.org/openmage/magento-lts/d/total.svg)
![https://github.com/openmage/magento-lts/actions/workflows/security-php.yml](https://github.com/openmage/magento-lts/actions/workflows/security-php.yml/badge.svg)
![https://github.com/OpenMage/magento-lts/actions/workflows/workflow.yml](https://github.com/OpenMage/magento-lts/actions/workflows/workflow.yml/badge.svg)
![https://www.php-fig.org/per/coding-style/](https://img.shields.io/badge/Coding%20standard-PER2.0-white.svg)

# Magento - Long Term Support

Expand Down
1 change: 1 addition & 0 deletions api.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* OpenMage
*
Expand Down
19 changes: 10 additions & 9 deletions app/Mage.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* OpenMage
*
Expand Down Expand Up @@ -37,15 +38,15 @@

$appPath = implode(PS, $paths);
set_include_path($appPath . PS . Mage::registry('original_include_path'));
include_once "Mage/Core/functions.php";
include_once "Varien/Autoload.php";
include_once 'Mage/Core/functions.php';
include_once 'Varien/Autoload.php';

Varien_Autoload::register();

/** AUTOLOADER PATCH **/
$autoloaderPath = getenv('COMPOSER_VENDOR_PATH');
if (!$autoloaderPath) {
$autoloaderPath = dirname(BP) . DS . 'vendor';
$autoloaderPath = dirname(BP) . DS . 'vendor';
if (!is_dir($autoloaderPath)) {
$autoloaderPath = BP . DS . 'vendor';
}
Expand Down Expand Up @@ -150,7 +151,7 @@ final class Mage
public static function getVersion()
{
$i = self::getVersionInfo();
return trim("{$i['major']}.{$i['minor']}.{$i['revision']}" . ($i['patch'] != '' ? ".{$i['patch']}" : "")
return trim("{$i['major']}.{$i['minor']}.{$i['revision']}" . ($i['patch'] != '' ? ".{$i['patch']}" : '')
. "-{$i['stability']}{$i['number']}", '.-');
}

Expand Down Expand Up @@ -835,7 +836,7 @@ public static function isInstalled($options = [])
if (is_readable($localConfigFile)) {
$localConfig = simplexml_load_file($localConfigFile);
date_default_timezone_set('UTC');
if (($date = $localConfig->global->install->date) && strtotime((string)$date)) {
if (($date = $localConfig->global->install->date) && strtotime((string) $date)) {
self::$_isInstalled = true;
}
}
Expand Down Expand Up @@ -892,7 +893,7 @@ public static function log($message, $level = null, $file = '', $forceLog = fals
// Validate file extension before save. Allowed file extensions: log, txt, html, csv
$_allowedFileExtensions = explode(
',',
(string) self::getConfig()->getNode('dev/log/allowedFileExtensions', Mage_Core_Model_Store::DEFAULT_CODE)
(string) self::getConfig()->getNode('dev/log/allowedFileExtensions', Mage_Core_Model_Store::DEFAULT_CODE),
);
if (! ($extension = pathinfo($file, PATHINFO_EXTENSION)) || ! in_array($extension, $_allowedFileExtensions)) {
return;
Expand All @@ -913,7 +914,7 @@ public static function log($message, $level = null, $file = '', $forceLog = fals

$format = '%timestamp% %priorityName% (%priority%): %message%' . PHP_EOL;
$formatter = new Zend_Log_Formatter_Simple($format);
$writerModel = (string)self::getConfig()->getNode('global/log/core/writer_model');
$writerModel = (string) self::getConfig()->getNode('global/log/core/writer_model');
if (!self::$_app || !$writerModel) {
$writer = new Zend_Log_Writer_Stream($logFile);
} else {
Expand Down Expand Up @@ -953,7 +954,7 @@ public static function logException(Throwable $e)
*/
public static function setIsDeveloperMode($mode)
{
self::$_isDeveloperMode = (bool)$mode;
self::$_isDeveloperMode = (bool) $mode;
return self::$_isDeveloperMode;
}

Expand Down Expand Up @@ -985,7 +986,7 @@ public static function printException(Throwable $e, $extra = '')
} else {
$reportData = [
(!empty($extra) ? $extra . "\n\n" : '') . $e->getMessage(),
$e->getTraceAsString()
$e->getTraceAsString(),
];

// retrieve server data
Expand Down
1 change: 1 addition & 0 deletions app/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* OpenMage
*
Expand Down
4 changes: 1 addition & 3 deletions app/code/core/Mage/Admin/Model/Acl/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
* @category Mage
* @package Mage_Admin
*/
class Mage_Admin_Model_Acl_Resource extends Zend_Acl_Resource
{
}
class Mage_Admin_Model_Acl_Resource extends Zend_Acl_Resource {}
4 changes: 1 addition & 3 deletions app/code/core/Mage/Admin/Model/Acl/Role/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
* @category Mage
* @package Mage_Admin
*/
class Mage_Admin_Model_Acl_Role_Generic extends Zend_Acl_Role
{
}
class Mage_Admin_Model_Acl_Role_Generic extends Zend_Acl_Role {}
4 changes: 1 addition & 3 deletions app/code/core/Mage/Admin/Model/Acl/Role/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
* @category Mage
* @package Mage_Admin
*/
class Mage_Admin_Model_Acl_Role_Group extends Mage_Admin_Model_Acl_Role_Generic
{
}
class Mage_Admin_Model_Acl_Role_Group extends Mage_Admin_Model_Acl_Role_Generic {}
4 changes: 1 addition & 3 deletions app/code/core/Mage/Admin/Model/Acl/Role/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
* @category Mage
* @package Mage_Admin
*/
class Mage_Admin_Model_Acl_Role_User extends Mage_Admin_Model_Acl_Role_Generic
{
}
class Mage_Admin_Model_Acl_Role_User extends Mage_Admin_Model_Acl_Role_Generic {}
6 changes: 3 additions & 3 deletions app/code/core/Mage/Admin/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct()
Mage::app()->saveCache(
$adminhtmlConfig->getXmlString(),
$this->getCacheId(),
[Mage_Core_Model_Config::CACHE_TAG]
[Mage_Core_Model_Config::CACHE_TAG],
);
}
}
Expand Down Expand Up @@ -162,8 +162,8 @@ public function getMenuItemLabel($path)
$moduleName = 'adminhtml';
$menuNode = $this->getAdminhtmlConfig()->getNode('menu/' . str_replace('/', '/children/', trim($path, '/')));
if ($menuNode->getAttribute('module')) {
$moduleName = (string)$menuNode->getAttribute('module');
$moduleName = (string) $menuNode->getAttribute('module');
}
return Mage::helper($moduleName)->__((string)$menuNode->title);
return Mage::helper($moduleName)->__((string) $menuNode->title);
}
}
4 changes: 1 addition & 3 deletions app/code/core/Mage/Admin/Model/Mysql4/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@
* @package Mage_Admin
* @deprecated
*/
class Mage_Admin_Model_Mysql4_Acl extends Mage_Admin_Model_Resource_Acl
{
}
class Mage_Admin_Model_Mysql4_Acl extends Mage_Admin_Model_Resource_Acl {}
4 changes: 1 addition & 3 deletions app/code/core/Mage/Admin/Model/Mysql4/Acl/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@
* @package Mage_Admin
* @deprecated
*/
class Mage_Admin_Model_Mysql4_Acl_Role extends Mage_Admin_Model_Resource_Acl_Role
{
}
class Mage_Admin_Model_Mysql4_Acl_Role extends Mage_Admin_Model_Resource_Acl_Role {}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@
* @package Mage_Admin
* @deprecated
*/
class Mage_Admin_Model_Mysql4_Acl_Role_Collection extends Mage_Admin_Model_Resource_Acl_Role_Collection
{
}
class Mage_Admin_Model_Mysql4_Acl_Role_Collection extends Mage_Admin_Model_Resource_Acl_Role_Collection {}
Loading

0 comments on commit 31ff920

Please sign in to comment.