Skip to content

Commit 329c563

Browse files
committed
Update CS rules and fix CS
1 parent 9ac660a commit 329c563

14 files changed

Lines changed: 44 additions & 84 deletions

File tree

.php-cs-fixer.php

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,14 @@
11
<?php
22

3-
declare(strict_types=1);
3+
// To support running PHP CS Fixer via PHAR file (e.g. in GitHub Actions)
4+
require_once __DIR__ . '/vendor/netgen/coding-standard/lib/PhpCsFixer/Config.php';
45

5-
return (new PhpCsFixer\Config())
6-
->setRiskyAllowed(true)
7-
->setRules([
8-
'@PER' => true,
9-
'@PER:risky' => true,
10-
'@PhpCsFixer' => true,
11-
'@PhpCsFixer:risky' => true,
12-
13-
// Overrides for rules included in PhpCsFixer rule sets
14-
'concat_space' => ['spacing' => 'one'],
15-
'fully_qualified_strict_types' => ['phpdoc_tags' => []],
16-
'method_chaining_indentation' => false,
17-
'multiline_promoted_properties' => true,
18-
'multiline_whitespace_before_semicolons' => false,
19-
'native_function_invocation' => ['include' => ['@all']],
20-
'no_superfluous_phpdoc_tags' => false,
21-
'no_unset_on_property' => false,
22-
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
23-
'ordered_types' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'alpha'],
24-
'php_unit_internal_class' => false,
25-
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
26-
'php_unit_test_class_requires_covers' => false,
27-
'phpdoc_align' => false,
28-
'phpdoc_order' => ['order' => ['param', 'throws', 'return']],
6+
return (new Netgen\CodingStandard\PhpCsFixer\Config())
7+
->addRules([
298
'phpdoc_no_alias_tag' => false,
30-
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
31-
'single_line_comment_style' => false,
32-
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments', 'match', 'parameters']],
33-
'yoda_style' => false,
34-
35-
// Additional rules
36-
'date_time_immutable' => true,
37-
'declare_strict_types' => true,
38-
'global_namespace_import' => [
39-
'import_classes' => null,
40-
'import_constants' => true,
41-
'import_functions' => true,
42-
],
43-
'heredoc_indentation' => ['indentation' => 'same_as_start'],
44-
// 'mb_str_functions' => true,
45-
'native_constant_invocation' => true,
46-
'nullable_type_declaration_for_default_null_value' => true,
47-
'static_lambda' => true,
48-
'ternary_to_null_coalescing' => true,
49-
'use_arrow_functions' => true,
509
])
5110
->setFinder(
5211
PhpCsFixer\Finder::create()
53-
->in('bundle'),
12+
->in('bundle')
5413
)
5514
;

bundle/API/Repository/Values/Tags/Tag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use function array_map;
1111
use function count;
1212
use function explode;
13-
use function trim;
13+
use function mb_trim;
1414

1515
/**
1616
* Class representing a tag.
@@ -115,7 +115,7 @@ public function __construct(array $properties = [])
115115
parent::__construct($properties);
116116

117117
if (isset($this->pathString) && $this->pathString !== '') {
118-
$this->path = array_map('intval', explode('/', trim($this->pathString, '/')));
118+
$this->path = array_map('intval', explode('/', mb_trim($this->pathString, '/')));
119119
}
120120
}
121121

bundle/Controller/Admin/TagController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
use function count;
2424
use function in_array;
25-
use function trim;
25+
use function mb_trim;
2626

2727
final class TagController extends Controller
2828
{
@@ -672,7 +672,7 @@ public function searchTagsAction(Request $request): Response
672672
$this->denyAccessUnlessGranted('ibexa:tags:read');
673673

674674
$tags = [];
675-
$searchText = trim($request->query->get('searchText') ?? '');
675+
$searchText = mb_trim($request->query->get('searchText') ?? '');
676676

677677
if ($searchText !== '') {
678678
$page = $request->query->getInt('page', 1);

bundle/Core/Pagination/Pagerfanta/View/TagsAdminView.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
use Twig\Environment;
1111

1212
use function max;
13+
use function mb_trim;
1314
use function min;
14-
use function trim;
1515

1616
/**
1717
* @final
@@ -160,6 +160,6 @@ private function generateUrl(int $page): string
160160
{
161161
// We use trim here because Pagerfanta (or Symfony?) adds an extra '?'
162162
// at the end of page when there are no other query params
163-
return trim(($this->routeGenerator)($page), '?');
163+
return mb_trim(($this->routeGenerator)($page), '?');
164164
}
165165
}

bundle/Core/Persistence/Cache/TagsHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use function count;
2323
use function explode;
2424
use function implode;
25-
use function trim;
25+
use function mb_trim;
2626

2727
final class TagsHandler extends AbstractInMemoryHandler implements TagsHandlerInterface
2828
{
@@ -53,7 +53,7 @@ public function load(int $tagId, ?array $translations = null, bool $useAlwaysAva
5353
fn (int $tagId): Tag => $this->tagsHandler->load($tagId, $translations, $useAlwaysAvailable),
5454
static function (Tag $tag): array {
5555
$tags = ['tag-' . $tag->id];
56-
foreach (explode('/', trim($tag->pathString, '/')) as $pathId) {
56+
foreach (explode('/', mb_trim($tag->pathString, '/')) as $pathId) {
5757
$tags[] = 'tag-path-' . $pathId;
5858
}
5959

@@ -80,7 +80,7 @@ public function loadList(array $tagIds, ?array $translations = null, bool $useAl
8080
fn (array $tagIds): array => $this->tagsHandler->loadList($tagIds, $translations, $useAlwaysAvailable),
8181
static function (Tag $tag): array {
8282
$tags = ['tag-' . $tag->id];
83-
foreach (explode('/', trim($tag->pathString, '/')) as $pathId) {
83+
foreach (explode('/', mb_trim($tag->pathString, '/')) as $pathId) {
8484
$tags[] = 'tag-path-' . $pathId;
8585
}
8686

@@ -307,7 +307,7 @@ private function getCacheTags(int $tagId, string $pathString): array
307307
{
308308
$tags = ['tag-' . $tagId];
309309

310-
foreach (explode('/', trim($pathString, '/')) as $pathId) {
310+
foreach (explode('/', mb_trim($pathString, '/')) as $pathId) {
311311
$tags[] = 'tag-path-' . $pathId;
312312
}
313313

bundle/Core/Persistence/Legacy/Tags/Gateway/DoctrineDatabase.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
use function implode;
2626
use function is_array;
2727
use function is_bool;
28+
use function max;
2829
use function mb_strtolower;
2930
use function mb_substr_count;
31+
use function mb_trim;
3032
use function str_replace;
3133
use function time;
32-
use function trim;
3334

3435
use const PHP_INT_MAX;
3536

@@ -1110,7 +1111,7 @@ private function insertTagKeywords(int $tagId, array $keywords, string $mainLang
11101111
*/
11111112
private function getSynonymPathString(int $synonymId, string $mainTagPathString): string
11121113
{
1113-
$pathStringElements = explode('/', trim($mainTagPathString, '/'));
1114+
$pathStringElements = explode('/', mb_trim($mainTagPathString, '/'));
11141115
array_pop($pathStringElements);
11151116

11161117
return (count($pathStringElements) > 0 ? '/' . implode('/', $pathStringElements) : '') . '/' . $synonymId . '/';

bundle/Core/REST/Controller/Tags.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use function explode;
1919
use function in_array;
2020
use function max;
21-
use function trim;
21+
use function mb_trim;
2222

2323
final class Tags extends RestController
2424
{
@@ -47,7 +47,7 @@ public function redirectTag(Request $request): BaseValues\TemporaryRedirect
4747
$this->router->generate(
4848
'ibexa.rest.netgen_tags_loadTag',
4949
[
50-
'tagPath' => trim($tag->pathString, '/'),
50+
'tagPath' => mb_trim($tag->pathString, '/'),
5151
],
5252
),
5353
);
@@ -64,7 +64,7 @@ public function loadTag(string $tagPath): Values\CachedValue
6464
$this->extractTagIdFromPath($tagPath),
6565
);
6666

67-
if (trim($tag->pathString, '/') !== $tagPath) {
67+
if (mb_trim($tag->pathString, '/') !== $tagPath) {
6868
throw new Exceptions\NotFoundException(
6969
"Could not find tag with path string {$tagPath}",
7070
);
@@ -326,7 +326,7 @@ public function copySubtree(string $tagPath, Request $request): BaseValues\Resou
326326
$this->router->generate(
327327
'ibexa.rest.netgen_tags_loadTag',
328328
[
329-
'tagPath' => trim($newTag->pathString, '/'),
329+
'tagPath' => mb_trim($newTag->pathString, '/'),
330330
],
331331
),
332332
);
@@ -369,7 +369,7 @@ public function moveSubtree(string $tagPath, Request $request): BaseValues\Resou
369369
$this->router->generate(
370370
'ibexa.rest.netgen_tags_loadTag',
371371
[
372-
'tagPath' => trim($tag->pathString, '/'),
372+
'tagPath' => mb_trim($tag->pathString, '/'),
373373
],
374374
),
375375
);
@@ -409,7 +409,7 @@ public function convertToSynonym(string $tagPath, Request $request): BaseValues\
409409
$this->router->generate(
410410
'ibexa.rest.netgen_tags_loadTag',
411411
[
412-
'tagPath' => trim($convertedTag->pathString, '/'),
412+
'tagPath' => mb_trim($convertedTag->pathString, '/'),
413413
],
414414
),
415415
);
@@ -467,7 +467,7 @@ public function deleteTag(string $tagPath): BaseValues\NoContent
467467
*/
468468
private function extractTagIdFromPath(string $path): int
469469
{
470-
$pathParts = explode('/', trim($path, '/'));
470+
$pathParts = explode('/', mb_trim($path, '/'));
471471

472472
return (int) array_pop($pathParts);
473473
}

