Skip to content

Commit 572951a

Browse files
authored
[4.0] php-cs-fixer v3.0 Support (joomla#33908)
1 parent ebd801a commit 572951a

7 files changed

Lines changed: 485 additions & 342 deletions

File tree

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
/configuration.php
1919
/.htaccess
2020
/web.config
21-
/.php_cs
22-
/.php_cs.cache
21+
/.php-cs-fixer.cache
2322
/media
2423

2524
# Template CSS files generated by NPM

.php-cs-fixer.dist.php

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
/**
3+
* @package Joomla.Site
4+
*
5+
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
6+
* @license GNU General Public License version 2 or later; see LICENSE.txt
7+
*/
8+
9+
/**
10+
* This is the configuration file for php-cs-fixer
11+
*
12+
* @see https://github.com/FriendsOfPHP/PHP-CS-Fixer
13+
* @see https://mlocati.github.io/php-cs-fixer-configurator/#version:3.0
14+
*
15+
*
16+
* If you would like to run the automated clean up, then open a command line and type one of the commands below
17+
*
18+
* To run a quick dry run to see the files that would be modified:
19+
*
20+
* ./libraries/vendor/bin/php-cs-fixer fix --dry-run
21+
*
22+
* To run a full check, with automated fixing of each problem :
23+
*
24+
* ./libraries/vendor/bin/php-cs-fixer fix
25+
*
26+
* You can run the clean up on a single file if you need to, this is faster
27+
*
28+
* ./libraries/vendor/bin/php-cs-fixer fix --dry-run administrator/index.php
29+
* ./libraries/vendor/bin/php-cs-fixer fix administrator/index.php
30+
*/
31+
32+
// Only index the files in /libraries and no deeper, to prevent /libraries/vendor being indexed
33+
$topFilesFinder = PhpCsFixer\Finder::create()
34+
->in(
35+
[
36+
__DIR__ . '/libraries'
37+
]
38+
)
39+
->files()
40+
->depth(0);
41+
42+
// Add all the core Joomla folders and append to this list the files indexed above from /libraries
43+
$mainFinder = PhpCsFixer\Finder::create()
44+
->in(
45+
[
46+
__DIR__ . '/administrator',
47+
__DIR__ . '/api',
48+
__DIR__ . '/build',
49+
__DIR__ . '/cache',
50+
__DIR__ . '/cli',
51+
__DIR__ . '/components',
52+
__DIR__ . '/includes',
53+
__DIR__ . '/installation',
54+
__DIR__ . '/language',
55+
__DIR__ . '/libraries/src',
56+
__DIR__ . '/modules',
57+
__DIR__ . '/plugins',
58+
__DIR__ . '/templates',
59+
__DIR__ . '/tests',
60+
__DIR__ . '/layouts',
61+
]
62+
)
63+
->append($topFilesFinder);
64+
65+
$config = new PhpCsFixer\Config();
66+
$config
67+
->setRiskyAllowed(true)
68+
->setIndent("\t")
69+
->setRules(
70+
[
71+
// psr-1
72+
'encoding' => true,
73+
// psr-2
74+
'elseif' => true,
75+
'single_blank_line_at_eof' => true,
76+
'no_spaces_after_function_name' => true,
77+
'blank_line_after_namespace' => true,
78+
'line_ending' => true,
79+
'constant_case' => ['case' => 'lower'],
80+
'lowercase_keywords' => true,
81+
'method_argument_space' => true,
82+
'single_import_per_statement' => true,
83+
'no_spaces_inside_parenthesis' => true,
84+
'single_line_after_imports' => true,
85+
'no_trailing_whitespace' => true,
86+
// symfony
87+
'no_whitespace_before_comma_in_array' => true,
88+
'whitespace_after_comma_in_array' => true,
89+
'no_empty_statement' => true,
90+
'simplified_null_return' => true,
91+
'no_extra_blank_lines' => true,
92+
'function_typehint_space' => true,
93+
'include' => true,
94+
'no_alias_functions' => true,
95+
'no_trailing_comma_in_list_call' => true,
96+
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
97+
'no_blank_lines_after_class_opening' => true,
98+
'phpdoc_trim' => true,
99+
'blank_line_before_statement' => ['statements' => ['return']],
100+
'no_trailing_comma_in_singleline_array' => true,
101+
'single_blank_line_before_namespace' => true,
102+
'cast_spaces' => true,
103+
'no_unused_imports' => true,
104+
'no_whitespace_in_blank_line' => true,
105+
// contrib
106+
'concat_space' => ['spacing' => 'one'],
107+
/**
108+
* PHP 7+ zend_try_compile_special_func compiles certain PHP Functions to opcode which is faster
109+
* @see https://github.com/php/php-src/blob/9dc947522186766db4a7e2d603703a2250797577/Zend/zend_compile.c#L4192
110+
*/
111+
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced', 'strict' => true],
112+
]
113+
)
114+
->setFinder($mainFinder);
115+
116+
return $config;

.php_cs.dist

Lines changed: 0 additions & 61 deletions
This file was deleted.

build/build.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function clean_checkout(string $dir)
6060
system('find . -name .github | xargs rm -rf -');
6161
system('find . -name .gitignore | xargs rm -rf -');
6262
system('find . -name .gitmodules | xargs rm -rf -');
63-
system('find . -name .php_cs | xargs rm -rf -');
63+
system('find . -name .php-cs-fixer.dist.php | xargs rm -rf -');
6464
system('find . -name .scrutinizer.yml | xargs rm -rf -');
6565
system('find . -name .travis.yml | xargs rm -rf -');
6666
system('find . -name appveyor.yml | xargs rm -rf -');
@@ -361,7 +361,7 @@ function clean_composer(string $dir)
361361
'.editorconfig',
362362
'.github',
363363
'.gitignore',
364-
'.php_cs.dist',
364+
'.php-cs-fixer.dist.php',
365365
'CODE_OF_CONDUCT.md',
366366
'README.md',
367367
'acceptance.suite.yml',

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@
8888
"phpunit/phpunit": "^8.5",
8989
"joomla/cms-coding-standards": "~2.0.0-alpha2@dev",
9090
"joomla/coding-standards": "~3.0@dev",
91-
"friendsofphp/php-cs-fixer": "~2.12",
91+
"joomla/mediawiki": "dev-master",
92+
"friendsofphp/php-cs-fixer": "^3.0",
9293
"squizlabs/php_codesniffer": "~3.0",
9394
"joomla-projects/joomla-browser": "~4.0@dev",
9495
"codeception/codeception": "~4.0",

0 commit comments

Comments
 (0)