Skip to content

Commit ed8a2ee

Browse files
committed
Add php-cs-fixer and run config
1 parent cf2828d commit ed8a2ee

12 files changed

Lines changed: 214 additions & 39 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ var/
88
public/
99
vendor/
1010
composer.lock
11+
.php-cs-fixer.cache

Build/Scripts/runTests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ case ${TEST_SUITE} in
826826
if [ -n "${CGLCHECK_DRY_RUN}" ]; then
827827
CGLCHECK_DRY_RUN="--dry-run --diff"
828828
fi
829-
COMMAND="php -dxdebug.mode=off bin/php-cs-fixer fix -v ${CGLCHECK_DRY_RUN} --path-mode intersection --config=Build/php-cs-fixer/config.php typo3/"
829+
COMMAND="php -dxdebug.mode=off bin/php-cs-fixer fix -v ${CGLCHECK_DRY_RUN} --path-mode intersection --config=Build/php-cs-fixer/config.php ."
830830
${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name cgl-${SUFFIX} ${IMAGE_PHP} ${COMMAND}
831831
SUITE_EXIT_CODE=$?
832832
;;
@@ -839,7 +839,7 @@ case ${TEST_SUITE} in
839839
if [ -n "${CGLCHECK_DRY_RUN}" ]; then
840840
CGLCHECK_DRY_RUN="--dry-run --diff"
841841
fi
842-
COMMAND="php -dxdebug.mode=off bin/php-cs-fixer fix -v ${CGLCHECK_DRY_RUN} --path-mode intersection --config=Build/php-cs-fixer/header-comment.php typo3/"
842+
COMMAND="php -dxdebug.mode=off bin/php-cs-fixer fix -v ${CGLCHECK_DRY_RUN} --path-mode intersection --config=Build/php-cs-fixer/header-comment.php ."
843843
${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name cgl-header-${SUFFIX} ${IMAGE_PHP} ${COMMAND}
844844
SUITE_EXIT_CODE=$?
845845
;;

Build/php-cs-fixer/config.php

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is copied from the TYPO3 CMS project.
7+
*
8+
* It is free software; you can redistribute it and/or modify it under
9+
* the terms of the GNU General Public License, either version 2
10+
* of the License, or any later version.
11+
*
12+
* For the full copyright and license information, please read the
13+
* LICENSE.txt file that was distributed with this source code.
14+
*
15+
* The TYPO3 project - inspiring people to share!
16+
*/
17+
18+
/**
19+
* This file represents the configuration for Code Sniffing PER-related
20+
* automatic checks of coding guidelines.
21+
*
22+
* Run it using runTests.sh, see 'runTests.sh -h' for more options.
23+
*
24+
* Fix entire extension:
25+
* > Build/Scripts/additionalTests.sh -p 8.3 -s composerInstallPackage -q "typo3/cms-core:[dev-main,13...]"
26+
* > Build/Scripts/runTests.sh -s cgl
27+
*
28+
* Fix your current patch:
29+
* > Build/Scripts/runTests.sh -s cglGit
30+
*/
31+
if (PHP_SAPI !== 'cli') {
32+
die('This script supports command line usage only. Please check your command.');
33+
}
34+
35+
// Return a Code Sniffing configuration using
36+
// all sniffers needed for PER
37+
// and additionally:
38+
// - Remove leading slashes in use clauses.
39+
// - PHP single-line arrays should not have trailing comma.
40+
// - Single-line whitespace before closing semicolon are prohibited.
41+
// - Remove unused use statements in the PHP source code
42+
// - Ensure Concatenation to have at least one whitespace around
43+
// - Remove trailing whitespace at the end of blank lines.
44+
return (new \PhpCsFixer\Config())
45+
->setParallelConfig(\PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
46+
->setFinder(
47+
PhpCsFixer\Finder::create()
48+
->ignoreVCSIgnored(true)
49+
->in(realpath(__DIR__ . '/../../'))
50+
->exclude('bin')
51+
->exclude('public')
52+
->exclude('typo3temp')
53+
->exclude('vendor')
54+
)
55+
->setRiskyAllowed(true)
56+
->setRules([
57+
'@DoctrineAnnotation' => true,
58+
// @todo: Switch to @PER-CS2.0 once php-cs-fixer's todo list is done: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7247
59+
'@PER-CS1.0' => true,
60+
'array_indentation' => true,
61+
'array_syntax' => ['syntax' => 'short'],
62+
'cast_spaces' => ['space' => 'none'],
63+
// @todo: Can be dropped once we enable @PER-CS2.0
64+
'concat_space' => ['spacing' => 'one'],
65+
'declare_equal_normalize' => ['space' => 'none'],
66+
'declare_parentheses' => true,
67+
'dir_constant' => true,
68+
// @todo: Can be dropped once we enable @PER-CS2.0
69+
'function_declaration' => [
70+
'closure_fn_spacing' => 'none',
71+
],
72+
'function_to_constant' => ['functions' => ['get_called_class', 'get_class', 'get_class_this', 'php_sapi_name', 'phpversion', 'pi']],
73+
'type_declaration_spaces' => true,
74+
'global_namespace_import' => ['import_classes' => false, 'import_constants' => false, 'import_functions' => false],
75+
'list_syntax' => ['syntax' => 'short'],
76+
// @todo: Can be dropped once we enable @PER-CS2.0
77+
'method_argument_space' => true,
78+
'modernize_strpos' => true,
79+
'modernize_types_casting' => true,
80+
'native_function_casing' => true,
81+
'no_alias_functions' => true,
82+
'no_blank_lines_after_phpdoc' => true,
83+
'no_empty_phpdoc' => true,
84+
'no_empty_statement' => true,
85+
'no_extra_blank_lines' => true,
86+
'no_leading_namespace_whitespace' => true,
87+
'no_null_property_initialization' => true,
88+
'no_short_bool_cast' => true,
89+
'no_singleline_whitespace_before_semicolons' => true,
90+
'no_superfluous_elseif' => true,
91+
'no_trailing_comma_in_singleline' => true,
92+
'no_unneeded_control_parentheses' => true,
93+
'no_unused_imports' => true,
94+
'no_useless_else' => true,
95+
'no_useless_nullsafe_operator' => true,
96+
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
97+
'php_unit_construct' => ['assertions' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame']],
98+
'php_unit_mock_short_will_return' => true,
99+
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
100+
'phpdoc_no_access' => true,
101+
'phpdoc_no_empty_return' => true,
102+
'phpdoc_no_package' => true,
103+
'phpdoc_scalar' => true,
104+
'phpdoc_trim' => true,
105+
'phpdoc_types' => true,
106+
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
107+
'return_type_declaration' => ['space_before' => 'none'],
108+
'single_quote' => true,
109+
'single_space_around_construct' => true,
110+
'single_line_comment_style' => ['comment_types' => ['hash']],
111+
// @todo: Can be dropped once we enable @PER-CS2.0
112+
'single_line_empty_body' => true,
113+
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
114+
'whitespace_after_comma_in_array' => ['ensure_single_space' => true],
115+
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
116+
]);
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is developed by evoWeb.
7+
*
8+
* It is free software; you can redistribute it and/or modify it under
9+
* the terms of the GNU General Public License, either version 2
10+
* of the License, or any later version.
11+
*
12+
* For the full copyright and license information, please read the
13+
* LICENSE.txt file that was distributed with this source code.
14+
*/
15+
16+
/**
17+
* This file adds header to php file which don't have any.
18+
*
19+
* Run it using runTests.sh, see 'runTests.sh -h' for more options.
20+
*
21+
* Fix entire extension:
22+
* > Build/Scripts/additionalTests.sh -p 8.3 -s composerInstallPackage -q "typo3/cms-core:[dev-main,13...]"
23+
* > Build/Scripts/runTests.sh -s cglHeader
24+
*
25+
* Fix your current patch:
26+
* > Build/Scripts/runTests.sh -s cglHeaderGit
27+
*/
28+
if (PHP_SAPI !== 'cli') {
29+
die('This script supports command line usage only. Please check your command.');
30+
}
31+
32+
$finder = PhpCsFixer\Finder::create()
33+
->name('*.php')
34+
->in(__DIR__ . '/../../')
35+
->exclude('Acceptance/Support/_generated') // EXT:core
36+
->exclude('Build')
37+
// Configuration files do not need header comments
38+
->exclude('Configuration')
39+
->notName('*locallang*.php')
40+
->notName('ext_localconf.php')
41+
->notName('ext_tables.php')
42+
->notName('ext_emconf.php')
43+
// ClassAliasMap files do not need header comments
44+
->notName('ClassAliasMap.php')
45+
// CodeSnippets and Examples in Documentation do not need header comments
46+
->exclude('Documentation')
47+
// Third-party inclusion files should not have a changed comment
48+
->notName('Rfc822AddressesParser.php')
49+
->notName('ClassMapGenerator.php')
50+
;
51+
52+
$headerComment = <<<COMMENT
53+
This file is developed by evoWeb.
54+
55+
It is free software; you can redistribute it and/or modify it under
56+
the terms of the GNU General Public License, either version 2
57+
of the License, or any later version.
58+
59+
For the full copyright and license information, please read the
60+
LICENSE.txt file that was distributed with this source code.
61+
COMMENT;
62+
63+
return (new \PhpCsFixer\Config())
64+
->setParallelConfig(\PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
65+
->setRiskyAllowed(false)
66+
->setRules([
67+
'no_extra_blank_lines' => true,
68+
'header_comment' => [
69+
'header' => $headerComment,
70+
'comment_type' => 'comment',
71+
'separate' => 'both',
72+
'location' => 'after_declare_strict',
73+
],
74+
])
75+
->setFinder($finder);

Classes/Controller/FileController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ public function __construct(
3939
protected ModuleTemplateFactory $moduleTemplateFactory,
4040
protected Converter $fileConverter,
4141
protected ExtensionService $extensionService,
42-
) {
43-
}
42+
) {}
4443

4544
public function selectExtensionAction(ServerRequestInterface $request): ResponseInterface
4645
{
@@ -199,7 +198,6 @@ protected function initializeModuleTemplate(ServerRequestInterface $request): Mo
199198
} catch (\Exception) {
200199
}
201200

202-
203201
return $moduleTemplate;
204202
}
205203

Classes/File/Converter.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,14 @@
33
declare(strict_types=1);
44

55
/*
6-
* Copyright notice
6+
* This file is developed by evoWeb.
77
*
8-
* (c) 2011 Xavier Perseguers <xavier@typo3.org>
9-
* All rights reserved
8+
* It is free software; you can redistribute it and/or modify it under
9+
* the terms of the GNU General Public License, either version 2
10+
* of the License, or any later version.
1011
*
11-
* This script is part of the TYPO3 project. The TYPO3 project is
12-
* free software; you can redistribute it and/or modify
13-
* it under the terms of the GNU General Public License as published by
14-
* the Free Software Foundation; either version 2 of the License, or
15-
* (at your option) any later version.
16-
*
17-
* The GNU General Public License can be found at
18-
* http://www.gnu.org/copyleft/gpl.html.
19-
*
20-
* This script is distributed in the hope that it will be useful,
21-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
22-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23-
* GNU General Public License for more details.
24-
*
25-
* This copyright notice MUST APPEAR in all copies of the script!
12+
* For the full copyright and license information, please read the
13+
* LICENSE.txt file that was distributed with this source code.
2614
*/
2715

2816
namespace Evoweb\EwLlxml2xliff\File;

Classes/Localization/Parser/LocallangXmlParser.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
declare(strict_types=1);
44

55
/*
6-
* This file is part of the TYPO3 CMS project.
6+
* This file is developed by evoWeb.
77
*
88
* It is free software; you can redistribute it and/or modify it under
99
* the terms of the GNU General Public License, either version 2
1010
* of the License, or any later version.
1111
*
1212
* For the full copyright and license information, please read the
1313
* LICENSE.txt file that was distributed with this source code.
14-
*
15-
* The TYPO3 project - inspiring people to share!
1614
*/
1715

1816
namespace Evoweb\EwLlxml2xliff\Localization\Parser;
@@ -90,7 +88,7 @@ protected function getParsedDataForElement(\SimpleXMLElement $bodyOfFileTag, str
9088
foreach ($children as $translationElement) {
9189
if ($translationElement->getName() === 'label') {
9290
$parsedData[(string)$translationElement['index']][0] = [
93-
$element => (string)$translationElement
91+
$element => (string)$translationElement,
9492
];
9593
}
9694
}

Classes/Service/ExtensionService.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
public function __construct(
2626
protected ListUtility $listUtility,
2727
protected Converter $converter,
28-
) {
29-
}
28+
) {}
3029

3130
public function getLocalExtensions(): array
3231
{
@@ -68,7 +67,7 @@ public function getFilesOfExtension(string $extensionKey): array
6867
if ($this->isLanguageFile($file) && !$this->xliffFileAlreadyExists($extensionPath, $file)) {
6968
$filename = GeneralUtility::removePrefixPathFromList([$file], $extensionPath)[0];
7069
$result[$filename] = [
71-
'filename' => $filename
70+
'filename' => $filename,
7271
];
7372
}
7473
}
@@ -110,7 +109,7 @@ public function convertLanguageFile(string $selectedExtension, string $selectedF
110109
'wasConvertedPreviously' => $wasConvertedPreviously,
111110
'fileConvertedSuccessfully' => $fileConvertedSuccessfully,
112111
'messages' => $messages,
113-
'files' => $files
112+
'files' => $files,
114113
];
115114
}
116115

Configuration/Backend/Modules.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
],
2323
'convertFile' => [
2424
'target' => FileController::class . '::convertFileAction',
25-
]
25+
],
2626
],
2727
],
2828
];

Configuration/Icons.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
return [
66
'llxml2xlifficon' => [
77
'provider' => SvgIconProvider::class,
8-
'source' => 'EXT:ew_llxml2xliff/Resources/Public/Icons/Extension.svg'
8+
'source' => 'EXT:ew_llxml2xliff/Resources/Public/Icons/Extension.svg',
99
],
1010
'llxml2xliff-convert' => [
1111
'provider' => SvgIconProvider::class,
1212
'source' =>
13-
'EXT:ew_llxml2xliff/Resources/Public/Icons/transition_conversion_convert_transfer_motion_icon_196300.svg'
13+
'EXT:ew_llxml2xliff/Resources/Public/Icons/transition_conversion_convert_transfer_motion_icon_196300.svg',
1414
],
1515
];

0 commit comments

Comments
 (0)