Skip to content

Commit

Permalink
Updated Rector to commit dea2e16665cf567c20664c7ef9bac38d0d7d4f49
Browse files Browse the repository at this point in the history
rectorphp/rector-src@dea2e16 [PHP 8.0] Fix case insenstive false positive replacement for str_ends_with (#5677)
  • Loading branch information
TomasVotruba committed Mar 2, 2024
1 parent 991980c commit d31429d
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 27 deletions.
14 changes: 10 additions & 4 deletions rules/Php80/Rector/Identical/StrEndsWithRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,18 @@ private function refactorSubstrCompare(BinaryOp $binaryOp)
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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
16 changes: 8 additions & 8 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -1928,27 +1928,27 @@
},
{
"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": {
"php": ">=8.1"
},
"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": {
Expand Down Expand Up @@ -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": [
{
Expand Down
2 changes: 1 addition & 1 deletion vendor/composer/installed.php

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions vendor/sebastian/diff/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vendor/sebastian/diff/LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion vendor/sebastian/diff/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"require-dev": {
"phpunit\/phpunit": "^10.0",
"symfony\/process": "^4.2 || ^5"
"symfony\/process": "^6.4"
},
"autoload": {
"classmap": [
Expand Down
4 changes: 2 additions & 2 deletions vendor/sebastian/diff/src/Differ.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(DiffOutputBuilderInterface $outputBuilder)
* @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);
Expand All @@ -57,7 +57,7 @@ public function diff($from, $to, LongestCommonSubsequenceCalculator $lcs = null)
* @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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ private function length(array $from, array $to) : array
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ private function writeHunk(array $diff, int $diffStartIndex, int $diffEndIndex,
$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
Expand Down
5 changes: 2 additions & 3 deletions vendor/sebastian/diff/src/Output/UnifiedDiffOutputBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use function min;
use function str_ends_with;
use function stream_get_contents;
use function strlen;
use function substr;
use RectorPrefix202403\SebastianBergmann\Diff\Differ;
/**
Expand Down Expand Up @@ -59,7 +58,7 @@ public function getDiff(array $diff) : string
$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");
}
}
Expand All @@ -71,7 +70,7 @@ public function getDiff(array $diff) : string
// 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
{
Expand Down

0 comments on commit d31429d

Please sign in to comment.