-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…hs-to-prevent-__DIR__-and-__FILE__-bc-break-false-positives Normalize `__DIR__` and `__FILE__` by changing the base path of `LocatedSource` instances, prevent false-positive BC breaks on those magic constants
- Loading branch information
Showing
8 changed files
with
432 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/SourceLocator/LocatedSourceWithStrippedSourcesDirectory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Roave\BackwardCompatibility\SourceLocator; | ||
|
||
use Roave\BetterReflection\SourceLocator\Located\LocatedSource; | ||
|
||
use function str_starts_with; | ||
use function strlen; | ||
use function substr_replace; | ||
|
||
/** @internal */ | ||
final class LocatedSourceWithStrippedSourcesDirectory extends LocatedSource | ||
{ | ||
public function __construct( | ||
private LocatedSource $next, | ||
private string $sourcesDirectory | ||
) { | ||
} | ||
|
||
public function getSource(): string | ||
{ | ||
return $this->next->getSource(); | ||
} | ||
|
||
public function getName(): ?string | ||
{ | ||
return $this->next->getName(); | ||
} | ||
|
||
public function getFileName(): ?string | ||
{ | ||
$fileName = $this->next->getFileName(); | ||
|
||
if ($fileName === null || ! str_starts_with($fileName, $this->sourcesDirectory)) { | ||
return $fileName; | ||
} | ||
|
||
return substr_replace($fileName, '', 0, strlen($this->sourcesDirectory)); | ||
} | ||
|
||
public function isInternal(): bool | ||
{ | ||
return $this->next->isInternal(); | ||
} | ||
|
||
public function getExtensionName(): ?string | ||
{ | ||
return $this->next->getExtensionName(); | ||
} | ||
|
||
public function isEvaled(): bool | ||
{ | ||
return $this->next->isEvaled(); | ||
} | ||
|
||
public function getAliasName(): ?string | ||
{ | ||
return $this->next->getAliasName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Roave\BackwardCompatibility\SourceLocator; | ||
|
||
use Roave\BetterReflection\Identifier\Identifier; | ||
use Roave\BetterReflection\Identifier\IdentifierType; | ||
use Roave\BetterReflection\Reflection\Reflection; | ||
use Roave\BetterReflection\Reflector\Reflector; | ||
use Roave\BetterReflection\SourceLocator\Ast\Locator; | ||
use Roave\BetterReflection\SourceLocator\Located\LocatedSource; | ||
|
||
/** @internal */ | ||
final class ReplaceSourcePathOfLocatedSources extends Locator | ||
{ | ||
public function __construct( | ||
private Locator $next, | ||
private string $sourcesDirectory | ||
) { | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
public function findReflection( | ||
Reflector $reflector, | ||
LocatedSource $locatedSource, | ||
Identifier $identifier, | ||
): Reflection { | ||
return $this->next->findReflection( | ||
$reflector, | ||
new LocatedSourceWithStrippedSourcesDirectory($locatedSource, $this->sourcesDirectory), | ||
$identifier | ||
); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
public function findReflectionsOfType( | ||
Reflector $reflector, | ||
LocatedSource $locatedSource, | ||
IdentifierType $identifierType, | ||
): array { | ||
return $this->next->findReflectionsOfType( | ||
$reflector, | ||
new LocatedSourceWithStrippedSourcesDirectory($locatedSource, $this->sourcesDirectory), | ||
$identifierType | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.