bundle/Core/REST/Output/ValueObjectVisitor/CreatedTag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Ibexa\Contracts\Rest\Output\Generator;
88
use Ibexa\Contracts\Rest\Output\Visitor;
99

10-
use function trim;
10+
use function mb_trim;
1111

1212
final class CreatedTag extends RestTag
1313
{
@@ -20,7 +20,7 @@ public function visit(Visitor $visitor, Generator $generator, mixed $data): void
2020
$this->router->generate(
2121
'ibexa.rest.netgen_tags_loadTag',
2222
[
23-
'tagPath' => trim($data->restTag->tag->pathString, '/'),
23+
'tagPath' => mb_trim($data->restTag->tag->pathString, '/'),
2424
],
2525
),
2626
);

bundle/Core/REST/Output/ValueObjectVisitor/RestTag.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use function explode;
1414
use function implode;
1515
use function in_array;
16-
use function trim;
16+
use function mb_trim;
1717

1818
class RestTag extends ValueObjectVisitor
1919
{
@@ -29,15 +29,15 @@ public function visit(Visitor $visitor, Generator $generator, mixed $data): void
2929
'href',
3030
$this->router->generate(
3131
'ibexa.rest.netgen_tags_loadTag',
32-
['tagPath' => trim($tag->pathString, '/')],
32+
['tagPath' => mb_trim($tag->pathString, '/')],
3333
),
3434
);
3535
$generator->endAttribute('href');
3636

