Skip to content

Commit

Permalink
[CodeQuality] Skip windows absolute path on AbsolutizeRequireAndInclu…
Browse files Browse the repository at this point in the history
…dePathRector
  • Loading branch information
samsonasik committed Jan 20, 2025
1 parent 7ec3ae3 commit c3684df
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\Include_\AbsolutizeRequireAndIncludePathRector\Fixture;

final class SkipAbsolutePaths
{
public function run()
{
include "C:\\Users\\prj\\vendor\\autoload.php";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
*/
final class AbsolutizeRequireAndIncludePathRector extends AbstractRector
{
/**
* @var string
* @see https://regex101.com/r/spMHn4/1
*/
private const WINDOWS_DRIVE_REGEX = '#^[a-zA-z]+.*\:[\/\\\]#';

public function __construct(
private readonly ValueResolver $valueResolver
) {
Expand Down Expand Up @@ -105,6 +111,10 @@ public function refactor(Node $node): ?Node
return null;
}

if (Strings::match($includeValue, self::WINDOWS_DRIVE_REGEX)) {
return null;
}

// add preslash to string
$node->expr->value = \str_starts_with($includeValue, './') ? Strings::substring(
$includeValue,
Expand Down

0 comments on commit c3684df

Please sign in to comment.