diff --git a/packages/ChangesReporting/Output/ConsoleOutputFormatter.php b/packages/ChangesReporting/Output/ConsoleOutputFormatter.php index f07bd8c3507..178cd80ef68 100644 --- a/packages/ChangesReporting/Output/ConsoleOutputFormatter.php +++ b/packages/ChangesReporting/Output/ConsoleOutputFormatter.php @@ -72,6 +72,13 @@ private function reportFileDiffs(array $fileDiffs): void $i = 0; foreach ($fileDiffs as $fileDiff) { $relativeFilePath = $fileDiff->getRelativeFilePath(); + + // append line number for faster file jump in diff + $firstLineNumber = $fileDiff->getFirstLineNumber(); + if ($firstLineNumber !== null) { + $relativeFilePath .= ':' . $firstLineNumber; + } + $message = sprintf('%d) %s', ++$i, $relativeFilePath); $this->outputStyle->writeln($message); diff --git a/packages/PHPStanStaticTypeMapper/TypeAnalyzer/UnionTypeAnalyzer.php b/packages/PHPStanStaticTypeMapper/TypeAnalyzer/UnionTypeAnalyzer.php index b628d04c81b..7d09cb31767 100644 --- a/packages/PHPStanStaticTypeMapper/TypeAnalyzer/UnionTypeAnalyzer.php +++ b/packages/PHPStanStaticTypeMapper/TypeAnalyzer/UnionTypeAnalyzer.php @@ -103,7 +103,7 @@ public function isScalar(UnionType $unionType): bool } foreach ($types as $type) { - if ($type instanceof StringType && !$type instanceof ConstantStringType) { + if ($type instanceof StringType && ! $type instanceof ConstantStringType) { continue; } if ($type instanceof FloatType) { diff --git a/rules/DowngradePhp72/NodeAnalyzer/BuiltInMethodAnalyzer.php b/rules/DowngradePhp72/NodeAnalyzer/BuiltInMethodAnalyzer.php index ae2416dca90..273cf56005c 100644 --- a/rules/DowngradePhp72/NodeAnalyzer/BuiltInMethodAnalyzer.php +++ b/rules/DowngradePhp72/NodeAnalyzer/BuiltInMethodAnalyzer.php @@ -11,8 +11,10 @@ final class BuiltInMethodAnalyzer { - public function __construct(private NodeNameResolver $nodeNameResolver, private ClassChildAnalyzer $classChildAnalyzer) - { + public function __construct( + private NodeNameResolver $nodeNameResolver, + private ClassChildAnalyzer $classChildAnalyzer + ) { } public function isImplementsBuiltInInterface(ClassReflection $classReflection, ClassMethod $classMethod): bool diff --git a/src/ValueObject/Reporting/FileDiff.php b/src/ValueObject/Reporting/FileDiff.php index bac5a5b5cec..d56055fafbe 100644 --- a/src/ValueObject/Reporting/FileDiff.php +++ b/src/ValueObject/Reporting/FileDiff.php @@ -4,12 +4,24 @@ namespace Rector\Core\ValueObject\Reporting; +use Nette\Utils\Strings; use Rector\ChangesReporting\ValueObject\RectorWithLineChange; use Rector\Core\Contract\Rector\RectorInterface; use Symplify\SmartFileSystem\SmartFileInfo; final class FileDiff { + /** + * @var string + * @se https://regex101.com/r/AUPIX4/1 + */ + private const FIRST_LINE_REGEX = '#@@(.*?)(?<' . self::FIRST_LINE_KEY . '>\d+)(.*?)@@#'; + + /** + * @var string + */ + private const FIRST_LINE_KEY = 'first_line'; + /** * @param RectorWithLineChange[] $rectorWithLineChanges */ @@ -62,6 +74,18 @@ public function getRectorClasses(): array return $this->sortClasses($rectorClasses); } + public function getFirstLineNumber(): ?int + { + $match = Strings::match($this->diff, self::FIRST_LINE_REGEX); + + // probably some error in diff + if (! isset($match[self::FIRST_LINE_KEY])) { + return null; + } + + return (int) $match[self::FIRST_LINE_KEY] - 1; + } + /** * @template TType as object * @param array> $rectorClasses