03c5f576ace5b505c5d4c7c32faf001cdfa83220
[Packages/TYPO3.CMS.git] / Build / .php_cs
1 <?php
2 /*
3 * This file is part of the TYPO3 CMS project.
4 *
5 * It is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License, either version 2
7 * of the License, or any later version.
8 *
9 * For the full copyright and license information, please read the
10 * LICENSE.txt file that was distributed with this source code.
11 *
12 * The TYPO3 project - inspiring people to share!
13 */
14 /**
15 * This file represents the configuration for Code Sniffing PSR-2-related
16 * automatic checks of coding guidelines
17 * Install @fabpot's great php-cs-fixer tool via
18 *
19 * $ composer global require friendsofphp/php-cs-fixer
20 *
21 * And then simply run
22 *
23 * $ php-cs-fixer fix --config ../Build/.php_cs
24 *
25 * inside the TYPO3 directory. Warning: This may take up to 10 minutes.
26 *
27 * For more information read:
28 * https://www.php-fig.org/psr/psr-2/
29 * https://cs.sensiolabs.org
30 */
31 if (PHP_SAPI !== 'cli') {
32 die('This script supports command line usage only. Please check your command.');
33 }
34 // Define in which folders to search and which folders to exclude
35 // Exclude some directories that are excluded by Git anyways to speed up the sniffing
36 $finder = PhpCsFixer\Finder::create()
37 ->exclude('vendor')
38 ->exclude('typo3conf')
39 ->exclude('typo3temp')
40 ->notName('install.php')
41 ->notName('index.php')
42 ->in(__DIR__ . '/../');
43 // Return a Code Sniffing configuration using
44 // all sniffers needed for PSR-2
45 // and additionally:
46 // - Remove leading slashes in use clauses.
47 // - PHP single-line arrays should not have trailing comma.
48 // - Single-line whitespace before closing semicolon are prohibited.
49 // - Remove unused use statements in the PHP source code
50 // - Ensure Concatenation to have at least one whitespace around
51 // - Remove trailing whitespace at the end of blank lines.
52 return PhpCsFixer\Config::create()
53 ->setRiskyAllowed(true)
54 ->setRules([
55 '@PSR2' => true,
56 '@DoctrineAnnotation' => true,
57 'no_leading_import_slash' => true,
58 'no_trailing_comma_in_singleline_array' => true,
59 'no_singleline_whitespace_before_semicolons' => true,
60 'no_unused_imports' => true,
61 'concat_space' => ['spacing' => 'one'],
62 'no_whitespace_in_blank_line' => true,
63 'ordered_imports' => true,
64 'single_quote' => true,
65 'no_empty_statement' => true,
66 'no_extra_consecutive_blank_lines' => true,
67 'phpdoc_no_package' => true,
68 'phpdoc_scalar' => true,
69 'no_blank_lines_after_phpdoc' => true,
70 'array_syntax' => ['syntax' => 'short'],
71 'whitespace_after_comma_in_array' => true,
72 'function_typehint_space' => true,
73 'hash_to_slash_comment' => true,
74 'no_alias_functions' => true,
75 'lowercase_cast' => true,
76 'no_leading_namespace_whitespace' => true,
77 'native_function_casing' => true,
78 'no_short_bool_cast' => true,
79 'no_unneeded_control_parentheses' => true,
80 'phpdoc_no_empty_return' => true,
81 'phpdoc_trim' => true,
82 'no_superfluous_elseif' => true,
83 'no_useless_else' => true,
84 'phpdoc_types' => true,
85 'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
86 'return_type_declaration' => ['space_before' => 'none'],
87 'cast_spaces' => ['space' => 'none'],
88 'declare_equal_normalize' => ['space' => 'single'],
89 'dir_constant' => true,
90 'phpdoc_no_access' => true
91 ])
92 ->setFinder($finder);