3737
$generator->startValueElement('id', $tag->id);
3838
$generator->endValueElement('id');
3939

40-
$tagPath = explode('/', trim($tag->pathString, '/'));
40+
$tagPath = explode('/', mb_trim($tag->pathString, '/'));
4141
$parentPathString = implode('/', array_slice($tagPath, 0, count($tagPath) - 1));
4242

4343
if ($tag->parentTagId > 0) {
@@ -113,7 +113,7 @@ public function visit(Visitor $visitor, Generator $generator, mixed $data): void
113113
$this->router->generate(
114114
'ibexa.rest.netgen_tags_loadTagChildren',
115115
[
116-
'tagPath' => trim($tag->pathString, '/'),
116+
'tagPath' => mb_trim($tag->pathString, '/'),
117117
],
118118
),
119119
);
@@ -128,7 +128,7 @@ public function visit(Visitor $visitor, Generator $generator, mixed $data): void
128128
'href',
129129
$this->router->generate(
130130
'ibexa.rest.netgen_tags_loadTagSynonyms',
131-
['tagPath' => trim($tag->pathString, '/')],
131+
['tagPath' => mb_trim($tag->pathString, '/')],
132132
),
133133
);
134134
$generator->endAttribute('href');
@@ -141,7 +141,7 @@ public function visit(Visitor $visitor, Generator $generator, mixed $data): void
141141
$this->router->generate(
142142
'ibexa.rest.netgen_tags_getRelatedContent',
143143
[
144-
'tagPath' => trim($tag->pathString, '/'),
144+
'tagPath' => mb_trim($tag->pathString, '/'),
145145
],
146146
),
147147
);

bundle/Core/REST/Output/ValueObjectVisitor/TagList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Ibexa\Contracts\Rest\Output\ValueObjectVisitor;
99
use Ibexa\Contracts\Rest\Output\Visitor;
1010

11-
use function trim;
11+
use function mb_trim;
1212

1313
final class TagList extends ValueObjectVisitor
1414
{
@@ -28,7 +28,7 @@ public function visit(Visitor $visitor, Generator $generator, mixed $data): void
2828
'href',
2929
$this->router->generate(
3030
'ibexa.rest.netgen_tags_loadTag',
31-
['tagPath' => trim($restTag->tag->pathString, '/')],
31+
['tagPath' => mb_trim($restTag->tag->pathString, '/')],
3232
),
3333
);
3434
$generator->endAttribute('href');

0 commit comments

Comments
 (0)