Skip to content

Commit

Permalink
Update phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
dantleech committed Aug 9, 2024
1 parent 99b85fa commit c094166
Show file tree
Hide file tree
Showing 58 changed files with 343 additions and 1,768 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use PhpCsFixer\Config;

$finder = PhpCsFixer\Finder::create()
->in('lib')
->in('src')
->in('tests')
->exclude([
'Workspace',
Expand Down
7 changes: 0 additions & 7 deletions .styleci.yml

This file was deleted.

4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"phpactor/class-to-file": "~0.5.0",
"phpactor/test-utils": "^1.1.5",
"phpbench/phpbench": "dev-master",
"phpstan/phpstan": "~0.12.0",
"phpstan/phpstan": "^1.0",
"phpunit/phpunit": "^9.0",
"symfony/filesystem": "^6.0",
"phpspec/prophecy-phpunit": "^2.0",
Expand All @@ -50,7 +50,7 @@
"scripts": {
"integrate": [
"./vendor/bin/php-cs-fixer fix --allow-risky=yes",
"./vendor/bin/phpstan analyse lib -c phpstan.neon",
"./vendor/bin/phpstan analyse --memory-limit=1G",
"./vendor/bin/phpunit",
"./vendor/bin/phpbench run --iterations=1",
"./tests/Smoke/smoke_test.php --limit=100"
Expand Down
1,790 changes: 132 additions & 1,658 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ includes:
- phpstan-baseline.neon
parameters:
level: 7
inferPrivatePropertyTypeFromConstructor: true
reportUnmatchedIgnoredErrors: true
checkGenericClassInNonGenericObjectType: false
excludePaths:
- src/Core/SourceCodeLocator/InternalStubs/GenericTypes.php

paths:
- lib
- src
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function __construct(
private bool $isSubscriptAssignment
) {
}

public function range(): ByteOffsetRange
{
return $this->range;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ private function memberAccessDiagnostics(MemberAccessContext $resolved): Generat
$member->memberType(),
);
}

/**
* @return Generator<DeprecatedUsageDiagnostic>
*/
Expand All @@ -262,6 +263,7 @@ private function classLikeDiagnostics(ClassLikeContext $resolved): Generator
$reflectionClass->classLikeType(),
);
}

/**
* @return Generator<DeprecatedUsageDiagnostic>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function diagnosticsForExtends(
yield from $this->fromReflectionClass($reflector, $range, $class, $parentClass, $class->docblock()->extends(), '@extends');
}
}

/**
* @return Generator<Diagnostic>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class DocblockMissingClassGenericDiagnostic implements Diagnostic
{

public function __construct(
private ByteOffsetRange $range,
private ClassName $className,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function foo() {
}
);
}

public function exit(NodeContextResolver $resolver, Frame $frame, Node $node): iterable
{
if (!$node instanceof MethodDeclaration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function message(): string
$suggestString
);
}

/**
* @return list<string>
*/
Expand All @@ -59,5 +60,4 @@ public function undefinedVariableName(): string
{
return $this->varName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class UnresolvableNameDiagnostic implements Diagnostic
{
public const TYPE_CLASS = 'class';

public const TYPE_FUNCTION = 'function';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
abstract class AbstractReflectionClass extends AbstractReflectedNode implements ReflectionClassLike
{
abstract public function name(): ClassName;

abstract public function docblock(): DocBlock;

public function isInterface(): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public function name(): string
return NodeUtil::nameFromTokenOrNode($this->node, $this->node->memberName);
}


public function method(): ReflectionMethod
{
$class = $this->class();
Expand All @@ -114,6 +113,7 @@ public function scope(): ReflectionScope
{
return new ReflectionScope($this->services->reflector(), $this->node);
}

public function nameRange(): ByteOffsetRange
{
$memberName = $this->node->memberName;
Expand Down
1 change: 1 addition & 0 deletions src/Bridge/TolerantParser/Reflection/ClassInvocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
interface ClassInvocation
{
public function class(): ReflectionClassLike;

public function arguments(): ReflectionArgumentCollection;
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public function isVirtual(): bool
return false;
}


public function value(): Type
{
if ($this->node->assignment === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function expressionType(): Type
$expr = $this->services->nodeContextResolver()->resolveNode($this->frame, $this->node->expression);
return $expr->type();
}

public function scope(): ReflectionScope
{
return new ReflectionScope($this->services->reflector(), $this->node);
Expand Down
1 change: 1 addition & 0 deletions src/Bridge/TolerantParser/Reflection/ReflectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function classLikeType(): string
{
return 'trait';
}

/**
* @return TraitDeclaration
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public function reflectNodeContext(Node $node): NodeContext
return $this->serviceLocator->nodeContextResolver()->resolveNode($frame, $node);
}


public function reflectNode(
TextDocument $sourceCode,
ByteOffset|int $offset
Expand Down
3 changes: 3 additions & 0 deletions src/Core/ClassHierarchyResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
final class ClassHierarchyResolver
{
public const INCLUDE_TRAIT = 0x00000001;

public const INCLUDE_INTERFACE = 0x00000010;

public const INCLUDE_PARENT = 0x00000100;

public const INCLUDE_MIXIN = 0x00001000;

/**
Expand Down
1 change: 0 additions & 1 deletion src/Core/DiagnosticExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ public function __construct(
public ?string $minPhpVersion = null
) {
}

}
1 change: 1 addition & 0 deletions src/Core/DiagnosticProvider/InMemoryDiagnosticProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function examples(): iterable
{
return [];
}

public function exit(NodeContextResolver $resolver, Frame $frame, Node $node): iterable
{
if (!$node instanceof SourceFileNode) {
Expand Down
3 changes: 3 additions & 0 deletions src/Core/DiagnosticSeverity.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
final class DiagnosticSeverity
{
public const ERROR = 1;

public const WARNING = 2;

public const INFORMATION = 3;

public const HINT = 4;

/**
Expand Down
5 changes: 5 additions & 0 deletions src/Core/DocBlock/PlainDocblock.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@
class PlainDocblock implements DocBlock
{
private const LEADING = 3;

private const TEXT = 2;

private const EXTRA_ASTERIX = 1;

private const START = 0;

private const WHITESPACE = 4;

private const WS_OR_TERMINATE = 5;

private string $raw;
Expand Down
1 change: 0 additions & 1 deletion src/Core/Inference/Assignments.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ final protected function __construct(array $variables)
$this->variables = $variables;
}


public function __toString(): string
{
return implode("\n", array_map(function (Variable $variable) {
Expand Down
1 change: 0 additions & 1 deletion src/Core/Inference/FunctionStubRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public function __construct(private array $functionMap)
{
}


public function get(string $name): ?FunctionStub
{
if (!isset($this->functionMap[$name])) {
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Inference/MemberTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
class MemberTypeResolver
{
const TYPE_METHODS = 'methods';

const TYPE_CONSTANTS = 'constants';

const TYPE_PROPERTIES = 'properties';

public function __construct(private ClassReflector $reflector)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ private function resolveContainerMemberType(
foreach ($classType->expandTypes()->classLike() as $subType) {
// upcast to ClassType to reflected type
if (get_class($subType) === ClassType::class) {
/** @phpstan-ignore-next-line */
$subType = $subType->asReflectedClasssType($resolver->reflector());
}

Expand Down
12 changes: 12 additions & 0 deletions src/Core/Inference/Symbol.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,29 @@
final class Symbol
{
public const CLASS_ = 'class';

public const VARIABLE = 'variable';

public const METHOD = 'method';

public const FUNCTION = 'function';

public const PROPERTY = 'property';

public const CONSTANT = 'constant';

public const DECLARED_CONSTANT = 'declared_constant';

public const CASE = 'case';

public const STRING = 'string';

public const NUMBER = 'number';

public const BOOLEAN = 'boolean';

public const ARRAY = 'array';

public const UNKNOWN = '<unknown>';

private string $name;
Expand Down
1 change: 1 addition & 0 deletions src/Core/Inference/TypeAssertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
final class TypeAssertion
{
const VARIABLE_TYPE_PROPERTY = 'property';

const VARIABLE_TYPE_VARIABLE = 'variable';

private string $name;
Expand Down
1 change: 0 additions & 1 deletion src/Core/Inference/TypeCombinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public static function narrowTo(Type $type, Type $narrowTo): Type
return $t;
}


public static function subtract(Type $type, Type $from): Type
{
$from = TypeFactory::toAggregateOrUnion($from);
Expand Down
1 change: 0 additions & 1 deletion src/Core/Inference/Walker/IncludeWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public function __construct(private LoggerInterface $logger, private FrameResolv
$this->parser = $parser ?: new Parser();
}


public function nodeFqns(): array
{
return [ScriptInclusionExpression::class];
Expand Down
2 changes: 0 additions & 2 deletions src/Core/Inference/Walker/TestAssertWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Microsoft\PhpParser\Node\Expression\ArgumentExpression;
use Microsoft\PhpParser\Node\Expression\CallExpression;
use PHPUnit\Framework\TestCase;
use Phpactor\TextDocument\ByteOffset;
use Phpactor\WorseReflection\Bridge\TolerantParser\TextDocument\NodeToTextDocumentConverter;
use Phpactor\WorseReflection\Core\Inference\Frame;
use Phpactor\WorseReflection\Core\Inference\FrameResolver;
Expand Down Expand Up @@ -38,7 +37,6 @@ public function enter(FrameResolver $resolver, Frame $frame, Node $node): Frame
$name = $node->callableExpression->getText();

if ($name === 'wrFrame') {
/** @phpstan-ignore-next-line Allow dump() here */
dump($frame->__toString());
return $frame;
}
Expand Down
1 change: 0 additions & 1 deletion src/Core/Inference/Walker/VariableWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public function __construct(private DocBlockFactory $docblockFactory)
{
}


public function nodeFqns(): array
{
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public function getIterator(): Traversable
{
$iterator = new AppendIterator();
foreach ($this->collections as $collection) {
/** @phpstan-ignore-next-line */
$iterator->append($collection->getIterator());
}

Expand All @@ -76,7 +75,6 @@ public function keys(): array

/**
* @param ReflectionMemberCollection<ReflectionMember> $collection
* @phpstan-ignore-next-line
*/
public function merge(ReflectionCollection $collection): self
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ public function enumCases(): ReflectionEnumCaseCollection
return new ReflectionEnumCaseCollection($this->enumCases);
}


public function map(Closure $closure)
{
$new = new self([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public function enumCases(): ReflectionEnumCaseCollection;
*/
public function byMemberType(string $type): ReflectionCollection;


/**
* @param Closure(T): ReflectionMember $mapper
* @return static
Expand Down
1 change: 0 additions & 1 deletion src/Core/Reflection/ReflectionClassLike.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function isInterface(): bool;

public function isInstanceOf(ClassName $className): bool;


/**
* @deprecated Use instanceof instead
*/
Expand Down
4 changes: 4 additions & 0 deletions src/Core/Reflection/ReflectionDeclaredConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
interface ReflectionDeclaredConstant
{
public function name(): Name;

public function type(): Type;

public function sourceCode(): TextDocument;

public function docblock(): DocBlock;

public function position(): ByteOffsetRange;
}
Loading

0 comments on commit c094166

Please sign in to comment.