Skip to content

Commit

Permalink
Added bleeding edge (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
lulco authored Jun 28, 2023
1 parent 63fb7bd commit 050697c
Show file tree
Hide file tree
Showing 27 changed files with 109 additions and 123 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/composer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
fail-fast: false
matrix:
php: [ '8.0', '8.1', '8.2' ]
outdated-args: [ '--ignore=phpunit/phpunit --ignore=phpstan/phpstan-nette' ]
outdated-args: [ '--ignore=phpunit/phpunit' ]
include:
- php: '7.4'
outdated-args: '--ignore=nette/finder --ignore=phpunit/phpunit --ignore=phpstan/phpstan-nette'
outdated-args: '--ignore=nette/finder --ignore=phpunit/phpunit'

name: Composer outdated - PHP ${{ matrix.php }}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"require": {
"php": ">=7.4 <8.3",
"ext-json": "*",
"phpstan/phpstan": "^1.10.6",
"phpstan/phpstan": "^1.10.21",
"phpstan/phpstan-nette": "^1.2.6",
"latte/latte": "^2.11.6 | ^3.0.4",
"nette/utils": "^3.2|^4.0",
Expand Down
45 changes: 43 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/spaze/phpstan-disallowed-calls/extension.neon
- vendor/phpstan/phpstan/conf/bleedingEdge.neon

parameters:
checkUninitializedProperties: true
Expand Down Expand Up @@ -45,7 +46,9 @@ parameters:

ignoreErrors:
-
message: '#^Calling PHPStan\\DependencyInjection\\DerivativeContainerFactory\:\:create\(\) is not covered by backward compatibility promise\. The method might change in a minor PHPStan version\.$#'
messages:
- '#^Calling PHPStan\\DependencyInjection\\DerivativeContainerFactory\:\:create\(\) is not covered by backward compatibility promise\. The method might change in a minor PHPStan version\.$#'
- '#^Accessing PHPStan\\Analyser\\FileAnalyser::class is not covered by backward compatibility promise\. The class might change in a minor PHPStan version\.$#'
path: src/Analyser/FileAnalyserFactory.php
-
message: '#^Calling PHPStan\\File\\FileExcluder::isExcludedFromAnalysing\(\) is not covered by backward compatibility promise\. The method might change in a minor PHPStan version\.$#'
Expand All @@ -58,7 +61,10 @@ parameters:
- '#^Creating new PHPStan\\Collectors\\Registry is not covered by backward compatibility promise\. The class might change in a minor PHPStan version\.$#'
path: src/Rule/LatteTemplatesRule.php
-
message: '#^Calling PHPStan\\File\\SimpleRelativePathHelper\:\:getRelativePath\(\) is not covered by backward compatibility promise\. The method might change in a minor PHPStan version\.$#'
messages:
- '#^Calling PHPStan\\File\\SimpleRelativePathHelper\:\:getRelativePath\(\) is not covered by backward compatibility promise\. The method might change in a minor PHPStan version\.$#'
- '#^Accessing PHPStan\\Command\\AnalyseCommand::DEFAULT_LEVEL is not covered by backward compatibility promise\. The class might change in a minor PHPStan version\.$#'
- '#^Accessing PHPStan\\Command\\AnalyseCommand::OPTION_LEVEL is not covered by backward compatibility promise\. The class might change in a minor PHPStan version\.$#'
path: src/Error/TableErrorFormatter.php

-
Expand Down Expand Up @@ -132,3 +138,38 @@ parameters:
message: '#^Method Latte\\CompileException\:\:setSource\(\) invoked with 3 parameters, 1-2 required\.$#'
path: src/Compiler/Compiler/Latte2Compiler.php
reportUnmatched: false

# is covered by backward compatibility promise
-
messages:
- '#^Although PHPStan\\Node\\InClassNode is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#'
- '#^Although PHPStan\\Node\\ClassMethod is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#'

-
messages:
-'#^Although PHPStan\\Rules\\MetadataRuleError is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#'
-'#^Although PHPStan\\Rules\\FileRuleError is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#'
-'#^Although PHPStan\\Rules\\LineRuleError is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#'
-'#^Although PHPStan\\Rules\\TipRuleError is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#'
-'#^Although PHPStan\\Rules\\IdentifierRuleError is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#'
-'#^Although PHPStan\\Rules\\NonIgnorableRuleError is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#'
path: src/Error/ErrorBuilder.php

# to be done later, no idea how to fix it now
-
message: '#^Method Efabrica\\PHPStanLatte\\Collector\\Collector\\AbstractCollector::collectItems\(\) should return array\<A of array\>\|null but returns array\<int, array\<string, mixed\>\>\.$#'
path: src/Collector/Collector/AbstractCollector.php
-
messages:
- '#^Doing instanceof PHPStan\\Type\\ObjectType is error-prone and deprecated\. Use Type\:\:isObject\(\) or Type\:\:getObjectClassNames\(\) instead\.$#'
- '#^Doing instanceof PHPStan\\Type\\Generic\\GenericObjectType is error-prone and deprecated\.$#'
path: src/LatteContext/Collector/ComponentCollector.php
-
message: '#^Parameter \#1 \$object of function get_class expects object, mixed given\.$#'
paths:
- src/Compiler/NodeVisitor/ChangeFiltersNodeVisitor.php
- src/Compiler/NodeVisitor/ChangeFunctionsNodeVisitor.php
-
# present only in nette/utils 4
message: '#^PHPDoc tag @var with type SplFileInfo is not subtype of native type Nette\\Utils\\FileInfo\.$#'
reportUnmatched: false
12 changes: 3 additions & 9 deletions src/Analyser/LatteContextData.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,13 @@

class LatteContextData
{
/**
* @var array<RuleError>
*/
/** @var array<RuleError> */
private array $errors;

/**
* @var array<CollectedLatteContextObject>
*/
/** @var array<CollectedLatteContextObject> */
private array $collectedData = [];

/**
* @var array<class-string, CollectedLatteContextObject[]>
*/
/** @var array<class-string, CollectedLatteContextObject[]> */
private array $collectedDataByType = [];

/**
Expand Down
8 changes: 2 additions & 6 deletions src/Collector/Finder/ResolvedNodeFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@
*/
final class ResolvedNodeFinder
{
/**
* @var array<string, CollectedResolvedNode[]>
*/
/** @var array<string, CollectedResolvedNode[]> */
private array $collectedResolvedNodes = [];

/**
* @var array<string>
*/
/** @var array<string> */
private array $analysedFiles = [];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ public function enterNode(Node $node): ?Node
}

$type = $this->getType($class);
if (!$type instanceof ObjectType) {
return null;
}

if (!$type->isInstanceOf('\Latte\Runtime\Template')->yes()) {
if ($type === null || !(new ObjectType('\Latte\Runtime\Template'))->isSuperTypeOf($type)->yes()) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/NodeVisitor/AddFormClassesNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function enterNode(Node $node): ?Node
}

$formControlType = $formControl->getType();
if ($formControlType instanceof ObjectType && ($formControlType->isInstanceOf('Nette\Forms\Controls\CheckboxList')->yes() || $formControlType->isInstanceOf('Nette\Forms\Controls\RadioList')->yes())) {
if ((new ObjectType('Nette\Forms\Controls\CheckboxList'))->isSuperTypeOf($formControlType)->yes() || (new ObjectType('Nette\Forms\Controls\RadioList'))->isSuperTypeOf($formControlType)->yes()) {
$this->possibleAlwaysTrueLabels[] = $this->findParentStmt($node);
}
} elseif ($node->dim instanceof Variable) {
Expand Down
6 changes: 1 addition & 5 deletions src/Compiler/NodeVisitor/ChangeFiltersNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,7 @@ private function addFilterVariables(ClassMethod $node): void
}

$type = $this->getType($class);
if (!$type instanceof ObjectType) {
return;
}

if (!$type->isInstanceOf('\Latte\Runtime\Template')->yes()) {
if ($type === null || !(new ObjectType('\Latte\Runtime\Template'))->isSuperTypeOf($type)->yes()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function enterNode(Node $node): ?Node
}

$callerType = $this->getType($node->var);
if ($callerType instanceof ObjectType && $callerType->isInstanceOf('Nette\Bridges\ApplicationLatte\SnippetDriver')->yes()) {
if ($callerType !== null && (new ObjectType('Nette\Bridges\ApplicationLatte\SnippetDriver'))->isSuperTypeOf($callerType)->yes()) {
$methodCall = new MethodCall($node->var, $node->name, $node->args);
$methodCall->setAttributes($node->getAttributes());
return $methodCall;
Expand Down
8 changes: 2 additions & 6 deletions src/LatteContext/CollectedData/CollectedMethodCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ final class CollectedMethodCall extends CollectedLatteContextObject
public const TERMINATING_CALL = 'terminating';
public const OUTPUT_CALL = 'output';

/**
* @var ?class-string
*/
/** @var ?class-string */
private ?string $callerClassName;

private string $callerMethodName;
Expand All @@ -33,9 +31,7 @@ final class CollectedMethodCall extends CollectedLatteContextObject
/** @var array<string, string|int|float|bool> */
private array $params;

/**
* @var ?class-string
*/
/** @var ?class-string */
private ?string $currentClassName;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/LatteContext/Collector/ComponentCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ private function buildComponents(Node $node, Scope $scope, ClassReflection $clas
$names = $this->valueResolver->resolveStrings($componentNameArg, $scope) ?? [];

$componentType = null;
if ($componentArgType instanceof ObjectType && $componentArgType->isInstanceOf('Nette\ComponentModel\IComponent')->yes()) {
if ((new ObjectType('Nette\ComponentModel\IComponent'))->isSuperTypeOf($componentArgType)->yes()) {
$componentType = $componentArgType;
} elseif ($componentArgType instanceof UnionType) {
$componentTypes = [];
foreach ($componentArgType->getTypes() as $type) {
if ($type instanceof ObjectType && $type->isInstanceOf('Nette\ComponentModel\IComponent')->yes()) {
if ((new ObjectType('Nette\ComponentModel\IComponent'))->isSuperTypeOf($type)->yes()) {
$componentTypes[] = $type;
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/LatteContext/Collector/FormCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ private function findCreateComponent(ClassMethod $node, ClassReflection $classRe
}

$returnType = $parametersAcceptor->getReturnType();
if (!$returnType instanceof ObjectType) {
return null;
}

if (!$returnType->isInstanceOf('Nette\Forms\Form')->yes()) {
if (!(new ObjectType('Nette\Forms\Form'))->isSuperTypeOf($returnType)->yes()) {
return null;
}

Expand Down
19 changes: 9 additions & 10 deletions src/LatteContext/Collector/FormControlCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\ObjectType;

/**
Expand Down Expand Up @@ -63,12 +62,7 @@ public function collectData(Node $node, Scope $scope): ?array
}

$formType = $scope->getType($node->var);

if (!$formType instanceof ObjectType) {
return null;
}

if (!$formType->isInstanceOf('Nette\Forms\Container')->yes()) {
if (!(new ObjectType('Nette\Forms\Container'))->isSuperTypeOf($formType)->yes()) {
return null;
}

Expand All @@ -91,8 +85,12 @@ public function collectData(Node $node, Scope $scope): ?array
$controlNameArg = $node->getArgs()[1] ?? null;
$controlNameDefault = null;
} else {
$objectClassNames = $formType->getObjectClassNames();
if ($objectClassNames === []) {
return null;
}
// other form methods
$formClassReflection = $this->reflectionProvider->getClass($formType->getClassName());
$formClassReflection = $this->reflectionProvider->getClass($objectClassNames[0]);
if (!$formClassReflection->hasMethod($formMethodName)) {
return null;
}
Expand All @@ -109,8 +107,9 @@ public function collectData(Node $node, Scope $scope): ?array

$formControlParameters = $formControlParametersAcceptor->getParameters();
$controlNameDefaultType = isset($formControlParameters[0]) ? $formControlParameters[0]->getDefaultValue() : null;
if ($controlNameDefaultType instanceof ConstantStringType) {
$controlNameDefault = trim($controlNameDefaultType->getValue(), '"\'');
$constantStringTypes = $controlNameDefaultType !== null ? $controlNameDefaultType->getConstantStrings() : [];
if ($constantStringTypes !== []) {
$controlNameDefault = trim($constantStringTypes[0]->getValue(), '"\'');
} else {
$controlNameDefault = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use PhpParser\Node\Expr\List_;
use PhpParser\Node\Expr\PropertyFetch;
use PHPStan\Analyser\Scope;
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\MixedType;

/**
Expand Down Expand Up @@ -56,8 +55,8 @@ public function collect(Node $node, Scope $scope): ?array

$types = [];
$expressionTypes = $scope->getType($node->expr);
if ($expressionTypes instanceof ConstantArrayType) {
$types = $expressionTypes->getValueTypes();
foreach ($expressionTypes->getConstantArrays() as $constantArrayType) {
$types = array_merge($types, $constantArrayType->getValueTypes());
}

$variables = [];
Expand Down
8 changes: 2 additions & 6 deletions src/LatteContext/Finder/ComponentFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@

final class ComponentFinder
{
/**
* @var array<string, array<string, Component[]>>
*/
/** @var array<string, array<string, Component[]>> */
private array $assignedComponents = [];

/**
* @var array<string, array<string, Component[]>>
*/
/** @var array<string, array<string, Component[]>> */
private array $declaredComponents = [];

private ReflectionProvider $reflectionProvider;
Expand Down
4 changes: 1 addition & 3 deletions src/LatteContext/Finder/FilterFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

final class FilterFinder
{
/**
* @var array<string, array<string, Filter[]>>
*/
/** @var array<string, array<string, Filter[]>> */
private array $collectedFilters = [];

private ReflectionProvider $reflectionProvider;
Expand Down
4 changes: 1 addition & 3 deletions src/LatteContext/Finder/FormControlFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

final class FormControlFinder
{
/**
* @var array<string, array<string, ControlInterface[]>>
*/
/** @var array<string, array<string, ControlInterface[]>> */
private array $assignedFormControls = [];

private ReflectionProvider $reflectionProvider;
Expand Down
4 changes: 1 addition & 3 deletions src/LatteContext/Finder/FormFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

final class FormFinder
{
/**
* @var array<string, array<string, CollectedForm[]>>
*/
/** @var array<string, array<string, CollectedForm[]>> */
private array $collectedForms = [];

private ReflectionProvider $reflectionProvider;
Expand Down
12 changes: 3 additions & 9 deletions src/LatteContext/Finder/MethodCallFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,13 @@ final class MethodCallFinder

private LattePhpDocResolver $lattePhpDocResolver;

/**
* @var array<string, array<string, CollectedMethodCall[]>>
*/
/** @var array<string, array<string, CollectedMethodCall[]>> */
private array $collectedMethodCalled = [];

/**
* @var array<string, array<string, bool>>>
*/
/** @var array<string, array<string, bool>> */
private array $hasTerminatingCalls = [];

/**
* @var array<string, array<string, bool>>>
*/
/** @var array<string, array<string, bool>> */
private array $hasOutputCalls = [];

public function __construct(LatteContextData $latteContext, ReflectionProvider $reflectionProvider, LattePhpDocResolver $lattePhpDocResolver)
Expand Down
4 changes: 1 addition & 3 deletions src/LatteContext/Finder/MethodFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

final class MethodFinder
{
/**
* @var array<string, array<string, CollectedMethod[]>>>
*/
/** @var array<string, array<string, CollectedMethod[]>> */
private array $collectedMethods = [];

private MethodCallFinder $methodCallFinder;
Expand Down
4 changes: 1 addition & 3 deletions src/LatteContext/Finder/TemplatePathFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

final class TemplatePathFinder
{
/**
* @var array<string, array<string, array<string>>>
*/
/** @var array<string, array<string, array<string>>> */
private array $collectedTemplatePaths = [];

private ReflectionProvider $reflectionProvider;
Expand Down
4 changes: 1 addition & 3 deletions src/LatteContext/Finder/TemplateRenderFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

final class TemplateRenderFinder
{
/**
* @var array<string, array<string, CollectedTemplateRender[]>>
*/
/** @var array<string, array<string, CollectedTemplateRender[]>> */
private array $collectedTemplateRenders = [];

private MethodCallFinder $methodCallFinder;
Expand Down
Loading

0 comments on commit 050697c

Please sign in to comment.