|
| 1 | +<?php |
| 2 | +declare(strict_types = 1); |
| 3 | +namespace TYPO3\CodingStandards; |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of the TYPO3 project - inspiring people to share! |
| 7 | + * (c) 2019 Benni Mack |
| 8 | + * |
| 9 | + * For the full copyright and license information, please view |
| 10 | + * the LICENSE file that was distributed with this source code. |
| 11 | + */ |
| 12 | + |
| 13 | +use PhpCsFixer\Config; |
| 14 | + |
| 15 | +class CsFixerConfig extends Config |
| 16 | +{ |
| 17 | + private static $defaultHeader = <<<EOF |
| 18 | +{header} |
| 19 | +
|
| 20 | +It is free software; you can redistribute it and/or modify it under |
| 21 | +the terms of the GNU General Public License, either version 2 |
| 22 | +of the License, or any later version. |
| 23 | +
|
| 24 | +For the full copyright and license information, please read the |
| 25 | +LICENSE.txt file that was distributed with this source code. |
| 26 | +
|
| 27 | +The TYPO3 project - inspiring people to share! |
| 28 | +EOF; |
| 29 | + |
| 30 | + private static $typo3Rules = [ |
| 31 | + '@DoctrineAnnotation' => true, |
| 32 | + '@PSR2' => true, |
| 33 | + 'array_syntax' => ['syntax' => 'short'], |
| 34 | + 'cast_spaces' => ['space' => 'none'], |
| 35 | + 'concat_space' => ['spacing' => 'one'], |
| 36 | + 'declare_equal_normalize' => ['space' => 'single'], |
| 37 | + 'dir_constant' => true, |
| 38 | + 'function_typehint_space' => true, |
| 39 | + 'hash_to_slash_comment' => true, |
| 40 | + 'lowercase_cast' => true, |
| 41 | + 'modernize_types_casting' => true, |
| 42 | + 'native_function_casing' => true, |
| 43 | + 'no_alias_functions' => true, |
| 44 | + 'no_blank_lines_after_phpdoc' => true, |
| 45 | + 'no_empty_phpdoc' => true, |
| 46 | + 'no_empty_statement' => true, |
| 47 | + 'no_extra_consecutive_blank_lines' => true, |
| 48 | + 'no_leading_import_slash' => true, |
| 49 | + 'no_leading_namespace_whitespace' => true, |
| 50 | + 'no_null_property_initialization' => true, |
| 51 | + 'no_short_bool_cast' => true, |
| 52 | + 'no_singleline_whitespace_before_semicolons' => true, |
| 53 | + 'no_superfluous_elseif' => true, |
| 54 | + 'no_trailing_comma_in_singleline_array' => true, |
| 55 | + 'no_unneeded_control_parentheses' => true, |
| 56 | + 'no_unused_imports' => true, |
| 57 | + 'no_useless_else' => true, |
| 58 | + 'no_whitespace_in_blank_line' => true, |
| 59 | + 'ordered_imports' => true, |
| 60 | + 'php_unit_construct' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame'], |
| 61 | + 'php_unit_mock_short_will_return' => true, |
| 62 | + 'php_unit_test_case_static_method_calls' => ['call_type' => 'self'], |
| 63 | + 'phpdoc_no_access' => true, |
| 64 | + 'phpdoc_no_empty_return' => true, |
| 65 | + 'phpdoc_no_package' => true, |
| 66 | + 'phpdoc_scalar' => true, |
| 67 | + 'phpdoc_trim' => true, |
| 68 | + 'phpdoc_types' => true, |
| 69 | + 'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'], |
| 70 | + 'return_type_declaration' => ['space_before' => 'none'], |
| 71 | + 'single_quote' => true, |
| 72 | + 'whitespace_after_comma_in_array' => true |
| 73 | + ]; |
| 74 | + |
| 75 | + public function __construct($name = 'TYPO3') |
| 76 | + { |
| 77 | + parent::__construct($name); |
| 78 | + } |
| 79 | + |
| 80 | + public static function create() |
| 81 | + { |
| 82 | + /** @var self $obj */ |
| 83 | + $obj = parent::create(); |
| 84 | + $obj->setRiskyAllowed(true); |
| 85 | + // Apply our rules |
| 86 | + $obj->setRules(static::$typo3Rules); |
| 87 | + $obj->getFinder()->exclude(['vendor', 'typo3temp', 'var', '.build']); |
| 88 | + return $obj; |
| 89 | + } |
| 90 | + |
| 91 | + public function addRules(array $rules) |
| 92 | + { |
| 93 | + $rules = array_replace_recursive($this->getRules(), $rules); |
| 94 | + $this->setRules($rules); |
| 95 | + } |
| 96 | + |
| 97 | + public function setHeader(string $header = 'This file is part of the TYPO3 CMS project.', $replaceAll = false) |
| 98 | + { |
| 99 | + if (!$replaceAll) { |
| 100 | + $header = str_replace('{header}', $header, static::$defaultHeader); |
| 101 | + } |
| 102 | + $rules = $this->getRules(); |
| 103 | + $rules['header_comment'] = [ |
| 104 | + 'header' => $header, |
| 105 | + 'commentType' => 'comment', |
| 106 | + 'location' => 'after_declare_strict', |
| 107 | + 'separate' => 'both' |
| 108 | + ]; |
| 109 | + return parent::setRules($rules); |
| 110 | + } |
| 111 | +} |
0 commit comments