Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ jobs:
dependencies:
- "locked"
php-version:
# Throws deprecated errors on 8.4
- "8.3"
- "8.4"
operating-system:
- "ubuntu-latest"

Expand Down Expand Up @@ -151,8 +150,7 @@ jobs:
dependencies:
- "locked"
php-version:
# Does not work on 8.4
- "8.3"
- "8.4"
operating-system:
- "ubuntu-latest"

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

],
"require-dev": {
"phpbench/phpbench": "^1.3.1",
"phpunit/phpunit": "^11.5.3"
"phpbench/phpbench": "^1.4.0",
"phpunit/phpunit": "^11.5.4"
},
"autoload": {
"psr-4": {
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/Reflection/Adapter/ReflectionMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function __construct(private BetterReflectionMethod $betterReflectionMeth
unset($this->class);
}

/** @psalm-suppress MethodSignatureMismatch */
public static function createFromMethodName(string $method): static
{
if (! str_contains($method, '::')) {
Expand Down
16 changes: 9 additions & 7 deletions src/Reflection/Adapter/ReflectionProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ public function isDynamic(): bool
return $this->betterReflectionProperty->isDynamic();
}

/** @psalm-mutation-free */
/**
* @return int-mask-of<self::IS_*>
*
* @psalm-mutation-free
*/
public function getModifiers(): int
{
return $this->betterReflectionProperty->getModifiers();
Expand Down Expand Up @@ -286,16 +290,14 @@ public function hasHooks(): bool
return $this->betterReflectionProperty->hasHooks();
}

/** @psalm-suppress UndefinedClass */
public function hasHook(PropertyHookType $hookType): bool
public function hasHook(PropertyHookType $type): bool
{
return $this->betterReflectionProperty->hasHook(BetterReflectionPropertyHookType::fromCoreReflectionPropertyHookType($hookType));
return $this->betterReflectionProperty->hasHook(BetterReflectionPropertyHookType::fromCoreReflectionPropertyHookType($type));
}

/** @psalm-suppress UndefinedClass */
public function getHook(PropertyHookType $hookType): ReflectionMethod|null
public function getHook(PropertyHookType $type): ReflectionMethod|null
{
$hook = $this->betterReflectionProperty->getHook(BetterReflectionPropertyHookType::fromCoreReflectionPropertyHookType($hookType));
$hook = $this->betterReflectionProperty->getHook(BetterReflectionPropertyHookType::fromCoreReflectionPropertyHookType($type));
if ($hook === null) {
return null;
}
Expand Down
1 change: 0 additions & 1 deletion src/Reflection/ReflectionPropertyHookType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ enum ReflectionPropertyHookType: string
case Get = 'get';
case Set = 'set';

/** @psalm-suppress UndefinedClass */
public static function fromCoreReflectionPropertyHookType(CoreReflectionPropertyHookType $hookType): self
{
/** @phpstan-ignore match.unhandled */
Expand Down
6 changes: 4 additions & 2 deletions src/Reflection/StringCast/ReflectionClassStringCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,11 @@ private static function methodsToString(array $methods, int $emptyLinesAmongItem
*/
private static function itemsToString(array $items, int $emptyLinesAmongItems = 1): string
{
$string = implode(str_repeat("\n", $emptyLinesAmongItems), $items);
$string = implode(str_repeat("\n", $emptyLinesAmongItems), $items);
$indentedString = preg_replace('/(^|\n)(?!\n)/', '\1' . self::indent(), $string);
assert($indentedString !== null);

return "\n" . preg_replace('/(^|\n)(?!\n)/', '\1' . self::indent(), $string);
return "\n" . $indentedString;
}

/** @psalm-pure */
Expand Down
6 changes: 5 additions & 1 deletion src/Reflection/StringCast/ReflectionStringCastHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Roave\BetterReflection\Reflection\ReflectionEnumCase;
use Roave\BetterReflection\Reflection\ReflectionProperty;

use function assert;
use function preg_replace;

/** @internal */
Expand All @@ -22,6 +23,9 @@ public static function docCommentToString(ReflectionProperty|ReflectionClassCons
return '';
}

return ($indent ? preg_replace('/(\n)(?!\n)/', '\1 ', $docComment) : $docComment) . "\n";
$indentedDocComment = $indent ? preg_replace('/(\n)(?!\n)/', '\1 ', $docComment) : $docComment;
assert($indentedDocComment !== null);

return $indentedDocComment . "\n";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,11 @@ private function parseFile(string $filePath): void
$absoluteFilePath = $this->getAbsoluteFilePath($filePath);
FileChecker::assertReadableFile($absoluteFilePath);

$fileContents = file_get_contents($absoluteFilePath);
assert($fileContents !== false);

/** @var list<Node\Stmt> $ast */
$ast = $this->phpParser->parse(file_get_contents($absoluteFilePath));
$ast = $this->phpParser->parse($fileContents);

// "@since" and "@removed" annotations in some cases do not contain a PHP version, but an extension version - e.g. "@since 1.3.0"
// So we check PHP version only for stubs of core extensions
Expand Down Expand Up @@ -664,6 +667,7 @@ private function addAnnotationToDocComment(
$docCommentText = sprintf('/** @%s */', $annotationName);
} else {
$docCommentText = preg_replace('~(\r?\n\s*)\*/~', sprintf('\1* @%s\1*/', $annotationName), $docComment->getText());
assert($docCommentText !== null);
}

$node->setDocComment(new Doc($docCommentText));
Expand All @@ -679,6 +683,8 @@ private function removeAnnotationFromDocComment(
}

$docCommentText = preg_replace('~@' . $annotationName . '.*$~m', '', $docComment->getText());
assert($docCommentText !== null);

$node->setDocComment(new Doc($docCommentText));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ private function addDocComment(
$docComment = sprintf("/**\n* %s\n*/", implode("\n *", $annotations));
} elseif ($annotations !== []) {
$docComment = preg_replace('~\s+\*/$~', sprintf("\n* %s\n*/", implode("\n *", $annotations)), $docComment);
assert($docComment !== null);
}

$node->setDocComment(new Doc($docComment));
Expand Down
2 changes: 2 additions & 0 deletions src/SourceLocator/Type/AnonymousClassObjectSourceLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public function getAnonymousClassNode(): Class_
};

$fileContents = file_get_contents($fileName);
assert($fileContents !== false);

/** @var list<Node\Stmt> $ast */
$ast = $this->parser->parse($fileContents);

Expand Down
12 changes: 9 additions & 3 deletions src/SourceLocator/Type/AutoloadSourceLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,20 @@
return null;
}

$fileContents = file_get_contents($locatedData['fileName']);
assert($fileContents !== false);

if (strtolower($identifier->getName()) !== strtolower($locatedData['name'])) {
return new AliasLocatedSource(
file_get_contents($locatedData['fileName']),
$fileContents,
$locatedData['name'],
$locatedData['fileName'],
$identifier->getName(),
);
}

return new LocatedSource(
file_get_contents($locatedData['fileName']),
$fileContents,
$identifier->getName(),
$locatedData['fileName'],
);
Expand Down Expand Up @@ -198,7 +201,7 @@

private function silenceErrors(): void
{
set_error_handler(static fn (): bool => true);

Check warning on line 204 in src/SourceLocator/Type/AutoloadSourceLocator.php

View workflow job for this annotation

GitHub Actions / Mutation tests (locked, 8.4, ubuntu-latest)

Escaped Mutant for Mutator "TrueValue": @@ @@ } private function silenceErrors(): void { - set_error_handler(static fn(): bool => true); + set_error_handler(static fn(): bool => false); } /** * We can only load functions if they already exist, because PHP does not
}

/**
Expand Down Expand Up @@ -266,8 +269,11 @@
continue;
}

$fileContents = file_get_contents($includedFileName);
assert($fileContents !== false);

/** @var list<Node\Stmt> $ast */
$ast = $this->phpParser->parse(file_get_contents($includedFileName));
$ast = $this->phpParser->parse($fileContents);

$this->nodeTraverser->traverse($ast);

Expand Down
2 changes: 2 additions & 0 deletions src/SourceLocator/Type/ClosureSourceLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public function getClosureNodes(): array
};

$fileContents = file_get_contents($fileName);
assert($fileContents !== false);

/** @var list<Node\Stmt> $ast */
$ast = $this->parser->parse($fileContents);

Expand Down
5 changes: 4 additions & 1 deletion src/SourceLocator/Type/Composer/PsrAutoloaderLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Roave\BetterReflection\SourceLocator\Type\DirectoriesSourceLocator;
use Roave\BetterReflection\SourceLocator\Type\SourceLocator;

use function assert;
use function file_get_contents;

final class PsrAutoloaderLocator implements SourceLocator
Expand All @@ -31,11 +32,13 @@ public function locateIdentifier(Reflector $reflector, Identifier $identifier):
foreach ($this->mapping->resolvePossibleFilePaths($identifier) as $file) {
try {
FileChecker::assertReadableFile($file);
$fileContents = file_get_contents($file);
assert($fileContents !== false);

return $this->astLocator->findReflection(
$reflector,
new LocatedSource(
file_get_contents($file),
$fileContents,
$identifier->getName(),
$file,
),
Expand Down
6 changes: 5 additions & 1 deletion src/SourceLocator/Type/ComposerSourceLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Roave\BetterReflection\SourceLocator\Exception\InvalidFileLocation;
use Roave\BetterReflection\SourceLocator\Located\LocatedSource;

use function assert;
use function file_get_contents;

/**
Expand Down Expand Up @@ -46,8 +47,11 @@ protected function createLocatedSource(Identifier $identifier): LocatedSource|nu
return null;
}

$fileContents = file_get_contents($filename);
assert($fileContents !== false);

return new LocatedSource(
file_get_contents($filename),
$fileContents,
$identifier->getName(),
$filename,
);
Expand Down
6 changes: 5 additions & 1 deletion src/SourceLocator/Type/SingleFileSourceLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Roave\BetterReflection\SourceLocator\FileChecker;
use Roave\BetterReflection\SourceLocator\Located\LocatedSource;

use function assert;
use function file_get_contents;

/**
Expand Down Expand Up @@ -43,8 +44,11 @@ public function __construct(private string $fileName, Locator $astLocator)
*/
protected function createLocatedSource(Identifier $identifier): LocatedSource|null
{
$fileContents = file_get_contents($this->fileName);
assert($fileContents !== false);

return new LocatedSource(
file_get_contents($this->fileName),
$fileContents,
$identifier->getName(),
$this->fileName,
);
Expand Down
6 changes: 3 additions & 3 deletions tools/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"doctrine/coding-standard": "^12.0.0",
"phpstan/phpstan": "^2.1.2",
"phpstan/phpstan-phpunit": "^2.0.4",
"vimeo/psalm": "^5.26.1",
"roave/backward-compatibility-check": "^8.10.0",
"roave/infection-static-analysis-plugin": "^1.35.0"
"vimeo/psalm": "^6.4.0",
"roave/backward-compatibility-check": "^8.13.0",
"roave/infection-static-analysis-plugin": "^1.36.0"
},
"config": {
"allow-plugins": {
Expand Down
Loading
Loading