Skip to content

Commit

Permalink
Update cs fixer (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszuznanski committed Jul 20, 2023
1 parent 4ddf88a commit a565d74
Show file tree
Hide file tree
Showing 32 changed files with 159 additions and 217 deletions.
99 changes: 20 additions & 79 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,88 +1,29 @@
<?php

if (PHP_SAPI !== 'cli') {
die('This script supports command line usage only. Please check your command.');
}

$header = <<<EOF
This file is part of the "headless" Extension for TYPO3 CMS.
For the full copyright and license information, please read the
LICENSE.md file that was distributed with this source code.
EOF;

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules(
[
'@DoctrineAnnotation' => true,
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_after_opening_tag' => true,
'braces' => ['allow_single_line_closure' => true],
'cast_spaces' => ['space' => 'none'],
'compact_nullable_typehint' => true,
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => ['space' => 'none'],
'dir_constant' => true,
'function_typehint_space' => true,
'general_phpdoc_annotation_remove' => ['annotations' => ['author']],
'lowercase_cast' => true,
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'modernize_types_casting' => true,
'native_function_casing' => true,
'new_with_braces' => true,
'no_alias_functions' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_null_property_initialization' => true,
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_superfluous_elseif' => true,
'no_trailing_comma_in_singleline' => true,
'no_unneeded_control_parentheses' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_whitespace_in_blank_line' => true,
'ordered_imports' => [
'imports_order' => [
'class',
'function',
'const',
],
'sort_algorithm' => 'alpha',
],
'php_unit_construct' => ['assertions' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame']],
'php_unit_mock_short_will_return' => true,
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
'phpdoc_no_access' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_scalar' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'return_type_declaration' => ['space_before' => 'none'],
'single_line_comment_style' => ['comment_types' => ['hash']],
'single_quote' => true,
'single_trait_insert_per_statement' => true,
'whitespace_after_comma_in_array' => true,
'header_comment' => [
'header' => $header,
'comment_type' => 'comment',
'location' => 'after_open',
'separate' => 'both'
],
]
)
->setFinder(
PhpCsFixer\Finder::create()
->exclude('.build')
->exclude('var')
->exclude('public')
->in(__DIR__)
);
$config = \TYPO3\CodingStandards\CsFixerConfig::create();
$config->getFinder()->in('Classes')->in('Configuration')->in('Tests');
$rules = $config->getRules();
$rules['ordered_imports'] = [
'imports_order' => [
'class',
'function',
'const',
],
'sort_algorithm' => 'alpha',
];
$rules['header_comment'] = [
'header' => $header,
'comment_type' => 'comment',
'location' => 'after_open',
'separate' => 'both'
];

$config->setRules($rules);
return $config;
6 changes: 3 additions & 3 deletions Classes/ContentObject/JsonContentObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function cObjGet(array $setup, string $addKey = ''): array
$sKeyArray = $this->filterByStringKeys($setup);
foreach ($sKeyArray as $theKey) {
$theValue = $setup[$theKey];
if ((string)$theKey && strpos($theKey, '.') === false) {
if ((string)$theKey && !str_contains($theKey, '.')) {
$conf = $setup[$theKey . '.'] ?? [];
$contentDataProcessing['dataProcessing.'] = $conf['dataProcessing.'] ?? [];
$content[$theKey] = $this->cObj->cObjGetSingle($theValue, $conf, $addKey . $theKey);
Expand All @@ -111,7 +111,7 @@ public function cObjGet(array $setup, string $addKey = ''): array
if ((isset($conf['boolval']) && $conf['boolval']) || $theValue === 'BOOL') {
$content[$theKey] = (bool)(int)$content[$theKey];
}
if ($theValue === 'USER_INT' || strpos((string)$content[$theKey], '<!--INT_SCRIPT.') === 0) {
if ($theValue === 'USER_INT' || str_starts_with((string)$content[$theKey], '<!--INT_SCRIPT.')) {
$content[$theKey] = $this->headlessUserInt->wrap($content[$theKey], (int)($conf['ifEmptyReturnNull'] ?? 0) === 1 ? HeadlessUserInt::STANDARD_NULLABLE : HeadlessUserInt::STANDARD);
}
if ((int)($conf['ifEmptyReturnNull'] ?? 0) === 1 && $content[$theKey] === '') {
Expand Down Expand Up @@ -165,7 +165,7 @@ protected function processFieldWithDataProcessing(array $dataProcessing): mixed
$dataProcessing,
[
'data' => $this->cObj->data,
'current' => $this->cObj->data[$this->cObj->currentValKey ?? null] ?? null
'current' => $this->cObj->data[$this->cObj->currentValKey ?? null] ?? null,
]
);

Expand Down
6 changes: 3 additions & 3 deletions Classes/DataProcessing/GalleryProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected function calculateMediaWidthsAndHeights()
);
$this->mediaDimensions[$key] = [
'width' => $mediaWidth,
'height' => $mediaHeight
'height' => $mediaHeight,
];
}

Expand All @@ -126,7 +126,7 @@ protected function calculateMediaWidthsAndHeights()
);
$this->mediaDimensions[$key] = [
'width' => $mediaWidth,
'height' => $mediaHeight
'height' => $mediaHeight,
];
}

Expand All @@ -144,7 +144,7 @@ protected function calculateMediaWidthsAndHeights()
);
$this->mediaDimensions[$key] = [
'width' => $mediaWidth,
'height' => $mediaHeight
'height' => $mediaHeight,
];
}
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/DataProcessing/RootSiteProcessing/DomainSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function process(SiteProviderInterface $provider, array $options = []): a
],
'i18n' => [
'locales' => $locales,
'defaultLocale' => $site->getDefaultLanguage()->getTypo3Language()
'defaultLocale' => $site->getDefaultLanguage()->getTypo3Language(),
],
];

