Skip to content

Commit

Permalink
Updated Rector to commit 040b839e71ec558c83553bc1462924e96993f6f0
Browse files Browse the repository at this point in the history
rectorphp/rector-src@040b839 [Windows] Rework add windows support on tests CI (#5504)
  • Loading branch information
TomasVotruba committed Jan 28, 2024
1 parent e47a59a commit c155c9c
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 35 deletions.
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 = 'b107a16f98aecf2a5ff969e30ff48595daadc06d';
public const PACKAGE_VERSION = '040b839e71ec558c83553bc1462924e96993f6f0';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-01-28 10:48:07';
public const RELEASE_DATE = '2024-01-28 15:48:41';
/**
* @var int
*/
Expand Down
17 changes: 13 additions & 4 deletions src/BetterPhpDocParser/PhpDocParser/BetterPhpDocParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ final class BetterPhpDocParser extends PhpDocParser
private $privatesAccessor;
/**
* @var string
* @see https://regex101.com/r/JOKSmr/1
* @see https://regex101.com/r/JDzr0c/1
*/
private const MULTI_NEW_LINES_REGEX = '#(\\n\\r|\\n){2,}#';
private const NEW_LINE_REGEX = "#(?<new_line>\r\n|\n)#";
/**
* @var string
* @see https://regex101.com/r/JOKSmr/5
*/
private const MULTI_NEW_LINES_REGEX = '#(?<new_line>\\r\\n|\\n){2,}#';
/**
* @param PhpDocNodeDecoratorInterface[] $phpDocNodeDecorators
*/
Expand Down Expand Up @@ -112,12 +117,16 @@ public function parseTagValue(TokenIterator $tokenIterator, string $tag) : PhpDo
$phpDocTagValueNode = parent::parseTagValue($tokenIterator, $tag);
$endPosition = $tokenIterator->currentPosition();
if ($isPrecededByHorizontalWhitespace && \property_exists($phpDocTagValueNode, 'description')) {
$phpDocTagValueNode->description = \str_replace("\n", "\n * ", (string) $phpDocTagValueNode->description);
$phpDocTagValueNode->description = Strings::replace((string) $phpDocTagValueNode->description, self::NEW_LINE_REGEX, static function (array $match) : string {
return $match['new_line'] . ' * ';
});
}
$startAndEnd = new StartAndEnd($startPosition, $endPosition);
$phpDocTagValueNode->setAttribute(PhpDocAttributeKey::START_AND_END, $startAndEnd);
if ($phpDocTagValueNode instanceof GenericTagValueNode) {
$phpDocTagValueNode->value = Strings::replace($phpDocTagValueNode->value, self::MULTI_NEW_LINES_REGEX, "\n");
$phpDocTagValueNode->value = Strings::replace($phpDocTagValueNode->value, self::MULTI_NEW_LINES_REGEX, static function (array $match) {
return $match['new_line'];
});
}
return $phpDocTagValueNode;
}
Expand Down
11 changes: 9 additions & 2 deletions src/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ final class PhpDocInfoPrinter
* @var string Uses a hardcoded unix-newline since most codes use it (even on windows) - otherwise we would need to normalize newlines
*/
private const NEWLINE_WITH_ASTERISK = "\n" . ' *';
/**
* @var string
* @see https://regex101.com/r/ME5Fcn/1
*/
private const NEW_LINE_WITH_SPACE_REGEX = "# (?<new_line>\r\n|\n)#";
/**
* @var int
*/
Expand Down Expand Up @@ -174,7 +179,9 @@ private function printPhpDocNode(PhpDocNode $phpDocNode) : string
if (\strncmp($output, '/**', \strlen('/**')) === 0 && !StringUtils::isMatch($output, self::CLOSING_DOCBLOCK_REGEX)) {
$output .= ' */';
}
return \str_replace(" \n", "\n", $output);
return Strings::replace($output, self::NEW_LINE_WITH_SPACE_REGEX, static function (array $match) {
return $match['new_line'];
});
}
private function hasDocblockStart(string $output) : bool
{
Expand Down Expand Up @@ -238,7 +245,7 @@ private function addTokensFromTo(string $output, int $from, int $to, bool $shoul
--$from;
}
// skip extra empty lines above if this is the last one
if ($shouldSkipEmptyLinesAbove && \strpos((string) $this->tokens[$from][0], \PHP_EOL) !== \false && \strpos((string) $this->tokens[$from + 1][0], \PHP_EOL) !== \false) {
if ($shouldSkipEmptyLinesAbove && \strpos((string) $this->tokens[$from][0], "\n") !== \false && \strpos((string) $this->tokens[$from + 1][0], "\n") !== \false) {
++$from;
}
return $this->appendToOutput($output, $from, $to, $positionJumpSet);
Expand Down
2 changes: 1 addition & 1 deletion src/FileSystem/FilePathHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function normalizePathAndSchema(string $originalPath) : string
$pathParts = \explode('/', \trim($path, '/'));
$normalizedPathParts = $this->normalizePathParts($pathParts, $scheme);
$pathStart = $scheme !== self::SCHEME_UNDEFINED ? $scheme . '://' : '';
return $pathStart . $pathRoot . \implode($directorySeparator, $normalizedPathParts);
return $this->normalizePath($pathStart . $pathRoot . \implode($directorySeparator, $normalizedPathParts));
}
private function relativeFilePathFromDirectory(string $fileRealPath, string $directory) : string
{
Expand Down
7 changes: 4 additions & 3 deletions src/Skipper/FileSystem/FnMatchPathNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ public function normalizeForFnmatch(string $path) : string
return '*' . \trim($path, '*') . '*';
}
if (\strpos($path, '..') !== \false) {
/** @var string|false $path */
$path = \realpath($path);
if ($path === \false) {
/** @var string|false $realPath */
$realPath = \realpath($path);
if ($realPath === \false) {
return '';
}
return \Rector\Skipper\FileSystem\PathNormalizer::normalize($realPath);
}
return $path;
}
Expand Down
12 changes: 12 additions & 0 deletions src/Skipper/FileSystem/PathNormalizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare (strict_types=1);
namespace Rector\Skipper\FileSystem;

final class PathNormalizer
{
public static function normalize(string $path) : string
{
return \str_replace('\\', '/', $path);
}
}
10 changes: 2 additions & 8 deletions src/Skipper/Fnmatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@ final class Fnmatcher
{
public function match(string $matchingPath, string $filePath) : bool
{
$normalizedMatchingPath = $this->normalizePath($matchingPath);
$normalizedFilePath = $this->normalizePath($filePath);
if (\fnmatch($normalizedMatchingPath, $normalizedFilePath)) {
if (\fnmatch($matchingPath, $filePath)) {
return \true;
}
// in case of relative compare
return \fnmatch('*/' . $normalizedMatchingPath, $normalizedFilePath);
}
private function normalizePath(string $path) : string
{
return \str_replace('\\', '/', $path);
return \fnmatch('*/' . $matchingPath, $filePath);
}
}
5 changes: 4 additions & 1 deletion src/Skipper/Matcher/FileInfoMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Rector\Skipper\Matcher;

use Rector\Skipper\FileSystem\FnMatchPathNormalizer;
use Rector\Skipper\FileSystem\PathNormalizer;
use Rector\Skipper\Fnmatcher;
use Rector\Skipper\RealpathMatcher;
final class FileInfoMatcher
Expand Down Expand Up @@ -34,7 +35,9 @@ public function __construct(FnMatchPathNormalizer $fnMatchPathNormalizer, Fnmatc
*/
public function doesFileInfoMatchPatterns(string $filePath, array $filePatterns) : bool
{
$filePath = PathNormalizer::normalize($filePath);
foreach ($filePatterns as $filePattern) {
$filePattern = PathNormalizer::normalize($filePattern);
if ($this->doesFileMatchPattern($filePath, $filePattern)) {
return \true;
}
Expand All @@ -46,7 +49,7 @@ public function doesFileInfoMatchPatterns(string $filePath, array $filePatterns)
*/
private function doesFileMatchPattern(string $filePath, string $ignoredPath) : bool
{
// in ecs.php, the path can be absolute
// in rector.php, the path can be absolute
if ($filePath === $ignoredPath) {
return \true;
}
Expand Down
13 changes: 5 additions & 8 deletions src/Skipper/RealpathMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
declare (strict_types=1);
namespace Rector\Skipper;

use Rector\Skipper\FileSystem\PathNormalizer;
final class RealpathMatcher
{
public function match(string $matchingPath, string $filePath) : bool
{
/** @var string|false $realPathMatchingPath */
$realPathMatchingPath = \realpath($matchingPath);
if (!\is_string($realPathMatchingPath)) {
if ($realPathMatchingPath === \false) {
return \false;
}
/** @var string|false $realpathFilePath */
$realpathFilePath = \realpath($filePath);
if (!\is_string($realpathFilePath)) {
if ($realpathFilePath === \false) {
return \false;
}
$normalizedMatchingPath = $this->normalizePath($realPathMatchingPath);
$normalizedFilePath = $this->normalizePath($realpathFilePath);
$normalizedMatchingPath = PathNormalizer::normalize($realPathMatchingPath);
$normalizedFilePath = PathNormalizer::normalize($realpathFilePath);
// skip define direct path
if (\is_file($normalizedMatchingPath)) {
return $normalizedMatchingPath === $normalizedFilePath;
Expand All @@ -29,8 +30,4 @@ public function match(string $matchingPath, string $filePath) : bool
}
return \strncmp($normalizedFilePath, $normalizedMatchingPath, \strlen($normalizedMatchingPath)) === 0;
}
private function normalizePath(string $path) : string
{
return \str_replace('\\', '/', $path);
}
}
1 change: 0 additions & 1 deletion src/Skipper/Skipper/PathSkipper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function __construct(FileInfoMatcher $fileInfoMatcher, SkippedPathsResolv
}
public function shouldSkip(string $filePath) : bool
{
$filePath = \str_replace('\\', '/', $filePath);
$skippedPaths = $this->skippedPathsResolver->resolve();
return $this->fileInfoMatcher->doesFileInfoMatchPatterns($filePath, $skippedPaths);
}
Expand Down
7 changes: 2 additions & 5 deletions src/Testing/Fixture/FixtureSplitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ public static function split(string $filePath) : array
*/
public static function splitFixtureFileContents(string $fixtureFileContents) : array
{
$posixContents = \explode("-----\n", $fixtureFileContents);
if (isset($posixContents[1])) {
return $posixContents;
}
return \explode("-----\r\n", $fixtureFileContents);
$fixtureFileContents = \str_replace("\r\n", "\n", $fixtureFileContents);
return \explode("-----\n", $fixtureFileContents);
}
}
1 change: 1 addition & 0 deletions vendor/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,7 @@
'Rector\\Set\\ValueObject\\SetList' => $baseDir . '/src/Set/ValueObject/SetList.php',
'Rector\\Skipper\\Contract\\SkipVoterInterface' => $baseDir . '/src/Skipper/Contract/SkipVoterInterface.php',
'Rector\\Skipper\\FileSystem\\FnMatchPathNormalizer' => $baseDir . '/src/Skipper/FileSystem/FnMatchPathNormalizer.php',
'Rector\\Skipper\\FileSystem\\PathNormalizer' => $baseDir . '/src/Skipper/FileSystem/PathNormalizer.php',
'Rector\\Skipper\\Fnmatcher' => $baseDir . '/src/Skipper/Fnmatcher.php',
'Rector\\Skipper\\Matcher\\FileInfoMatcher' => $baseDir . '/src/Skipper/Matcher/FileInfoMatcher.php',
'Rector\\Skipper\\RealpathMatcher' => $baseDir . '/src/Skipper/RealpathMatcher.php',
Expand Down
1 change: 1 addition & 0 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,7 @@ class ComposerStaticInitf637847380e2ddf55dcae18dded1d2b3
'Rector\\Set\\ValueObject\\SetList' => __DIR__ . '/../..' . '/src/Set/ValueObject/SetList.php',
'Rector\\Skipper\\Contract\\SkipVoterInterface' => __DIR__ . '/../..' . '/src/Skipper/Contract/SkipVoterInterface.php',
'Rector\\Skipper\\FileSystem\\FnMatchPathNormalizer' => __DIR__ . '/../..' . '/src/Skipper/FileSystem/FnMatchPathNormalizer.php',
'Rector\\Skipper\\FileSystem\\PathNormalizer' => __DIR__ . '/../..' . '/src/Skipper/FileSystem/PathNormalizer.php',
'Rector\\Skipper\\Fnmatcher' => __DIR__ . '/../..' . '/src/Skipper/Fnmatcher.php',
'Rector\\Skipper\\Matcher\\FileInfoMatcher' => __DIR__ . '/../..' . '/src/Skipper/Matcher/FileInfoMatcher.php',
'Rector\\Skipper\\RealpathMatcher' => __DIR__ . '/../..' . '/src/Skipper/RealpathMatcher.php',
Expand Down

0 comments on commit c155c9c

Please sign in to comment.