Skip to content

Commit a9ac2b2

Browse files
committed
Updated Rector to commit 62254600d1d3f036ae3e9c502613c4ac96a8b71b
rectorphp/rector-src@6225460 [CodeQuality] Add support for compare $this::class compare with string on UseIdenticalOverEqualWithSameTypeRector (#5698)
1 parent d1ec79d commit a9ac2b2

File tree

8 files changed

+47
-35
lines changed

8 files changed

+47
-35
lines changed

rules/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,24 @@ public function refactor(Node $node) : ?Node
6363
return null;
6464
}
6565
$rightStaticType = $this->nodeTypeResolver->getNativeType($node->right);
66+
if ($leftStaticType->isString()->yes() && $rightStaticType->isString()->yes()) {
67+
return $this->processIdenticalOrNotIdentical($node);
68+
}
6669
if ($rightStaticType instanceof MixedType) {
6770
return null;
6871
}
6972
// different types
7073
if (!$leftStaticType->equals($rightStaticType)) {
7174
return null;
7275
}
76+
return $this->processIdenticalOrNotIdentical($node);
77+
}
78+
/**
79+
* @param \PhpParser\Node\Expr\BinaryOp\Equal|\PhpParser\Node\Expr\BinaryOp\NotEqual $node
80+
* @return \PhpParser\Node\Expr\BinaryOp\Identical|\PhpParser\Node\Expr\BinaryOp\NotIdentical
81+
*/
82+
private function processIdenticalOrNotIdentical($node)
83+
{
7384
if ($node instanceof Equal) {
7485
return new Identical($node->left, $node->right);
7586
}

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '4a1880bd2976e3cda6db8b1ca27c44c2c933b9e4';
22+
public const PACKAGE_VERSION = '62254600d1d3f036ae3e9c502613c4ac96a8b71b';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2024-03-07 20:44:22';
27+
public const RELEASE_DATE = '2024-03-07 23:31:56';
2828
/**
2929
* @var int
3030
*/

vendor/composer/installed.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@
6969
},
7070
{
7171
"name": "composer\/pcre",
72-
"version": "3.1.1",
73-
"version_normalized": "3.1.1.0",
72+
"version": "3.1.2",
73+
"version_normalized": "3.1.2.0",
7474
"source": {
7575
"type": "git",
7676
"url": "https:\/\/github.com\/composer\/pcre.git",
77-
"reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9"
77+
"reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace"
7878
},
7979
"dist": {
8080
"type": "zip",
81-
"url": "https:\/\/api.github.com\/repos\/composer\/pcre\/zipball\/00104306927c7a0919b4ced2aaa6782c1e61a3c9",
82-
"reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9",
81+
"url": "https:\/\/api.github.com\/repos\/composer\/pcre\/zipball\/4775f35b2d70865807c89d32c8e7385b86eb0ace",
82+
"reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace",
8383
"shasum": ""
8484
},
8585
"require": {
@@ -90,7 +90,7 @@
9090
"phpstan\/phpstan-strict-rules": "^1.1",
9191
"symfony\/phpunit-bridge": "^5"
9292
},
93-
"time": "2023-10-11T07:11:09+00:00",
93+
"time": "2024-03-07T15:38:35+00:00",
9494
"type": "library",
9595
"extra": {
9696
"branch-alias": {
@@ -123,7 +123,7 @@
123123
],
124124
"support": {
125125
"issues": "https:\/\/github.com\/composer\/pcre\/issues",
126-
"source": "https:\/\/github.com\/composer\/pcre\/tree\/3.1.1"
126+
"source": "https:\/\/github.com\/composer\/pcre\/tree\/3.1.2"
127127
},
128128
"funding": [
129129
{

vendor/composer/installed.php

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

vendor/composer/pcre/src/MatchAllResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final class MatchAllResult
3131
public $matched;
3232
/**
3333
* @param 0|positive-int $count
34-
* @param array<int|string, array<string|null>> $matches
34+
* @param array<int|string, list<string|null>> $matches
3535
*/
3636
public function __construct(int $count, array $matches)
3737
{

vendor/composer/pcre/src/MatchAllStrictGroupsResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final class MatchAllStrictGroupsResult
3131
public $matched;
3232
/**
3333
* @param 0|positive-int $count
34-
* @param array<array<string>> $matches
34+
* @param array<list<string>> $matches
3535
*/
3636
public function __construct(int $count, array $matches)
3737
{

vendor/composer/pcre/src/Preg.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Preg
1818
public const INVALID_TYPE_MSG = '$subject must be a string, %s given.';
1919
/**
2020
* @param non-empty-string $pattern
21-
* @param array<string|null> $matches Set by method
21+
* @param array<mixed> $matches Set by method
2222
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
2323
* @return 0|1
2424
*
@@ -37,7 +37,7 @@ public static function match(string $pattern, string $subject, ?array &$matches
3737
* Variant of `match()` which outputs non-null matches (or throws)
3838
*
3939
* @param non-empty-string $pattern
40-
* @param array<string> $matches Set by method
40+
* @param array<mixed> $matches Set by method
4141
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
4242
* @return 0|1
4343
* @throws UnexpectedNullMatchException
@@ -54,7 +54,7 @@ public static function matchStrictGroups(string $pattern, string $subject, ?arra
5454
* Runs preg_match with PREG_OFFSET_CAPTURE
5555
*
5656
* @param non-empty-string $pattern
57-
* @param array<int|string, array{string|null, int}> $matches Set by method
57+
* @param array<mixed> $matches Set by method
5858
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_UNMATCHED_AS_NULL and PREG_OFFSET_CAPTURE are always set, no other flags are supported
5959
* @return 0|1
6060
*
@@ -70,7 +70,7 @@ public static function matchWithOffsets(string $pattern, string $subject, ?array
7070
}
7171
/**
7272
* @param non-empty-string $pattern
73-
* @param array<int|string, list<string|null>> $matches Set by method
73+
* @param array<mixed> $matches Set by method
7474
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
7575
* @return 0|positive-int
7676
*
@@ -91,7 +91,7 @@ public static function matchAll(string $pattern, string $subject, ?array &$match
9191
* Variant of `match()` which outputs non-null matches (or throws)
9292
*
9393
* @param non-empty-string $pattern
94-
* @param array<int|string, list<string|null>> $matches Set by method
94+
* @param array<mixed> $matches Set by method
9595
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
9696
* @return 0|positive-int
9797
* @throws UnexpectedNullMatchException
@@ -108,7 +108,7 @@ public static function matchAllStrictGroups(string $pattern, string $subject, ?a
108108
* Runs preg_match_all with PREG_OFFSET_CAPTURE
109109
*
110110
* @param non-empty-string $pattern
111-
* @param array<int|string, list<array{string|null, int}>> $matches Set by method
111+
* @param array<mixed> $matches Set by method
112112
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_UNMATCHED_AS_NULL and PREG_MATCH_OFFSET are always set, no other flags are supported
113113
* @return 0|positive-int
114114
*
@@ -148,7 +148,7 @@ public static function replace($pattern, $replacement, $subject, int $limit = -1
148148
}
149149
/**
150150
* @param string|string[] $pattern
151-
* @param callable(array<int|string, string|null>): string $replacement
151+
* @param ($flags is PREG_OFFSET_CAPTURE ? (callable(array<int|string, array{string|null, int<-1, max>}>): string) : callable(array<int|string, string|null>): string) $replacement
152152
* @param string $subject
153153
* @param int $count Set by method
154154
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_OFFSET_CAPTURE is supported, PREG_UNMATCHED_AS_NULL is always set
@@ -173,10 +173,10 @@ public static function replaceCallback($pattern, callable $replacement, $subject
173173
* Variant of `replaceCallback()` which outputs non-null matches (or throws)
174174
*
175175
* @param string $pattern
176-
* @param callable(array<int|string, string>): string $replacement
176+
* @param ($flags is PREG_OFFSET_CAPTURE ? (callable(array<int|string, array{string, int<0, max>}>): string) : callable(array<int|string, string>): string) $replacement
177177
* @param string $subject
178178
* @param int $count Set by method
179-
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_OFFSET_CAPTURE or PREG_UNMATCHED_AS_NULL, only available on PHP 7.4+
179+
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_OFFSET_CAPTURE is supported, PREG_UNMATCHED_AS_NULL is always set
180180
*
181181
* @param-out int<0, max> $count
182182
*/
@@ -187,7 +187,7 @@ public static function replaceCallbackStrictGroups(string $pattern, callable $re
187187
}, $subject, $limit, $count, $flags);
188188
}
189189
/**
190-
* @param array<string, callable(array<int|string, string|null>): string> $pattern
190+
* @param ($flags is PREG_OFFSET_CAPTURE ? (array<string, callable(array<int|string, array{string|null, int<-1, max>}>): string>) : array<string, callable(array<int|string, string|null>): string>) $pattern
191191
* @param string $subject
192192
* @param int $count Set by method
193193
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_OFFSET_CAPTURE is supported, PREG_UNMATCHED_AS_NULL is always set
@@ -256,7 +256,7 @@ public static function grep(string $pattern, array $array, int $flags = 0) : arr
256256
* Variant of match() which returns a bool instead of int
257257
*
258258
* @param non-empty-string $pattern
259-
* @param array<string|null> $matches Set by method
259+
* @param array<mixed> $matches Set by method
260260
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
261261
*
262262
* @param-out array<int|string, string|null> $matches
@@ -269,7 +269,7 @@ public static function isMatch(string $pattern, string $subject, ?array &$matche
269269
* Variant of `isMatch()` which outputs non-null matches (or throws)
270270
*
271271
* @param non-empty-string $pattern
272-
* @param array<string> $matches Set by method
272+
* @param array<mixed> $matches Set by method
273273
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
274274
* @throws UnexpectedNullMatchException
275275
*
@@ -283,7 +283,7 @@ public static function isMatchStrictGroups(string $pattern, string $subject, ?ar
283283
* Variant of matchAll() which returns a bool instead of int
284284
*
285285
* @param non-empty-string $pattern
286-
* @param array<int|string, list<string|null>> $matches Set by method
286+
* @param array<mixed> $matches Set by method
287287
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
288288
*
289289
* @param-out array<int|string, list<string|null>> $matches
@@ -296,7 +296,7 @@ public static function isMatchAll(string $pattern, string $subject, ?array &$mat
296296
* Variant of `isMatchAll()` which outputs non-null matches (or throws)
297297
*
298298
* @param non-empty-string $pattern
299-
* @param array<int|string, list<string>> $matches Set by method
299+
* @param array<mixed> $matches Set by method
300300
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
301301
*
302302
* @param-out array<int|string, list<string>> $matches
@@ -311,7 +311,7 @@ public static function isMatchAllStrictGroups(string $pattern, string $subject,
311311
* Runs preg_match with PREG_OFFSET_CAPTURE
312312
*
313313
* @param non-empty-string $pattern
314-
* @param array<int|string, array{string|null, int}> $matches Set by method
314+
* @param array<mixed> $matches Set by method
315315
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
316316
*
317317
* @param-out array<int|string, array{string|null, int<-1, max>}> $matches
@@ -326,7 +326,7 @@ public static function isMatchWithOffsets(string $pattern, string $subject, ?arr
326326
* Runs preg_match_all with PREG_OFFSET_CAPTURE
327327
*
328328
* @param non-empty-string $pattern
329-
* @param array<int|string, list<array{string|null, int}>> $matches Set by method
329+
* @param array<mixed> $matches Set by method
330330
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
331331
*
332332
* @param-out array<int|string, list<array{string|null, int<-1, max>}>> $matches
@@ -348,16 +348,17 @@ private static function checkSetOrder(int $flags) : void
348348
}
349349
}
350350
/**
351-
* @param array<int|string, string|null> $matches
351+
* @param array<int|string, string|null|array{string|null, int}> $matches
352352
* @return array<int|string, string>
353353
* @throws UnexpectedNullMatchException
354354
*/
355355
private static function enforceNonNullMatches(string $pattern, array $matches, string $variantMethod)
356356
{
357357
foreach ($matches as $group => $match) {
358-
if (null === $match) {
359-
throw new UnexpectedNullMatchException('Pattern "' . $pattern . '" had an unexpected unmatched group "' . $group . '", make sure the pattern always matches or use ' . $variantMethod . '() instead.');
358+
if (\is_string($match) || \is_array($match) && \is_string($match[0])) {
359+
continue;
360360
}
361+
throw new UnexpectedNullMatchException('Pattern "' . $pattern . '" had an unexpected unmatched group "' . $group . '", make sure the pattern always matches or use ' . $variantMethod . '() instead.');
361362
}
362363
/** @var array<string> */
363364
return $matches;

vendor/composer/pcre/src/Regex.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static function replace($pattern, $replacement, $subject, int $limit = -1
101101
}
102102
/**
103103
* @param string|string[] $pattern
104-
* @param callable(array<int|string, string|null>): string $replacement
104+
* @param ($flags is PREG_OFFSET_CAPTURE ? (callable(array<int|string, array{string|null, int<-1, max>}>): string) : callable(array<int|string, string|null>): string) $replacement
105105
* @param string $subject
106106
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_OFFSET_CAPTURE is supported, PREG_UNMATCHED_AS_NULL is always set
107107
*/
@@ -114,17 +114,17 @@ public static function replaceCallback($pattern, callable $replacement, $subject
114114
* Variant of `replaceCallback()` which outputs non-null matches (or throws)
115115
*
116116
* @param string $pattern
117-
* @param callable(array<int|string, string>): string $replacement
117+
* @param ($flags is PREG_OFFSET_CAPTURE ? (callable(array<int|string, array{string, int<0, max>}>): string) : callable(array<int|string, string>): string) $replacement
118118
* @param string $subject
119-
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_OFFSET_CAPTURE or PREG_UNMATCHED_AS_NULL, only available on PHP 7.4+
119+
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_OFFSET_CAPTURE is supported, PREG_UNMATCHED_AS_NULL is always set
120120
*/
121121
public static function replaceCallbackStrictGroups($pattern, callable $replacement, $subject, int $limit = -1, int $flags = 0) : ReplaceResult
122122
{
123123
$result = Preg::replaceCallbackStrictGroups($pattern, $replacement, $subject, $limit, $count, $flags);
124124
return new ReplaceResult($count, $result);
125125
}
126126
/**
127-
* @param array<string, callable(array<int|string, string|null>): string> $pattern
127+
* @param ($flags is PREG_OFFSET_CAPTURE ? (array<string, callable(array<int|string, array{string|null, int<-1, max>}>): string>) : array<string, callable(array<int|string, string|null>): string>) $pattern
128128
* @param string $subject
129129
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_OFFSET_CAPTURE is supported, PREG_UNMATCHED_AS_NULL is always set
130130
*/

0 commit comments

Comments
 (0)