Expand Down
2 changes: 1 addition & 1 deletion Classes/DataProcessing/RootSitesProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function process(
[
'processorConfiguration' => $processorConfiguration,
'siteUid' => $siteUid,
'cObj' => $cObj
'cObj' => $cObj,
]
);

Expand Down
2 changes: 1 addition & 1 deletion Classes/Middleware/RedirectHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function buildRedirectResponse(UriInterface $uri, array $redirectRecor

return new JsonResponse([
'redirectUrl' => $redirectUrlEvent->getTargetUrl(),
'statusCode' => $redirectUrlEvent->getTargetStatusCode()
'statusCode' => $redirectUrlEvent->getTargetStatusCode(),
]);
}
}
8 changes: 4 additions & 4 deletions Classes/Service/PaginationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PaginationService
'itemsPerPage' => 10,
'maximumNumberOfLinks' => 99,
'insertAbove' => false,
'insertBelow' => true
'insertBelow' => true,
];

/**
Expand Down Expand Up @@ -93,7 +93,7 @@ public function __construct(
'itemsPerPage' => $itemsPerPage,
'maximumNumberOfLinks' => $maximumNumberOfLinks,
'insertAbove' => $insertAbove,
'insertBelow' => $insertBelow
'insertBelow' => $insertBelow,
];
$this->numberOfPages = (int)ceil(count($this->objects) / $itemsPerPage);
}
Expand Down Expand Up @@ -140,7 +140,7 @@ public function paginate(int $currentPage = 1): array
'configuration' => $this->configuration,
'recordId' => $this->recordId,
'pageId' => $this->getCurrentPageId(),
'pagination' => $this->buildPagination()
'pagination' => $this->buildPagination(),
];
}

Expand Down Expand Up @@ -169,7 +169,7 @@ protected function buildPagination(): array
'displayRangeStart' => $this->displayRangeStart,
'displayRangeEnd' => $this->displayRangeEnd,
'hasLessPages' => $this->displayRangeStart > 2,
'hasMorePages' => $this->displayRangeEnd + 1 < $this->numberOfPages
'hasMorePages' => $this->displayRangeEnd + 1 < $this->numberOfPages,
];
if ($this->currentPage < $this->numberOfPages) {
$pagination['nextPage'] = $this->currentPage + 1;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Utility/FileUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function processFile(
],
'cropDimensions' => [
'width' => $this->getCroppedDimensionalProperty($fileReference, 'width', $cropVariant),
'height' => $this->getCroppedDimensionalProperty($fileReference, 'height', $cropVariant)
'height' => $this->getCroppedDimensionalProperty($fileReference, 'height', $cropVariant),
],
'crop' => $crop,
'autoplay' => $fileReference->getProperty('autoplay'),
Expand Down
5 changes: 2 additions & 3 deletions Classes/Utility/UrlUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use function array_merge;
use function rtrim;
use function str_contains;
use function strpos;

class UrlUtility implements LoggerAwareInterface, HeadlessFrontendUrlInterface
{
Expand Down Expand Up @@ -182,11 +181,11 @@ private function sanitizeBaseUrl(string $base): string
{
// no protocol ("//") and the first part is no "/" (path), means that this is a domain like
// "www.domain.com/blabla", and we want to ensure that this one then gets a "no-scheme agnostic" part
if (!empty($base) && strpos($base, '//') === false && $base[0] !== '/') {
if (!empty($base) && !str_contains($base, '//') && $base[0] !== '/') {
// either a scheme is added, or no scheme but with domain, or a path which is not absolute
// make the base prefixed with a slash, so it is recognized as path, not as domain
// treat as path
if (strpos($base, '.') === false) {
if (!str_contains($base, '.')) {
$base = '/' . $base;
} else {
// treat as domain name
Expand Down
2 changes: 1 addition & 1 deletion Classes/ViewHelpers/Iterator/ExplodeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function render()
protected function resolveGlue(): string
{
$glue = $this->arguments['glue'];
if (false !== strpos($glue, ':') && 1 < strlen($glue)) {
if (str_contains($glue, ':') && strlen($glue) > 1) {
// glue contains a special type identifier, resolve the actual glue
list($type, $value) = explode(':', $glue);
switch ($type) {
Expand Down
14 changes: 7 additions & 7 deletions Configuration/RequestMiddlewares.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
'after' => [
'typo3/cms-frontend/content-length-headers',
],
'target' => UserIntMiddleware::class
'target' => UserIntMiddleware::class,
],
],
];
Expand All @@ -33,18 +33,18 @@
'after' => [
'typo3/cms-adminpanel/data-persister',
],
'target' => ElementBodyResponseMiddleware::class
'target' => ElementBodyResponseMiddleware::class,
];
}

if ($features->isFeatureEnabled('headless.cookieDomainPerSite')) {
$middlewares['backend'] = [
'headless/cms-backend/cookie-domain-middleware' => [
'before' => [
'typo3/cms-backend/authentication'
'typo3/cms-backend/authentication',
],
'target' => \FriendsOfTYPO3\Headless\Middleware\CookieDomainPerSite::class
]
'target' => \FriendsOfTYPO3\Headless\Middleware\CookieDomainPerSite::class,
],
];
}

Expand All @@ -58,7 +58,7 @@
'disabled' => true,
],
'typo3/cms-frontend/shortcut-and-mountpoint-redirect' => [
'disabled' => true
'disabled' => true,
],
'headless/cms-redirects/redirecthandler' => [
'target' => RedirectHandler::class,
Expand All @@ -78,6 +78,6 @@
'typo3/cms-frontend/content-length-headers',
],
],
]
],
]);
})();
2 changes: 1 addition & 1 deletion Configuration/SiteConfiguration/Overrides/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'eval' => 'trim',
'placeholder' => 'http://www.domain.local',
],
]
],
];

$replaceShowItem = 'base, frontendBase, ';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'eval' => 'trim',
'placeholder' => 'http://www.domain.local',
],
]
],
];

$replaceShowItem = 'base, frontendBase, ';
Expand Down
8 changes: 4 additions & 4 deletions Tests/Functional/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
abstract class BaseTest extends FunctionalTestCase
{
protected array $coreExtensionsToLoad = [
'install'
'install',
];
protected array $testExtensionsToLoad = [
'typo3conf/ext/headless'
'typo3conf/ext/headless',
];

/**
Expand All @@ -40,7 +40,7 @@ public function setUp(): void
1,
[
'constants' => ['EXT:headless/Configuration/TypoScript/constants.typoscript'],
'setup' => ['EXT:headless/Configuration/TypoScript/setup.typoscript']
'setup' => ['EXT:headless/Configuration/TypoScript/setup.typoscript'],
]
);

Expand Down Expand Up @@ -70,7 +70,7 @@ protected function assertJsonSchema(string $jsonString, string $jsonSchemaFile)
);
$validator = new Validator();
$validator->check($data, $schema);
if (false === $validator->isValid()) {
if ($validator->isValid() === false) {
foreach ($validator->getErrors() as $error) {
self::fail(sprintf('Property "%s" is not valid: %s in %s', $error['property'], $error['message'], $jsonString));
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/PageTypes/BasePageTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function assertJsonSchema(string $jsonString, string $jsonSchemaFile)
);
$validator = new Validator();
$validator->check($data, $schema);
if (false === $validator->isValid()) {
if ($validator->isValid() === false) {
foreach ($validator->getErrors() as $error) {
self::fail(sprintf('Property "%s" is not valid: %s in %s', $error['property'], $error['message'], $jsonString));
}
Expand Down
Loading

0 comments on commit a565d74

Please sign in to comment.