Skip to content
Open
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
525 changes: 525 additions & 0 deletions build/PHPStan/Build/MissingNativeTypeRule.php

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ rules:
- PHPStan\Build\MemoizationPropertyRule
- PHPStan\Build\OrChainIdenticalComparisonToInArrayRule
- PHPStan\Build\NoPhpVersionInjectionInScopeAwareExtensionRule
- PHPStan\Build\MissingNativeTypeRule

services:
-
Expand Down
23 changes: 5 additions & 18 deletions src/Analyser/ArgumentsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ public function __construct(
}

/**
* @param MethodReflection|FunctionReflection|null $calleeReflection
* @param ParametersAcceptor[] $parametersAcceptors
* @param ParametersAcceptor[]|null $namedArgumentsVariants
* @param callable(Node $node, Scope $scope): void $nodeCallback
Expand All @@ -135,7 +134,7 @@ public function __construct(
public function processArgs(
NodeScopeResolver $nodeScopeResolver,
Node\Stmt $stmt,
$calleeReflection,
MethodReflection|FunctionReflection|null $calleeReflection,
?ExtendedMethodReflection $nakedMethodReflection,
array $parametersAcceptors,
?array $namedArgumentsVariants,
Expand Down Expand Up @@ -1096,10 +1095,7 @@ public function processDroppedArgs(
}
}

/**
* @param MethodReflection|FunctionReflection|null $calleeReflection
*/
private function callCallbackImmediately(?ParameterReflection $parameter, ?Type $parameterType, $calleeReflection): bool
private function callCallbackImmediately(?ParameterReflection $parameter, ?Type $parameterType, MethodReflection|FunctionReflection|null $calleeReflection): bool
{
$parameterCallableType = null;
if ($parameterType !== null && $calleeReflection instanceof FunctionReflection) {
Expand Down Expand Up @@ -1135,10 +1131,7 @@ private function shouldInvalidateCallbackExpressions(?ParameterReflection $param
return true;
}

/**
* @param MethodReflection|FunctionReflection|null $calleeReflection
*/
private function getParameterTypeFromParameterClosureTypeExtension(CallLike $callLike, $calleeReflection, ParameterReflection $parameter, MutatingScope $scope): ?Type
private function getParameterTypeFromParameterClosureTypeExtension(CallLike $callLike, MethodReflection|FunctionReflection|null $calleeReflection, ParameterReflection $parameter, MutatingScope $scope): ?Type
{
if ($callLike instanceof FuncCall && $calleeReflection instanceof FunctionReflection) {
foreach ($this->functionParameterClosureTypeExtensions->getAll() as $functionParameterClosureTypeExtension) {
Expand Down Expand Up @@ -1176,10 +1169,7 @@ private function getParameterTypeFromParameterClosureTypeExtension(CallLike $cal
return null;
}

/**
* @param MethodReflection|FunctionReflection|null $calleeReflection
*/
private function getParameterOutExtensionsType(CallLike $callLike, $calleeReflection, ParameterReflection $currentParameter, MutatingScope $scope): ?Type
private function getParameterOutExtensionsType(CallLike $callLike, MethodReflection|FunctionReflection|null $calleeReflection, ParameterReflection $currentParameter, MutatingScope $scope): ?Type
{
$paramOutTypes = [];
if ($callLike instanceof FuncCall && $calleeReflection instanceof FunctionReflection) {
Expand Down Expand Up @@ -1231,12 +1221,9 @@ private function getParameterOutExtensionsType(CallLike $callLike, $calleeReflec
return null;
}

/**
* @param FunctionReflection|MethodReflection|null $calleeReflection
*/
private function resolveClosureThisType(
?CallLike $call,
$calleeReflection,
FunctionReflection|MethodReflection|null $calleeReflection,
ParameterReflection $parameter,
MutatingScope $scope,
): ?Type
Expand Down
2 changes: 1 addition & 1 deletion src/Analyser/CalledMethodProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function clearCalledMethodResults(): void
* @param Node[]|Node|scalar|null $node
* @param callable(Node $node, Scope $scope): void $nodeCallback
*/
private function processNodesForCalledMethod(NodeScopeResolver $nodeScopeResolver, $node, ExpressionResultStorage $storage, string $fileName, MethodReflection $methodReflection, callable $nodeCallback): void
private function processNodesForCalledMethod(NodeScopeResolver $nodeScopeResolver, Node|int|float|string|bool|array|null $node, ExpressionResultStorage $storage, string $fileName, MethodReflection $methodReflection, callable $nodeCallback): void
{
if ($node instanceof Node) {
$declaringClass = $methodReflection->getDeclaringClass();
Expand Down
5 changes: 1 addition & 4 deletions src/Analyser/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,9 @@ private function renameFixedFile(string $oldFile, string $newFile): array
);
}

/**
* @return mixed
*/
#[ReturnTypeWillChange]
#[Override]
public function jsonSerialize()
public function jsonSerialize(): mixed
{
return [
'message' => $this->message,
Expand Down
2 changes: 1 addition & 1 deletion src/Analyser/Ignore/IgnoredError.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function getIgnoredErrorLabel(array|string $ignoredError): string
* @param mixed[]|string $ignoredError
* @return string Representation of the ignored error
*/
public static function stringifyPattern($ignoredError): string
public static function stringifyPattern(string|array $ignoredError): string
{
if (!is_array($ignoredError)) {
return $ignoredError;
Expand Down
5 changes: 1 addition & 4 deletions src/Analyser/ImpurePoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ public function getScope(): Scope
return $this->scope;
}

/**
* @return Node\Expr|Node\Stmt|VirtualNode
*/
public function getNode()
public function getNode(): Node\Expr|Node\Stmt|VirtualNode
{
return $this->node;
}
Expand Down
5 changes: 1 addition & 4 deletions src/Analyser/InternalError.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,9 @@ public static function decode(array $json): self
return new self($json['message'], $json['contextDescription'], $json['trace'], $json['traceAsString'], $json['shouldReportBug']);
}

/**
* @return mixed
*/
#[ReturnTypeWillChange]
#[Override]
public function jsonSerialize()
public function jsonSerialize(): mixed
{
return [
'message' => $this->message,
Expand Down
5 changes: 1 addition & 4 deletions src/Analyser/InternalThrowPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ public function getType(): Type
return $this->type;
}

/**
* @return Node\Expr|Node\Stmt
*/
public function getNode()
public function getNode(): Node\Expr|Node\Stmt
{
return $this->node;
}
Expand Down
5 changes: 1 addition & 4 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -1716,10 +1716,7 @@ public function getTrackedExpressionType(Expr $node): Type
return $this->expressionTypes[$this->getNodeKey($node)]->getType();
}

/**
* @param MethodReflection|FunctionReflection|null $reflection
*/
public function pushInFunctionCall($reflection, ?ParameterReflection $parameter, bool $rememberTypes): self
public function pushInFunctionCall(MethodReflection|FunctionReflection|null $reflection, ?ParameterReflection $parameter, bool $rememberTypes): self
{
$stack = $this->inFunctionCallsStack;
$stack[] = [$reflection, $parameter];
Expand Down
5 changes: 1 addition & 4 deletions src/Analyser/NodeCallbackScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,7 @@ private function preprocessScope(MutatingScope $scope): Scope
return $scope;
}

/**
* @param MethodReflection|FunctionReflection|null $reflection
*/
public function pushInFunctionCall($reflection, ?ParameterReflection $parameter, bool $rememberTypes): self
public function pushInFunctionCall(MethodReflection|FunctionReflection|null $reflection, ?ParameterReflection $parameter, bool $rememberTypes): self
{
/** @var self $scope */
$scope = parent::pushInFunctionCall($reflection, $parameter, $rememberTypes);
Expand Down
6 changes: 2 additions & 4 deletions src/Analyser/ResultCache/ResultCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1853,10 +1853,9 @@ private function encodeValueDependencies(array $valueDependencies, ResultCachePa
}

/**
* @param mixed $encoded
* @return list<array{extensionClass: string, storedKey: string, value: string, analysis: list<string>, declarations: list<string>}>
*/
private function decodeValueDependencies($encoded, ResultCachePathTransformer $transformer): array
private function decodeValueDependencies(mixed $encoded, ResultCachePathTransformer $transformer): array
{
if (!is_array($encoded) || !is_array($encoded['paths'] ?? null) || !is_array($encoded['entries'] ?? null)) {
throw new RuntimeException('The value dependencies are malformed.');
Expand Down Expand Up @@ -2326,10 +2325,9 @@ private function encodeDependencyGraph(array $invertedDependencies, ResultCacheP
}

/**
* @param mixed $dependencyGraph
* @return array<string, array{fileHash: string, fileStat?: string, dependentFiles: list<string>, usedTraitDependentFiles?: list<string>}>
*/
private function decodeDependencyGraph($dependencyGraph, ResultCachePathTransformer $transformer): array
private function decodeDependencyGraph(mixed $dependencyGraph, ResultCachePathTransformer $transformer): array
{
if (!is_array($dependencyGraph) || !is_array($dependencyGraph['paths'] ?? null) || !is_array($dependencyGraph['entries'] ?? null)) {
throw new RuntimeException('The dependency graph is malformed.');
Expand Down
2 changes: 1 addition & 1 deletion src/Analyser/StmtHandler/TraitUseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private function processTraitUse(NodeScopeResolver $nodeScopeResolver, Node\Stmt
* @param callable(Node $node, Scope $scope): void $nodeCallback
* @param list<Dependencies|null> $dependencies what the walked trait statements depend on
*/
private function processNodesForTraitUse(NodeScopeResolver $nodeScopeResolver, $node, ClassReflection $traitReflection, MutatingScope $scope, ExpressionResultStorage $storage, array $adaptations, callable $nodeCallback, array &$dependencies): void
private function processNodesForTraitUse(NodeScopeResolver $nodeScopeResolver, Node|int|float|string|bool|array|null $node, ClassReflection $traitReflection, MutatingScope $scope, ExpressionResultStorage $storage, array $adaptations, callable $nodeCallback, array &$dependencies): void
{
if ($node instanceof Node) {
if ($node instanceof Node\Stmt\Trait_ && $traitReflection->getName() === (string) $node->namespacedName && $traitReflection->getNativeReflection()->getStartLine() === $node->getStartLine()) {
Expand Down
5 changes: 1 addition & 4 deletions src/Analyser/ThrowPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ public function getType(): Type
return $this->type;
}

/**
* @return Node\Expr|Node\Stmt
*/
public function getNode()
public function getNode(): Node\Expr|Node\Stmt
{
return $this->node;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Analyser/VariableFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ public static function arrow(ArrowFunction $arrow, ?self $body, ?self $outputs):
return new VariableControlFlow(self::ARROW, [$body, $outputs], arrow: $arrow);
}

/** @param int|string|null $offset */
public static function read(string $name, ?int $targetId = null, bool $container = false, $offset = null): ?self
public static function read(string $name, ?int $targetId = null, bool $container = false, int|string|null $offset = null): ?self
{
if ($name === 'this' || in_array($name, Scope::SUPERGLOBAL_VARIABLES, true)) {
return null;
Expand Down
3 changes: 1 addition & 2 deletions src/Analyser/VariableLivenessResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,7 @@ private function passBindingProbes(array $next, string $name, ?VariableWrite $wr
return $next;
}

/** @param int|string $offset */
private static function offsetKey($offset): string
private static function offsetKey(int|string $offset): string
{
return (is_int($offset) ? 'i:' : 's:') . $offset;
}
Expand Down
5 changes: 1 addition & 4 deletions src/Analyser/VariableWriteOffset.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
final class VariableWriteOffset
{

/**
* @return int|string|null
*/
public static function fromType(Type $dimType)
public static function fromType(Type $dimType): int|string|null
{
$keyType = $dimType->toArrayKey();
if (!$keyType->isConstantScalarValue()->yes()) {
Expand Down
8 changes: 2 additions & 6 deletions src/Cache/ArenaCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,16 @@ public static function lookup(string $key): mixed

/**
* Publishes the value unless the key already has one - the first publish wins.
*
* @param mixed $value
*/
public static function publish(string $key, $value): void
public static function publish(string $key, mixed $value): void
{
}

/**
* Publishes the value in place of the one the key has - for a value just
* computed because the published one was out of date.
*
* @param mixed $value
*/
public static function replace(string $key, $value): void
public static function replace(string $key, mixed $value): void
{
}

Expand Down
8 changes: 2 additions & 6 deletions src/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ public function __construct(

/**
* @param non-empty-string $key
*
* @return mixed|null
*/
public function load(string $key, string $variableKey)
public function load(string $key, string $variableKey): mixed
{
// Every entry is also shared across the run's parallel workers
// through the shared-memory arena (turbo extension only; the seam is
Expand Down Expand Up @@ -58,10 +56,8 @@ public function load(string $key, string $variableKey)

/**
* @param non-empty-string $key
*
* @param mixed $data
*/
public function save(string $key, string $variableKey, $data): void
public function save(string $key, string $variableKey, mixed $data): void
{
$this->storage->save($key, $variableKey, $data);

Expand Down
10 changes: 2 additions & 8 deletions src/Cache/CacheItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
final class CacheItem
{

/**
* @param mixed $data
*/
public function __construct(private string $variableKey, private $data)
public function __construct(private string $variableKey, private mixed $data)
{
}

Expand All @@ -17,10 +14,7 @@ public function isVariableKeyValid(string $variableKey): bool
return $this->variableKey === $variableKey;
}

/**
* @return mixed
*/
public function getData()
public function getData(): mixed
{
return $this->data;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Cache/CacheStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ public function load(string $key, string $variableKey);

/**
* @param non-empty-string $key
*
* @param mixed $data
*/
public function save(string $key, string $variableKey, $data): void;
public function save(string $key, string $variableKey, mixed $data): void;

}
8 changes: 2 additions & 6 deletions src/Cache/FileCacheStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ public function __construct(private string $directory)
{
}

/**
* @return mixed|null
*/
public function load(string $key, string $variableKey)
public function load(string $key, string $variableKey): mixed
{
[,, $filePath] = $this->getFilePaths($key);

Expand Down Expand Up @@ -88,10 +85,9 @@ public function load(string $key, string $variableKey)
}

/**
* @param mixed $data
* @throws DirectoryCreatorException
*/
public function save(string $key, string $variableKey, $data): void
public function save(string $key, string $variableKey, mixed $data): void
{
[$firstDirectory, $secondDirectory, $path] = $this->getFilePaths($key);
DirectoryCreator::ensureDirectoryExists($this->directory, 0777);
Expand Down
10 changes: 2 additions & 8 deletions src/Cache/MemoryCacheStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ final class MemoryCacheStorage implements CacheStorage
/** @var array<string, CacheItem> */
private array $storage = [];

/**
* @return mixed|null
*/
public function load(string $key, string $variableKey)
public function load(string $key, string $variableKey): mixed
{
if (!isset($this->storage[$key])) {
return null;
Expand All @@ -25,10 +22,7 @@ public function load(string $key, string $variableKey)
return $item->getData();
}

/**
* @param mixed $data
*/
public function save(string $key, string $variableKey, $data): void
public function save(string $key, string $variableKey, mixed $data): void
{
$this->storage[$key] = new CacheItem($variableKey, $data);
}
Expand Down
Loading
Loading