mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit dea2e16665cf567c20664c7ef9bac38d0d7d4f49
dea2e16665
[PHP 8.0] Fix case insenstive false positive replacement for str_ends_with (#5677)
This commit is contained in:
parent
991980cf2b
commit
d31429d029
|
@ -163,12 +163,18 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
$substrCompareFuncCall = $funcCallAndExpr->getFuncCall();
|
||||
if (\count($substrCompareFuncCall->getArgs()) < 2) {
|
||||
$args = $substrCompareFuncCall->getArgs();
|
||||
if (\count($args) < 2) {
|
||||
return null;
|
||||
}
|
||||
$haystack = $args[0]->value;
|
||||
$needle = $args[1]->value;
|
||||
$thirdArgValue = $args[2]->value;
|
||||
$isCaseInsensitiveValue = isset($args[4]) ? $this->valueResolver->getValue($args[4]->value) : null;
|
||||
// is case insensitive → not valid replacement
|
||||
if ($isCaseInsensitiveValue === \true) {
|
||||
return null;
|
||||
}
|
||||
$haystack = $substrCompareFuncCall->getArgs()[0]->value;
|
||||
$needle = $substrCompareFuncCall->getArgs()[1]->value;
|
||||
$thirdArgValue = $substrCompareFuncCall->getArgs()[2]->value;
|
||||
if (!$this->isUnaryMinusStrlenFuncCallArgValue($thirdArgValue, $needle) && !$this->isHardCodedLNumberAndString($thirdArgValue, $needle)) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '7191fae140cc8c35a699b6487117e1efa8b4d2f5';
|
||||
public const PACKAGE_VERSION = 'dea2e16665cf567c20664c7ef9bac38d0d7d4f49';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-03-01 20:04:35';
|
||||
public const RELEASE_DATE = '2024-03-02 13:06:24';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -1928,17 +1928,17 @@
|
|||
},
|
||||
{
|
||||
"name": "sebastian\/diff",
|
||||
"version": "5.1.0",
|
||||
"version_normalized": "5.1.0.0",
|
||||
"version": "5.1.1",
|
||||
"version_normalized": "5.1.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/sebastianbergmann\/diff.git",
|
||||
"reference": "fbf413a49e54f6b9b17e12d900ac7f6101591b7f"
|
||||
"reference": "c41e007b4b62af48218231d6c2275e4c9b975b2e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/sebastianbergmann\/diff\/zipball\/fbf413a49e54f6b9b17e12d900ac7f6101591b7f",
|
||||
"reference": "fbf413a49e54f6b9b17e12d900ac7f6101591b7f",
|
||||
"url": "https:\/\/api.github.com\/repos\/sebastianbergmann\/diff\/zipball\/c41e007b4b62af48218231d6c2275e4c9b975b2e",
|
||||
"reference": "c41e007b4b62af48218231d6c2275e4c9b975b2e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1946,9 +1946,9 @@
|
|||
},
|
||||
"require-dev": {
|
||||
"phpunit\/phpunit": "^10.0",
|
||||
"symfony\/process": "^4.2 || ^5"
|
||||
"symfony\/process": "^6.4"
|
||||
},
|
||||
"time": "2023-12-22T10:55:06+00:00",
|
||||
"time": "2024-03-02T07:15:17+00:00",
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
|
@ -1986,7 +1986,7 @@
|
|||
"support": {
|
||||
"issues": "https:\/\/github.com\/sebastianbergmann\/diff\/issues",
|
||||
"security": "https:\/\/github.com\/sebastianbergmann\/diff\/security\/policy",
|
||||
"source": "https:\/\/github.com\/sebastianbergmann\/diff\/tree\/5.1.0"
|
||||
"source": "https:\/\/github.com\/sebastianbergmann\/diff\/tree\/5.1.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2,6 +2,12 @@
|
|||
|
||||
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
|
||||
|
||||
## [5.1.1] - 2024-03-02
|
||||
|
||||
### Changed
|
||||
|
||||
* Do not use implicitly nullable parameters
|
||||
|
||||
## [5.1.0] - 2023-12-22
|
||||
|
||||
### Added
|
||||
|
@ -124,6 +130,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
|
|||
|
||||
* This component is no longer supported on PHP 5.6
|
||||
|
||||
[5.1.1]: https://github.com/sebastianbergmann/diff/compare/5.1.0...5.1.1
|
||||
[5.1.0]: https://github.com/sebastianbergmann/diff/compare/5.0.3...5.1.0
|
||||
[5.0.3]: https://github.com/sebastianbergmann/diff/compare/5.0.2...5.0.3
|
||||
[5.0.2]: https://github.com/sebastianbergmann/diff/compare/5.0.1...5.0.2
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2002-2023, Sebastian Bergmann
|
||||
Copyright (c) 2002-2024, Sebastian Bergmann
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
},
|
||||
"require-dev": {
|
||||
"phpunit\/phpunit": "^10.0",
|
||||
"symfony\/process": "^4.2 || ^5"
|
||||
"symfony\/process": "^6.4"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
|
|
|
@ -48,7 +48,7 @@ final class Differ
|
|||
* @param mixed[]|string $from
|
||||
* @param mixed[]|string $to
|
||||
*/
|
||||
public function diff($from, $to, LongestCommonSubsequenceCalculator $lcs = null) : string
|
||||
public function diff($from, $to, ?LongestCommonSubsequenceCalculator $lcs = null) : string
|
||||
{
|
||||
$diff = $this->diffToArray($from, $to, $lcs);
|
||||
return $this->outputBuilder->getDiff($diff);
|
||||
|
@ -57,7 +57,7 @@ final class Differ
|
|||
* @param mixed[]|string $from
|
||||
* @param mixed[]|string $to
|
||||
*/
|
||||
public function diffToArray($from, $to, LongestCommonSubsequenceCalculator $lcs = null) : array
|
||||
public function diffToArray($from, $to, ?LongestCommonSubsequenceCalculator $lcs = null) : array
|
||||
{
|
||||
if (is_string($from)) {
|
||||
$from = $this->splitStringByLines($from);
|
||||
|
|
|
@ -17,7 +17,7 @@ use function sprintf;
|
|||
use Exception;
|
||||
final class ConfigurationException extends InvalidArgumentException
|
||||
{
|
||||
public function __construct(string $option, string $expected, $value, int $code = 0, Exception $previous = null)
|
||||
public function __construct(string $option, string $expected, $value, int $code = 0, ?Exception $previous = null)
|
||||
{
|
||||
parent::__construct(sprintf('Option "%s" must be %s, got "%s".', $option, $expected, is_object($value) ? \get_class($value) : (null === $value ? '<null>' : gettype($value) . '#' . $value)), $code, $previous);
|
||||
}
|
||||
|
|
|
@ -65,7 +65,11 @@ final class MemoryEfficientLongestCommonSubsequenceCalculator implements Longest
|
|||
if ($from[$i] === $to[$j]) {
|
||||
$current[$j + 1] = $prev[$j] + 1;
|
||||
} else {
|
||||
// don't use max() to avoid function call overhead
|
||||
/**
|
||||
* @noinspection PhpConditionCanBeReplacedWithMinMaxCallInspection
|
||||
*
|
||||
* We do not use max() here to avoid the function call overhead
|
||||
*/
|
||||
if ($current[$j] > $prev[$j + 1]) {
|
||||
$current[$j + 1] = $current[$j];
|
||||
} else {
|
||||
|
|
|
@ -230,11 +230,11 @@ final class StrictUnifiedDiffOutputBuilder implements DiffOutputBuilderInterface
|
|||
$this->changed = \true;
|
||||
fwrite($output, $diff[$i][0]);
|
||||
}
|
||||
//} elseif ($diff[$i][1] === Differ::DIFF_LINE_END_WARNING) { // custom comment inserted by PHPUnit/diff package
|
||||
// } elseif ($diff[$i][1] === Differ::DIFF_LINE_END_WARNING) { // custom comment inserted by PHPUnit/diff package
|
||||
// skip
|
||||
//} else {
|
||||
// } else {
|
||||
// unknown/invalid
|
||||
//}
|
||||
// }
|
||||
}
|
||||
}
|
||||
private function assertString(array $options, string $option) : void
|
||||
|
|
|
@ -20,7 +20,6 @@ use function max;
|
|||
use function min;
|
||||
use function str_ends_with;
|
||||
use function stream_get_contents;
|
||||
use function strlen;
|
||||
use function substr;
|
||||
use RectorPrefix202403\SebastianBergmann\Diff\Differ;
|
||||
/**
|
||||
|
@ -59,7 +58,7 @@ final class UnifiedDiffOutputBuilder extends AbstractChunkOutputBuilder
|
|||
$buffer = fopen('php://memory', 'r+b');
|
||||
if ('' !== $this->header) {
|
||||
fwrite($buffer, $this->header);
|
||||
if (\substr_compare($this->header, "\n", -strlen("\n")) !== 0) {
|
||||
if (\substr_compare($this->header, "\n", -\strlen("\n")) !== 0) {
|
||||
fwrite($buffer, "\n");
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +70,7 @@ final class UnifiedDiffOutputBuilder extends AbstractChunkOutputBuilder
|
|||
// If the diff is non-empty and last char is not a linebreak: add it.
|
||||
// This might happen when both the `from` and `to` do not have a trailing linebreak
|
||||
$last = substr($diff, -1);
|
||||
return 0 !== strlen($diff) && "\n" !== $last && "\r" !== $last ? $diff . "\n" : $diff;
|
||||
return '' !== $diff && "\n" !== $last && "\r" !== $last ? $diff . "\n" : $diff;
|
||||
}
|
||||
private function writeDiffHunks($output, array $diff) : void
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue