|
| 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; |
0 commit comments