Skip to content

Commit

Permalink
Make relativeFilePathFromDirectory() private as used only locally (#4735
Browse files Browse the repository at this point in the history
)
  • Loading branch information
TomasVotruba committed Aug 9, 2023
1 parent 6b84177 commit 31ad417
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/FileSystem/FilePathHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,6 @@ public function relativePath(string $fileRealPath): string
return $this->relativeFilePathFromDirectory($fileRealPath, getcwd());
}

/**
* @api
*/
public function relativeFilePathFromDirectory(string $fileRealPath, string $directory): string
{
Assert::directory($directory);

$normalizedFileRealPath = $this->normalizePath($fileRealPath);

$relativeFilePath = $this->filesystem->makePathRelative($normalizedFileRealPath, $directory);

return rtrim($relativeFilePath, '/');
}

/**
* Used from
* https://github.com/phpstan/phpstan-src/blob/02425e61aa48f0668b4efb3e73d52ad544048f65/src/File/FileHelper.php#L40, with custom modifications
Expand Down Expand Up @@ -86,6 +72,15 @@ public function normalizePathAndSchema(string $originalPath): string
return $pathStart . $pathRoot . implode($directorySeparator, $normalizedPathParts);
}

private function relativeFilePathFromDirectory(string $fileRealPath, string $directory): string
{
Assert::directory($directory);
$normalizedFileRealPath = $this->normalizePath($fileRealPath);

$relativeFilePath = $this->filesystem->makePathRelative($normalizedFileRealPath, $directory);
return rtrim($relativeFilePath, '/');
}

private function normalizePath(string $filePath): string
{
return \str_replace('\\', '/', $filePath);
Expand Down
11 changes: 11 additions & 0 deletions src/PhpParser/NodeTraverser/RectorNodeTraverser.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ public function traverse(array $nodes): array
return parent::traverse($nodes);
}

/**
* @api used in tests to update the active rules
* @param PhpRectorInterface[] $phpRectors
*/
public function refreshPhpRectors(array $phpRectors): void
{
$this->phpRectors = $phpRectors;
$this->visitors = [];
$this->areNodeVisitorsPrepared = false;
}

/**
* This must happen after $this->configuration is set after ProcessCommand::execute() is run,
* otherwise we get default false positives.
Expand Down

0 comments on commit 31ad417

Please sign in to comment.