Skip to content

Commit 2ca5b83

Browse files
committed
[TASK] Added code quality checks
Signed-off-by: Torben Hansen <derhansen@gmail.com>
1 parent 8992c82 commit 2ca5b83

10 files changed

Lines changed: 187 additions & 77 deletions

File tree

.Build/composer.json

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
{
2-
"name": "derhansen/form_crshield_build",
3-
"description": "composer.json for builds",
4-
"repositories": [
5-
{
6-
"type": "path",
7-
"url": "../"
8-
}
9-
],
10-
"require": {
11-
"derhansen/form_crshield": "@dev",
12-
"typo3/cms-core": "^14.3",
13-
"typo3/cms-extbase": "^14.3",
14-
"typo3/cms-form": "^14.3",
15-
"typo3/cms-frontend": "^14.3"
16-
},
17-
"require-dev": {
18-
"typo3/cms-backend": " ^14.3",
19-
"typo3/cms-fluid-styled-content": "^14.3",
20-
"typo3/cms-tstemplate": "^14.3",
21-
"typo3/cms-install": "^14.3",
22-
"typo3/cms-extensionmanager": "^14.3",
23-
"codeception/codeception": "^5.0",
24-
"codeception/module-webdriver": "^3.2.0",
25-
"codeception/module-db": "^3.0.1",
26-
"codeception/module-phpbrowser": "^3.0.0",
27-
"codeception/module-asserts": "^3.0.0"
28-
},
29-
"config": {
30-
"lock": false,
31-
"allow-plugins": {
32-
"typo3/class-alias-loader": true,
33-
"typo3/cms-composer-installers": true
34-
}
35-
}
2+
"name": "derhansen/form_crshield_build",
3+
"description": "composer.json for builds",
4+
"repositories": [
5+
{
6+
"type": "path",
7+
"url": "../"
8+
}
9+
],
10+
"require": {
11+
"derhansen/form_crshield": "@dev",
12+
"typo3/cms-core": "^14.3",
13+
"typo3/cms-extbase": "^14.3",
14+
"typo3/cms-form": "^14.3",
15+
"typo3/cms-frontend": "^14.3"
16+
},
17+
"require-dev": {
18+
"typo3/cms-backend": " ^14.3",
19+
"typo3/cms-fluid-styled-content": "^14.3",
20+
"typo3/cms-tstemplate": "^14.3",
21+
"typo3/cms-install": "^14.3",
22+
"typo3/cms-extensionmanager": "^14.3",
23+
"friendsofphp/php-cs-fixer": "^3.12.0",
24+
"codeception/codeception": "^5.0",
25+
"codeception/module-webdriver": "^3.2.0",
26+
"codeception/module-db": "^3.0.1",
27+
"codeception/module-phpbrowser": "^3.0.0",
28+
"codeception/module-asserts": "^3.0.0"
29+
},
30+
"config": {
31+
"lock": false,
32+
"allow-plugins": {
33+
"typo3/class-alias-loader": true,
34+
"typo3/cms-composer-installers": true
35+
}
36+
}
3637
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
$header = <<<'EOF'
4+
5+
This file is part of the TYPO3 extension form_crshield.
6+
7+
(c) Torben Hansen <derhansen@gmail.com>
8+
9+
For the full copyright and license information, please view the LICENSE
10+
file that was distributed with this source code.
11+
EOF;
12+
13+
return (new \PhpCsFixer\Config())
14+
->setRiskyAllowed(true)
15+
->setRules([
16+
'@DoctrineAnnotation' => true,
17+
// @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
18+
'@PER-CS1.0' => true,
19+
'array_indentation' => true,
20+
'array_syntax' => ['syntax' => 'short'],
21+
'cast_spaces' => ['space' => 'none'],
22+
// @todo: Can be dropped once we enable @PER-CS2.0
23+
'concat_space' => ['spacing' => 'one'],
24+
'declare_equal_normalize' => ['space' => 'none'],
25+
'declare_parentheses' => true,
26+
'dir_constant' => true,
27+
// @todo: Can be dropped once we enable @PER-CS2.0
28+
'function_declaration' => [
29+
'closure_fn_spacing' => 'none',
30+
],
31+
'function_to_constant' => ['functions' => ['get_called_class', 'get_class', 'get_class_this', 'php_sapi_name', 'phpversion', 'pi']],
32+
'type_declaration_spaces' => true,
33+
'global_namespace_import' => ['import_classes' => false, 'import_constants' => false, 'import_functions' => false],
34+
'list_syntax' => ['syntax' => 'short'],
35+
// @todo: Can be dropped once we enable @PER-CS2.0
36+
'method_argument_space' => true,
37+
'modernize_strpos' => true,
38+
'modernize_types_casting' => true,
39+
'native_function_casing' => true,
40+
'no_alias_functions' => true,
41+
'no_blank_lines_after_phpdoc' => true,
42+
'no_empty_phpdoc' => true,
43+
'no_empty_statement' => true,
44+
'no_extra_blank_lines' => true,
45+
'no_leading_namespace_whitespace' => true,
46+
'no_null_property_initialization' => true,
47+
'no_short_bool_cast' => true,
48+
'no_singleline_whitespace_before_semicolons' => true,
49+
'no_superfluous_elseif' => true,
50+
'no_trailing_comma_in_singleline' => true,
51+
'no_unneeded_control_parentheses' => true,
52+
'no_unused_imports' => true,
53+
'no_useless_else' => true,
54+
'no_useless_nullsafe_operator' => true,
55+
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
56+
'php_unit_construct' => ['assertions' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame']],
57+
'php_unit_mock_short_will_return' => true,
58+
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
59+
'phpdoc_no_access' => true,
60+
'phpdoc_no_empty_return' => true,
61+
'phpdoc_no_package' => true,
62+
'phpdoc_scalar' => true,
63+
'phpdoc_trim' => true,
64+
'phpdoc_types' => true,
65+
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
66+
'return_type_declaration' => ['space_before' => 'none'],
67+
'single_quote' => true,
68+
'single_space_around_construct' => true,
69+
'single_line_comment_style' => ['comment_types' => ['hash']],
70+
// @todo: Can be dropped once we enable @PER-CS2.0
71+
'single_line_empty_body' => true,
72+
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
73+
'whitespace_after_comma_in_array' => ['ensure_single_space' => true],
74+
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
75+
])
76+
->setFinder(
77+
PhpCsFixer\Finder::create()
78+
->in(dirname(__DIR__ . '/../../../'))
79+
->exclude(['.Build', 'Documentation', 'Resources'])
80+
->notName('ext_emconf.php')
81+
);

.github/workflows/CodeQuality.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Code Quality Checks
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
strategy:
11+
matrix:
12+
env:
13+
- { php: 8.2}
14+
- { php: 8.3}
15+
- { php: 8.4}
16+
17+
env: ${{ matrix.env }}
18+
19+
steps:
20+
- uses: actions/checkout@v3
21+
22+
- name: Set up PHP Version
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: ${{ matrix.env.php }}
26+
tools: composer:v2
27+
28+
- name: Validate composer.json and composer.lock
29+
run: composer validate
30+
31+
- name: Cache dependencies
32+
uses: actions/cache@v3
33+
with:
34+
path: ~/.composer/cache
35+
key: dependencies-composer-${{ hashFiles('composer.json') }}
36+
37+
- name: Install composer dependencies
38+
run: |
39+
cd .Build
40+
composer install --no-progress
41+
42+
- name: Validate PHP coding guidelines
43+
run: |
44+
.Build/vendor/bin/php-cs-fixer fix --config=.Build/php-cs-fixer/.php-cs-fixer.php -v --dry-run --stop-on-violation --using-cache=no

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
.idea
2+
.php-cs-fixer.cache
23
composer.lock
34
config
45
var
56
.Build/public
67
.Build/vendor
7-
.Build/composer.lock
8+
.Build/composer.lock

Classes/EventListener/FormCrShield.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected function getPageExpirationTime(FormRuntime $runtime): int
111111
}
112112

113113
/**
114-
* Get the cache timeout for the current page (taken 1:1 from TypoScriptFrontendController)
114+
* Get the cache timeout for the current page
115115
*/
116116
protected function getCacheTimeout(ServerRequestInterface $request): int
117117
{

Classes/Service/ChallengeResponseService.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ public function __construct(
1414
protected readonly LoggerInterface $logger,
1515
protected readonly HashService $hashService,
1616
protected readonly Context $context
17-
) {
18-
}
17+
) {}
1918

2019
public function getChallenge(string $method, int $expirationTime, int $delay, string $salt): string
2120
{
@@ -29,7 +28,7 @@ public function getChallenge(string $method, int $expirationTime, int $delay, st
2928
'expirationTime' => $expirationTime,
3029
'delay' => $delay,
3130
'salt' => $salt,
32-
'challenge' => $challenge
31+
'challenge' => $challenge,
3332
]
3433
);
3534

@@ -85,15 +84,9 @@ public function isValidResponse(string $submittedResponse, string $salt): bool
8584

8685
private function getCalculatedData(string $knownHmac, string $method): string
8786
{
88-
switch ($method) {
89-
case '2':
90-
$result = strrev($knownHmac);
91-
break;
92-
case '1':
93-
default:
94-
$result = str_rot13($knownHmac);
95-
}
96-
97-
return $result;
87+
return match ($method) {
88+
'2' => strrev($knownHmac),
89+
default => str_rot13($knownHmac),
90+
};
9891
}
99-
}
92+
}

