Skip to content

Commit fa1ac40

Browse files
committed
Bump respect/coding-standard from 4 to 5
I had to make a few manual changes for everything to pass.
1 parent 784080a commit fa1ac40

File tree

55 files changed

+191
-193
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+191
-193
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
"phpstan/phpstan-phpunit": "^2.0",
2121
"phpstan/phpstan-strict-rules": "^2.0",
2222
"phpunit/phpunit": "^12.5",
23-
"respect/coding-standard": "^4.0",
24-
"squizlabs/php_codesniffer": "^3.7"
23+
"respect/coding-standard": "^5.0"
2524
},
2625
"autoload": {
2726
"psr-4": {

phpcs.xml.dist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,19 @@
1717
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
1818
<exclude-pattern>tests/fixtures/</exclude-pattern>
1919
</rule>
20+
<rule ref="Squiz.Arrays.ArrayDeclaration.ValueNoNewline">
21+
<exclude-pattern>tests/unit/Stringifiers/CallableStringifierTest.php</exclude-pattern>
22+
</rule>
23+
<rule ref="Squiz.Functions.GlobalFunction">
24+
<exclude-pattern>tests/integration/lib/helpers.php</exclude-pattern>
25+
</rule>
26+
<rule ref="Generic.Files.InlineHTML.Found">
27+
<exclude-pattern>tests/integration/</exclude-pattern>
28+
</rule>
29+
<rule ref="PSR12.Files.FileHeader.HeaderPosition">
30+
<exclude-pattern>tests/integration/</exclude-pattern>
31+
</rule>
32+
<rule ref="Generic.PHP.CharacterBeforePHPOpeningTag.Found">
33+
<exclude-pattern>tests/integration/</exclude-pattern>
34+
</rule>
2035
</ruleset>

src/Helpers/ObjectHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
trait ObjectHelper
2020
{
21-
private function format(object $object, ?string ...$pieces): string
21+
private function format(object $object, string|null ...$pieces): string
2222
{
2323
$filteredPieces = array_filter($pieces);
2424
if (count($filteredPieces) === 0) {

src/Quoters/StandardQuoter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
final class StandardQuoter implements Quoter
2222
{
23-
private const OBJECT_PLACEHOLDER = ' ... }';
24-
private const ARRAY_PLACEHOLDER = ' ... ]';
25-
private const GENERIC_PLACEHOLDER = ' ...';
23+
private const string OBJECT_PLACEHOLDER = ' ... }';
24+
private const string ARRAY_PLACEHOLDER = ' ... ]';
25+
private const string GENERIC_PLACEHOLDER = ' ...';
2626

2727
public function __construct(private readonly int $maximumLength)
2828
{

src/Stringifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212

1313
interface Stringifier
1414
{
15-
public function stringify(mixed $raw, int $depth): ?string;
15+
public function stringify(mixed $raw, int $depth): string|null;
1616
}

src/Stringifiers/ArrayObjectStringifier.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ final class ArrayObjectStringifier implements Stringifier
2121

2222
public function __construct(
2323
private readonly Stringifier $stringifier,
24-
private readonly Quoter $quoter
24+
private readonly Quoter $quoter,
2525
) {
2626
}
2727

28-
public function stringify(mixed $raw, int $depth): ?string
28+
public function stringify(mixed $raw, int $depth): string|null
2929
{
3030
if (!$raw instanceof ArrayObject) {
3131
return null;
3232
}
3333

3434
return $this->quoter->quote(
3535
$this->format($raw, 'getArrayCopy() =>', $this->stringifier->stringify($raw->getArrayCopy(), $depth + 1)),
36-
$depth
36+
$depth,
3737
);
3838
}
3939
}

src/Stringifiers/ArrayStringifier.php

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

2323
final class ArrayStringifier implements Stringifier
2424
{
25-
private const LIMIT_EXCEEDED_PLACEHOLDER = '...';
25+
private const string LIMIT_EXCEEDED_PLACEHOLDER = '...';
2626

2727
public function __construct(
2828
private readonly Stringifier $stringifier,
2929
private readonly Quoter $quoter,
3030
private readonly int $maximumDepth,
31-
private readonly int $maximumNumberOfItems
31+
private readonly int $maximumNumberOfItems,
3232
) {
3333
}
3434

35-
public function stringify(mixed $raw, int $depth): ?string
35+
public function stringify(mixed $raw, int $depth): string|null
3636
{
3737
if (!is_array($raw)) {
3838
return null;
@@ -66,7 +66,7 @@ public function stringify(mixed $raw, int $depth): ?string
6666
return $this->quoter->quote(sprintf('[%s]', implode(', ', $items)), $depth);
6767
}
6868

69-
private function stringifyKeyValue(mixed $value, int $depth): ?string
69+
private function stringifyKeyValue(mixed $value, int $depth): string|null
7070
{
7171
if (is_array($value)) {
7272
return $this->stringify($value, $depth);
@@ -75,9 +75,7 @@ private function stringifyKeyValue(mixed $value, int $depth): ?string
7575
return $this->stringifier->stringify($value, $depth);
7676
}
7777

78-
/**
79-
* @param mixed[] $array
80-
*/
78+
/** @param mixed[] $array */
8179
private function isSequential(array $array): bool
8280
{
8381
return array_keys($array) === range(0, count($array) - 1);

src/Stringifiers/BoolStringifier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
final class BoolStringifier implements Stringifier
1919
{
2020
public function __construct(
21-
private readonly Quoter $quoter
21+
private readonly Quoter $quoter,
2222
) {
2323
}
2424

25-
public function stringify(mixed $raw, int $depth): ?string
25+
public function stringify(mixed $raw, int $depth): string|null
2626
{
2727
if (!is_bool($raw)) {
2828
return null;

src/Stringifiers/CallableStringifier.php

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct(
4747
) {
4848
}
4949

50-
public function stringify(mixed $raw, int $depth): ?string
50+
public function stringify(mixed $raw, int $depth): string|null
5151
{
5252
if (!is_callable($raw)) {
5353
return null;
@@ -69,15 +69,18 @@ public function stringify(mixed $raw, int $depth): ?string
6969
return $this->buildStaticMethod(new ReflectionMethod($raw[0], $raw[1]), $depth);
7070
}
7171

72-
/** @var callable-string $raw */
73-
if (str_contains($raw, ':')) {
72+
if (is_string($raw) && str_contains($raw, ':')) {
7473
/** @var class-string $class */
7574
$class = (string) strstr($raw, ':', true);
7675
$method = substr((string) strrchr($raw, ':'), 1);
7776

7877
return $this->buildStaticMethod(new ReflectionMethod($class, $method), $depth);
7978
}
8079

80+
if (!is_string($raw)) {
81+
return null;
82+
}
83+
8184
return $this->buildFunction(new ReflectionFunction($raw), $depth);
8285
}
8386

@@ -90,15 +93,15 @@ private function buildMethod(ReflectionMethod $reflection, object $object, int $
9093
{
9194
return $this->quoter->quote(
9295
sprintf('%s->%s', $this->getName($object), $this->buildSignature($reflection, $depth)),
93-
$depth
96+
$depth,
9497
);
9598
}
9699

97100
private function buildStaticMethod(ReflectionMethod $reflection, int $depth): string
98101
{
99102
return $this->quoter->quote(
100103
sprintf('%s::%s', $reflection->class, $this->buildSignature($reflection, $depth)),
101-
$depth
104+
$depth,
102105
);
103106
}
104107

@@ -112,10 +115,10 @@ private function buildSignature(ReflectionFunctionAbstract $function, int $depth
112115
array_map(
113116
fn(ReflectionParameter $parameter): string => $this->buildParameter(
114117
$parameter,
115-
$depth + 1
118+
$depth + 1,
116119
),
117-
$function->getParameters()
118-
)
120+
$function->getParameters(),
121+
),
119122
),
120123
);
121124

@@ -125,7 +128,7 @@ private function buildSignature(ReflectionFunctionAbstract $function, int $depth
125128
' use ($%s)',
126129
implode(
127130
', $',
128-
array_keys($closureUsedVariables)
131+
array_keys($closureUsedVariables),
129132
),
130133
);
131134
}
@@ -160,7 +163,7 @@ private function buildParameter(ReflectionParameter $reflectionParameter, int $d
160163
return $parameter;
161164
}
162165

163-
private function buildValue(ReflectionParameter $reflectionParameter, int $depth): ?string
166+
private function buildValue(ReflectionParameter $reflectionParameter, int $depth): string|null
164167
{
165168
if (!$reflectionParameter->isDefaultValueAvailable()) {
166169
return $this->stringifier->stringify(null, $depth);
@@ -178,19 +181,26 @@ private function buildType(ReflectionType $raw, int $depth): string
178181
if ($raw instanceof ReflectionUnionType) {
179182
return implode(
180183
'|',
181-
array_map(fn(ReflectionType $type) => $this->buildType($type, $depth), $raw->getTypes())
184+
array_map(fn(ReflectionType $type) => $this->buildType($type, $depth), $raw->getTypes()),
182185
);
183186
}
184187

185188
if ($raw instanceof ReflectionIntersectionType) {
186189
return implode(
187190
'&',
188-
array_map(fn(ReflectionType $type) => $this->buildType($type, $depth), $raw->getTypes())
191+
array_map(fn(ReflectionType $type) => $this->buildType($type, $depth), $raw->getTypes()),
189192
);
190193
}
191194

192-
/** @var ReflectionNamedType $raw */
195+
if ($raw instanceof ReflectionNamedType) {
196+
$type = $raw->getName();
197+
if ($raw->allowsNull()) {
198+
$type = sprintf('?%s', $type);
199+
}
200+
201+
return $type;
202+
}
193203

194-
return ($raw->allowsNull() ? '?' : '') . $raw->getName();
204+
return '';
195205
}
196206
}

src/Stringifiers/CompositeStringifier.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@
1818

1919
final class CompositeStringifier implements Stringifier
2020
{
21-
private const MAXIMUM_DEPTH = 3;
22-
private const MAXIMUM_NUMBER_OF_ITEMS = 5;
23-
private const MAXIMUM_NUMBER_OF_PROPERTIES = self::MAXIMUM_NUMBER_OF_ITEMS;
24-
private const MAXIMUM_LENGTH = 120;
21+
private const int MAXIMUM_DEPTH = 3;
22+
private const int MAXIMUM_NUMBER_OF_ITEMS = 5;
23+
private const int MAXIMUM_NUMBER_OF_PROPERTIES = self::MAXIMUM_NUMBER_OF_ITEMS;
24+
private const int MAXIMUM_LENGTH = 120;
2525

26-
/**
27-
* @var Stringifier[]
28-
*/
26+
/** @var Stringifier[] */
2927
private array $stringifiers = [];
3028

3129
public function __construct(Stringifier ...$stringifiers)
@@ -52,15 +50,15 @@ public static function createDefault(): self
5250
$quoter,
5351
self::MAXIMUM_DEPTH,
5452
self::MAXIMUM_NUMBER_OF_ITEMS,
55-
)
53+
),
5654
);
5755
$stringifier->prependStringifier(
5856
new ObjectStringifier(
5957
$stringifier,
6058
$quoter,
6159
self::MAXIMUM_DEPTH,
62-
self::MAXIMUM_NUMBER_OF_PROPERTIES
63-
)
60+
self::MAXIMUM_NUMBER_OF_PROPERTIES,
61+
),
6462
);
6563
$stringifier->prependStringifier($callableStringifier = new CallableStringifier($stringifier, $quoter));
6664
$stringifier->prependStringifier(new FiberObjectStringifier($callableStringifier, $quoter));
@@ -81,7 +79,7 @@ public function prependStringifier(Stringifier $stringifier): void
8179
array_unshift($this->stringifiers, $stringifier);
8280
}
8381

84-
public function stringify(mixed $raw, int $depth): ?string
82+
public function stringify(mixed $raw, int $depth): string|null
8583
{
8684
foreach ($this->stringifiers as $stringifier) {
8785
$string = $stringifier->stringify($raw, $depth);

0 commit comments

Comments
 (0)