From 8ec1f43dd3c4e95127a32c7c4ff691c96ec0a580 Mon Sep 17 00:00:00 2001 From: Mathias Brodala Date: Fri, 15 Dec 2023 10:00:38 +0100 Subject: [PATCH 1/6] [TASK] Add friendsofphp/php-cs-fixer and typo3/coding-standards --- composer.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/composer.json b/composer.json index 97f6004..03ea2a9 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,7 @@ "require-dev": { "cakephp/cakephp-codesniffer": "^5.0", "ergebnis/composer-normalize": "^2.3", + "friendsofphp/php-cs-fixer": "^3.41", "helmich/typo3-typoscript-lint": "^3.0", "jangregor/phpstan-prophecy": "^1.0.0", "michielroos/typo3scan": "^1.7", @@ -43,6 +44,7 @@ "slevomat/coding-standard": "^8.0", "squizlabs/php_codesniffer": "^3.1", "typo3/cms-scheduler": "^11.5 || ^12.4", + "typo3/coding-standards": "^0.7.1", "typo3/testing-framework": "^7.0 || ^8.0" }, "replace": { From 7e573d8f49f4a40ce0e61625f4bb5f4049fae533 Mon Sep 17 00:00:00 2001 From: Mathias Brodala Date: Fri, 15 Dec 2023 10:05:09 +0100 Subject: [PATCH 2/6] [TASK] Set up PHP-CS-Fixer config --- .editorconfig | 60 +++++++++++++++++++++++++++++++++--------- .gitattributes | 1 + .gitignore | 1 + .php-cs-fixer.dist.php | 11 ++++++++ 4 files changed, 61 insertions(+), 12 deletions(-) create mode 100644 .php-cs-fixer.dist.php diff --git a/.editorconfig b/.editorconfig index 917a782..0acfb72 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,24 +1,60 @@ -root = true -charset = utf-8 +# EditorConfig is awesome: http://EditorConfig.org -trim_trailing_whitespace = true +# top-most EditorConfig file +root = true +# Unix-style newlines with a newline ending every file [*] +charset = utf-8 end_of_line = lf -insert_final_newline = true - -[composer.json] indent_style = space indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true -[*.less] -indent_style = space +# TS/JS-Files +[*.{ts,js}] indent_size = 2 -[*.php] -indent_style = space +# JSON-Files +[*.json] +indent_style = tab + +# ReST-Files +[*.{rst,rst.txt}] indent_size = 4 +max_line_length = 80 -[*.ts] -indent_style = space +# Markdown-Files +[*.md] +max_line_length = 80 + +# YAML-Files +[*.{yaml,yml}] +indent_size = 2 + +# NEON-Files +[*.neon] +indent_size = 2 +indent_style = tab + +# package.json +[package.json] indent_size = 2 + +# TypoScript +[*.{typoscript,tsconfig}] +indent_size = 2 + +# XLF-Files +[*.xlf] +indent_style = tab + +# SQL-Files +[*.sql] +indent_style = tab +indent_size = 2 + +# .htaccess +[{_.htaccess,.htaccess}] +indent_style = tab diff --git a/.gitattributes b/.gitattributes index 2a4a9ad..8965be8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,6 +3,7 @@ .github export-ignore .gitignore export-ignore .phpunit.result.cache export-ignore +.php-cs-fixer.* export-ignore bower.json export-ignore composer.lock export-ignore docker-compose.yml export-ignore diff --git a/.gitignore b/.gitignore index c908fd7..0456a08 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/.php-cs-fixer.cache /.phpunit.result.cache /bower_components /composer.lock diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..40a0806 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,11 @@ +getFinder() + ->in(__DIR__) + ->exclude([ + 'var', + 'web', + ]); + +return $config; From 373425f3a4e6e518ace2be0fba8f9ca1f94507dc Mon Sep 17 00:00:00 2001 From: Mathias Brodala Date: Fri, 15 Dec 2023 10:05:42 +0100 Subject: [PATCH 3/6] [TASK] Use PHP-CS-Fixer for "*:style" Composer commands --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 03ea2a9..9fea25f 100644 --- a/composer.json +++ b/composer.json @@ -112,7 +112,7 @@ "deploy:ter:upload": [ "composer global exec -v -- tailor ter:publish --comment \"$(git tag -l --format='%(contents)' $TAG)\" $TAG" ], - "fix:style": "phpcbf", + "fix:style": "php-cs-fixer fix --diff", "lint": [ "@lint:php", "@lint:typoscript", @@ -122,7 +122,7 @@ "@lint:xml" ], "lint:php": "parallel-lint --exclude vendor --exclude web .", - "lint:style": "phpcs", + "lint:style": "php-cs-fixer fix --dry-run --diff", "lint:typoscript": "typoscript-lint --ansi", "lint:xml": "xmllint --pattern '*.xlf,*.svg' Resources --ansi", "php:rector:fix": "rector", From 51b60b2cb6919b275d4a44503ffec2b5f46f8160 Mon Sep 17 00:00:00 2001 From: Mathias Brodala Date: Fri, 15 Dec 2023 10:06:55 +0100 Subject: [PATCH 4/6] [TASK] Fix code style violations --- .../Controller/Backend/FormLogController.php | 9 +--- .../Backend/FormLogSuggestController.php | 6 +-- Classes/Domain/Data/JsonData.php | 2 +- .../Domain/Form/Finishers/LoggerFinisher.php | 2 +- Classes/Domain/FormLog/DateRangeFilter.php | 6 +-- Classes/Domain/FormLog/FilterInterface.php | 2 +- Classes/Domain/FormLog/Filters.php | 2 +- Classes/Domain/FormLog/Suggestions.php | 6 +-- Classes/Domain/FormLog/ValueFilter.php | 6 +-- Classes/Domain/Model/FormLogEntry.php | 2 +- Classes/Domain/Model/FormLogEntry/Page.php | 2 +- .../Repository/FormLogEntryRepository.php | 2 +- Classes/Export/AbstractExport.php | 2 +- Classes/Export/CsvExport.php | 2 +- Classes/Export/XlsxExport.php | 2 +- Classes/Form/Element/JSONDataElement.php | 2 +- Classes/Json.php | 6 +-- Classes/Rendering/ValueFormatter.php | 2 +- .../Format/FormValueViewHelper.php | 2 +- Configuration/ContentSecurityPolicies.php | 3 +- Configuration/TCA/tx_formlog_entries.php | 1 + .../Form/Finishers/LoggerFinisherTest.php | 20 ++++----- .../Domain/Form/Finishers/functions.php | 2 +- .../Domain/FormLog/SuggestionsTest.php | 4 +- Tests/Unit/Domain/Data/JsonDataTest.php | 8 ++-- .../Domain/FormLog/DateRangeFilterTest.php | 16 +++---- Tests/Unit/Domain/FormLog/FiltersTest.php | 44 +++++++++---------- Tests/Unit/Domain/FormLog/ValueFilterTest.php | 10 ++--- Tests/Unit/Export/AbstractExportTest.php | 10 ++--- .../Unit/Form/Element/JSONDataElementTest.php | 4 +- Tests/Unit/JsonTest.php | 2 +- Tests/Unit/Rendering/ValueFormatterTest.php | 8 ++-- ext_localconf.php | 1 + ext_tables.php | 1 + 34 files changed, 92 insertions(+), 107 deletions(-) diff --git a/Classes/Controller/Backend/FormLogController.php b/Classes/Controller/Backend/FormLogController.php index 2a235dc..fcc9268 100644 --- a/Classes/Controller/Backend/FormLogController.php +++ b/Classes/Controller/Backend/FormLogController.php @@ -1,6 +1,6 @@ CsvExport::class, 'xlsx' => XlsxExport::class, @@ -36,9 +35,7 @@ class FormLogController extends ActionController protected FormLogEntryRepository $formLogEntryRepository; - public function __construct(protected ModuleTemplateFactory $moduleTemplateFactory) - { - } + public function __construct(protected ModuleTemplateFactory $moduleTemplateFactory) {} public function injectFormLogEntryRepository(FormLogEntryRepository $formLogEntryRepository) { @@ -47,8 +44,6 @@ public function injectFormLogEntryRepository(FormLogEntryRepository $formLogEntr /** * Initialize all actions - * - * @return void */ public function initializeAction() { diff --git a/Classes/Controller/Backend/FormLogSuggestController.php b/Classes/Controller/Backend/FormLogSuggestController.php index 5d175c5..efe3adb 100644 --- a/Classes/Controller/Backend/FormLogSuggestController.php +++ b/Classes/Controller/Backend/FormLogSuggestController.php @@ -1,6 +1,6 @@ select(['*'], 'tx_formlog_entries') ->fetchAssociative(); - $this->assertSame(123, $logEntry['pid'] ?? null); - $this->assertSame($formDefinition->getIdentifier(), $logEntry['identifier'] ?? null); - $this->assertSame($expectedData, $logEntry['data'] ?? null); - $this->assertSame('[]', $logEntry['finisher_variables'] ?? null); + self::assertSame(123, $logEntry['pid'] ?? null); + self::assertSame($formDefinition->getIdentifier(), $logEntry['identifier'] ?? null); + self::assertSame($expectedData, $logEntry['data'] ?? null); + self::assertSame('[]', $logEntry['finisher_variables'] ?? null); } public function formData(): \Generator @@ -234,10 +234,10 @@ public function logsFinisherVariables() ->select(['*'], 'tx_formlog_entries') ->fetchAssociative(); - $this->assertSame(123, $logEntry['pid'] ?? null); - $this->assertSame($formDefinition->getIdentifier(), $logEntry['identifier'] ?? null); - $this->assertSame('{"name":"Tester"}', $logEntry['data'] ?? null); - $this->assertSame('{"SaveToDatabase":{"insertedUids.0":124}}', $logEntry['finisher_variables'] ?? null); + self::assertSame(123, $logEntry['pid'] ?? null); + self::assertSame($formDefinition->getIdentifier(), $logEntry['identifier'] ?? null); + self::assertSame('{"name":"Tester"}', $logEntry['data'] ?? null); + self::assertSame('{"SaveToDatabase":{"insertedUids.0":124}}', $logEntry['finisher_variables'] ?? null); } protected function buildFormDefinition(array $configuration): FormDefinition @@ -292,7 +292,7 @@ protected function submitForm(FormDefinition $formDefinition, array $formValues ->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE) ->withAttribute('extbase', GeneralUtility::makeInstance(ExtbaseRequestParameters::class)) ->withAttribute('currentContentObject', $contentObjectRenderer); - + $request = GeneralUtility::makeInstance(ExtbaseRequest::class, $serverRequest); } diff --git a/Tests/Functional/Domain/Form/Finishers/functions.php b/Tests/Functional/Domain/Form/Finishers/functions.php index ae28196..da97a19 100644 --- a/Tests/Functional/Domain/Form/Finishers/functions.php +++ b/Tests/Functional/Domain/Form/Finishers/functions.php @@ -1,6 +1,6 @@ getForProperty($property); - $this->assertEquals($expected, $result); + self::assertEquals($expected, $result); } public function properties(): \Generator diff --git a/Tests/Unit/Domain/Data/JsonDataTest.php b/Tests/Unit/Domain/Data/JsonDataTest.php index d750af9..9ee5906 100644 --- a/Tests/Unit/Domain/Data/JsonDataTest.php +++ b/Tests/Unit/Domain/Data/JsonDataTest.php @@ -1,6 +1,6 @@ assertEquals('bar', $data['foo']); - $this->assertEquals(10, $data['qux']); + self::assertEquals('bar', $data['foo']); + self::assertEquals(10, $data['qux']); return $data; } @@ -33,6 +33,6 @@ public function formatJsonData(JsonData $data): void { $jsonString = (string)$data; - $this->assertEquals('{"foo":"bar","qux":10}', $jsonString); + self::assertEquals('{"foo":"bar","qux":10}', $jsonString); } } diff --git a/Tests/Unit/Domain/FormLog/DateRangeFilterTest.php b/Tests/Unit/Domain/FormLog/DateRangeFilterTest.php index 5f040df..e47817f 100644 --- a/Tests/Unit/Domain/FormLog/DateRangeFilterTest.php +++ b/Tests/Unit/Domain/FormLog/DateRangeFilterTest.php @@ -1,6 +1,6 @@ assertSame($date1, $dateRangeFilter->getStartDate()); - $this->assertSame($date2, $dateRangeFilter->getEndDate()); + self::assertSame($date1, $dateRangeFilter->getStartDate()); + self::assertSame($date2, $dateRangeFilter->getEndDate()); } /** @@ -47,7 +47,7 @@ public function isEmptyByDefault() { $dateRangeFilter = new DateRangeFilter(); - $this->assertTrue($dateRangeFilter->isEmpty()); + self::assertTrue($dateRangeFilter->isEmpty()); } /** @@ -60,15 +60,15 @@ public function isNotEmptyWithAtLeastOneDate() $dateRangeFilter = new DateRangeFilter($date1); - $this->assertFalse($dateRangeFilter->isEmpty()); + self::assertFalse($dateRangeFilter->isEmpty()); $dateRangeFilter = new DateRangeFilter(null, $date2); - $this->assertFalse($dateRangeFilter->isEmpty()); + self::assertFalse($dateRangeFilter->isEmpty()); $dateRangeFilter = new DateRangeFilter($date1, $date2); - $this->assertFalse($dateRangeFilter->isEmpty()); + self::assertFalse($dateRangeFilter->isEmpty()); } /** @@ -87,6 +87,6 @@ public function canBeConvertedToArray(): void 'endDate' => '2020-09-28T11:30:00+00:00', ]; - $this->assertEquals($expected, $result); + self::assertEquals($expected, $result); } } diff --git a/Tests/Unit/Domain/FormLog/FiltersTest.php b/Tests/Unit/Domain/FormLog/FiltersTest.php index 94eacf5..fb4ed87 100644 --- a/Tests/Unit/Domain/FormLog/FiltersTest.php +++ b/Tests/Unit/Domain/FormLog/FiltersTest.php @@ -1,6 +1,6 @@ prophesize(DateRangeFilter::class)->reveal(); $filters = new Filters($pageTitleFilter, $identifierFilter, $submissionDateFilter); - $this->assertSame($pageTitleFilter, $filters->getPageTitle()); - $this->assertSame($identifierFilter, $filters->getIdentifier()); - $this->assertSame($submissionDateFilter, $filters->getSubmissionDate()); + self::assertSame($pageTitleFilter, $filters->getPageTitle()); + self::assertSame($identifierFilter, $filters->getIdentifier()); + self::assertSame($submissionDateFilter, $filters->getSubmissionDate()); } /** @@ -54,8 +54,8 @@ public function constructsWithFilterDefaults() { $filters = new Filters(); - $this->assertInstanceOf(ValueFilter::class, $filters->getPageTitle()); - $this->assertInstanceOf(DateRangeFilter::class, $filters->getSubmissionDate()); + self::assertInstanceOf(ValueFilter::class, $filters->getPageTitle()); + self::assertInstanceOf(DateRangeFilter::class, $filters->getSubmissionDate()); } /** @@ -65,7 +65,7 @@ public function isEmptyByDefault() { $filters = new Filters(); - $this->assertTrue($filters->isEmpty()); + self::assertTrue($filters->isEmpty()); } /** @@ -80,15 +80,15 @@ public function isNotEmptyWithAtLeastOneNonEmptyFilter() $filters = new Filters($pageTitleFilter->reveal()); - $this->assertFalse($filters->isEmpty()); + self::assertFalse($filters->isEmpty()); $filters = new Filters(null, null, $submissionDateFilter->reveal()); - $this->assertFalse($filters->isEmpty()); + self::assertFalse($filters->isEmpty()); $filters = new Filters($pageTitleFilter->reveal(), null, $submissionDateFilter->reveal()); - $this->assertFalse($filters->isEmpty()); + self::assertFalse($filters->isEmpty()); } /** @@ -99,7 +99,7 @@ public function yieldsNothingOnTraversalByDefault() $filters = new Filters(); $items = iterator_to_array($filters); - $this->assertEmpty($items); + self::assertEmpty($items); } /** @@ -117,19 +117,19 @@ public function yieldsNonEmptyFiltersOnTraversal() $filters = new Filters($pageTitleFilter->reveal()); $items = iterator_to_array($filters); - $this->assertCount(1, $items); - $this->assertContainsOnlyInstancesOf(ValueFilter::class, $items); + self::assertCount(1, $items); + self::assertContainsOnlyInstancesOf(ValueFilter::class, $items); $filters = new Filters(null, null, $submissionDateFilter->reveal()); $items = iterator_to_array($filters); - $this->assertCount(1, $items); - $this->assertContainsOnlyInstancesOf(DateRangeFilter::class, $items); + self::assertCount(1, $items); + self::assertContainsOnlyInstancesOf(DateRangeFilter::class, $items); $filters = new Filters($pageTitleFilter->reveal(), $identifierFilter->reveal(), $submissionDateFilter->reveal()); $items = iterator_to_array($filters); - $this->assertCount(2, $items); + self::assertCount(2, $items); } /** @@ -152,11 +152,11 @@ public function canBeConvertedToArray(): void $result = $filters->toArray(); - $this->assertArrayHasKey('pageTitle', $result); - $this->assertIsArray($result['pageTitle']); - $this->assertArrayHasKey('identifier', $result); - $this->assertIsArray($result['identifier']); - $this->assertArrayHasKey('submissionDate', $result); - $this->assertIsArray($result['submissionDate']); + self::assertArrayHasKey('pageTitle', $result); + self::assertIsArray($result['pageTitle']); + self::assertArrayHasKey('identifier', $result); + self::assertIsArray($result['identifier']); + self::assertArrayHasKey('submissionDate', $result); + self::assertIsArray($result['submissionDate']); } } diff --git a/Tests/Unit/Domain/FormLog/ValueFilterTest.php b/Tests/Unit/Domain/FormLog/ValueFilterTest.php index 39aac65..bca6a28 100644 --- a/Tests/Unit/Domain/FormLog/ValueFilterTest.php +++ b/Tests/Unit/Domain/FormLog/ValueFilterTest.php @@ -1,6 +1,6 @@ assertEquals('foo', $valueFilter->getValue()); + self::assertEquals('foo', $valueFilter->getValue()); } /** @@ -44,7 +44,7 @@ public function isEmptyByDefault() { $valueFilter = new ValueFilter(); - $this->assertTrue($valueFilter->isEmpty()); + self::assertTrue($valueFilter->isEmpty()); } /** @@ -54,7 +54,7 @@ public function isNotEmptyWithValue() { $valueFilter = new ValueFilter('foo'); - $this->assertFalse($valueFilter->isEmpty()); + self::assertFalse($valueFilter->isEmpty()); } /** @@ -69,6 +69,6 @@ public function canBeConvertedToArray(): void 'value' => 'foo', ]; - $this->assertEquals($expected, $result); + self::assertEquals($expected, $result); } } diff --git a/Tests/Unit/Export/AbstractExportTest.php b/Tests/Unit/Export/AbstractExportTest.php index 283ed60..8b2f493 100644 --- a/Tests/Unit/Export/AbstractExportTest.php +++ b/Tests/Unit/Export/AbstractExportTest.php @@ -1,6 +1,6 @@ getColumnPaths(); } - public function dump(iterable $items): void - { - } + public function dump(iterable $items): void {} }; $configuration = [ @@ -54,6 +52,6 @@ public function dump(iterable $items): void 'custom', ]; - $this->assertEquals($expected, $result); + self::assertEquals($expected, $result); } } diff --git a/Tests/Unit/Form/Element/JSONDataElementTest.php b/Tests/Unit/Form/Element/JSONDataElementTest.php index 7daa910..862e65b 100644 --- a/Tests/Unit/Form/Element/JSONDataElementTest.php +++ b/Tests/Unit/Form/Element/JSONDataElementTest.php @@ -1,6 +1,6 @@ render(); - $this->assertEquals($expected, $result['html']); + self::assertEquals($expected, $result['html']); } public function samples() diff --git a/Tests/Unit/JsonTest.php b/Tests/Unit/JsonTest.php index b5cdec2..32109f8 100644 --- a/Tests/Unit/JsonTest.php +++ b/Tests/Unit/JsonTest.php @@ -1,6 +1,6 @@ valueFormatter->format($value); - $this->assertEquals($expected, $result); + self::assertEquals($expected, $result); } public function formValues(): \Generator @@ -167,7 +167,7 @@ public function rendersDateWithCustomFormat(): void ->setDateTimeFormat('d.m.Y') ->format($date); - $this->assertEquals('08.01.2021', $result); + self::assertEquals('08.01.2021', $result); } /** @@ -177,6 +177,6 @@ public function throwsExceptionOnUnsupportedValues(): void { $this->expectException(\UnexpectedValueException::class); - $this->valueFormatter->format(new \stdClass); + $this->valueFormatter->format(new \stdClass()); } } diff --git a/ext_localconf.php b/ext_localconf.php index 72f8e90..45a0364 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -1,4 +1,5 @@ Date: Fri, 15 Dec 2023 10:07:34 +0100 Subject: [PATCH 5/6] [TASK] Remove squizlabs/php_codesniffer and related packages --- composer.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/composer.json b/composer.json index 9fea25f..1af5e69 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,6 @@ "typo3fluid/fluid": "^2.3" }, "require-dev": { - "cakephp/cakephp-codesniffer": "^5.0", "ergebnis/composer-normalize": "^2.3", "friendsofphp/php-cs-fixer": "^3.41", "helmich/typo3-typoscript-lint": "^3.0", @@ -41,8 +40,6 @@ "rector/rector": "^0.18.5", "saschaegerer/phpstan-typo3": "^1.0.0", "sclable/xml-lint": "^0.6.0", - "slevomat/coding-standard": "^8.0", - "squizlabs/php_codesniffer": "^3.1", "typo3/cms-scheduler": "^11.5 || ^12.4", "typo3/coding-standards": "^0.7.1", "typo3/testing-framework": "^7.0 || ^8.0" From 2e210f9a032d0fe971ab91cfea228ae5c8846865 Mon Sep 17 00:00:00 2001 From: Mathias Brodala Date: Fri, 15 Dec 2023 10:08:13 +0100 Subject: [PATCH 6/6] [TASK] Drop PHPCS config --- .gitattributes | 1 - phpcs.xml | 59 -------------------------------------------------- 2 files changed, 60 deletions(-) delete mode 100644 phpcs.xml diff --git a/.gitattributes b/.gitattributes index 8965be8..b50c3c8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10,7 +10,6 @@ docker-compose.yml export-ignore Gruntfile.js export-ignore package.json export-ignore package-lock.json export-ignore -phpcs.xml export-ignore phpstan*.neon export-ignore phpunit-functional.xml export-ignore phpunit.xml export-ignore diff --git a/phpcs.xml b/phpcs.xml deleted file mode 100644 index 6b3324e..0000000 --- a/phpcs.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - Classes - Configuration/TCA - Tests - ext_emconf.php - ext_localconf.php - ext_tables.php - - - - - - - Tests/Functional/Domain/Form/Finishers/functions.php - - - - Classes/Hooks/DataHandlerHook.php - - - - - - - - - - - - - - - - - - - - - - - - - - Configuration/TCA/*.php - ext_*.php - - - - - -