Tests/Acceptance/WithChromeBrowser/FormCrshieldCest.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@
22

33
namespace Tests\Acceptance;
44

5-
use AcceptanceTester;
6-
75
/**
86
* Test suite executed in chrome webbrowser with JavaScript enabled. All form tests respect the default
97
* delay of 3 seconds.
108
*/
119
class FormCrshieldCest
1210
{
13-
public function rootPageIsShown(AcceptanceTester $I): void
11+
public function rootPageIsShown(\AcceptanceTester $I): void
1412
{
1513
$I->amOnPage('/');
1614
$I->see('Root Page');
1715
}
1816

19-
public function simpleFormCanNotBeSubmittedIfDefaultDelayNotPassed(AcceptanceTester $I): void
17+
public function simpleFormCanNotBeSubmittedIfDefaultDelayNotPassed(\AcceptanceTester $I): void
2018
{
2119
$I->amOnPage('simple-form');
2220
$I->see('Step');
@@ -26,7 +24,7 @@ public function simpleFormCanNotBeSubmittedIfDefaultDelayNotPassed(AcceptanceTes
2624
$I->dontSee('SUCCESS');
2725
}
2826

29-
public function simpleFormCanBeSubmitted(AcceptanceTester $I): void
27+
public function simpleFormCanBeSubmitted(\AcceptanceTester $I): void
3028
{
3129
$I->amOnPage('simple-form');
3230
$I->wait(4);
@@ -37,7 +35,7 @@ public function simpleFormCanBeSubmitted(AcceptanceTester $I): void
3735
$I->waitForText('SUCCESS', 5);
3836
}
3937

40-
public function simpleFormWithSummaryCanBeSubmitted(AcceptanceTester $I): void
38+
public function simpleFormWithSummaryCanBeSubmitted(\AcceptanceTester $I): void
4139
{
4240
$I->amOnPage('simple-form-with-summary');
4341
$I->wait(4);
@@ -50,7 +48,7 @@ public function simpleFormWithSummaryCanBeSubmitted(AcceptanceTester $I): void
5048
$I->waitForText('SUCCESS', 5);
5149
}
5250

53-
public function multipleStepFormCanBeSubmitted(AcceptanceTester $I): void
51+
public function multipleStepFormCanBeSubmitted(\AcceptanceTester $I): void
5452
{
5553
$I->amOnPage('multiple-step-form');
5654
$I->wait(4);
@@ -62,7 +60,7 @@ public function multipleStepFormCanBeSubmitted(AcceptanceTester $I): void
6260
$I->waitForText('SUCCESS', 5);
6361
}
6462

65-
public function multipleStepFormWithSummaryCanBeSubmitted(AcceptanceTester $I): void
63+
public function multipleStepFormWithSummaryCanBeSubmitted(\AcceptanceTester $I): void
6664
{
6765
$I->amOnPage('multiple-step-form-with-summary');
6866
$I->wait(4);
@@ -77,7 +75,7 @@ public function multipleStepFormWithSummaryCanBeSubmitted(AcceptanceTester $I):
7775
$I->waitForText('SUCCESS', 5);
7876
}
7977

80-
public function serverSideValidationCanBeSubmittedWithValidValues(AcceptanceTester $I): void
78+
public function serverSideValidationCanBeSubmittedWithValidValues(\AcceptanceTester $I): void
8179
{
8280
$I->amOnPage('server-side-validation');
8381
$I->wait(4);
@@ -89,7 +87,7 @@ public function serverSideValidationCanBeSubmittedWithValidValues(AcceptanceTest
8987
$I->waitForText('SUCCESS', 5);
9088
}
9189

92-
public function serverSideValidationSubmitWithEmptyValuesThenResubmit(AcceptanceTester $I): void
90+
public function serverSideValidationSubmitWithEmptyValuesThenResubmit(\AcceptanceTester $I): void
9391
{
9492
$I->amOnPage('server-side-validation');
9593
$I->wait(4);

Tests/Acceptance/WithChromeBrowser/_support/Helper/Acceptance.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,4 @@
55
// here you can define custom actions
66
// all public methods declared in helper class will be available in $I
77

8-
class Acceptance extends \Codeception\Module
9-
{
10-
11-
}
8+
class Acceptance extends \Codeception\Module {}

0 commit comments

Comments
 (0)