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