Skip to content

Commit 28fd694

Browse files
committed
uses nette/phpstan-rules
1 parent 879b5a6 commit 28fd694

4 files changed

Lines changed: 139 additions & 3 deletions

File tree

composer.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
"nette/tester": "^2.6",
2323
"nikic/php-parser": "^5.0",
2424
"tracy/tracy": "^2.8",
25-
"phpstan/phpstan": "^2.0@stable",
25+
"phpstan/phpstan": "^2.1@stable",
26+
"phpstan/extension-installer": "^1.4@stable",
27+
"nette/phpstan-rules": "^1.0",
2628
"jetbrains/phpstorm-attributes": "^1.2"
2729
},
2830
"suggest": {
@@ -43,5 +45,10 @@
4345
"branch-alias": {
4446
"dev-master": "4.2-dev"
4547
}
48+
},
49+
"config": {
50+
"allow-plugins": {
51+
"phpstan/extension-installer": true
52+
}
4653
}
4754
}

phpstan.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ parameters:
44
paths:
55
- src
66

7-
checkMissingCallableSignature: true
8-
97
ignoreErrors:
108
# Intentional runtime type validation pattern: (function (Type ...$items) {})(...$items)
119
- identifier: expr.resultUnused
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
3+
/**
4+
* PHPStan type tests.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
use Nette\PhpGenerator\ClassType;
10+
use Nette\PhpGenerator\Closure;
11+
use Nette\PhpGenerator\Constant;
12+
use Nette\PhpGenerator\EnumCase;
13+
use Nette\PhpGenerator\EnumType;
14+
use Nette\PhpGenerator\GlobalFunction;
15+
use Nette\PhpGenerator\InterfaceType;
16+
use Nette\PhpGenerator\Method;
17+
use Nette\PhpGenerator\Parameter;
18+
use Nette\PhpGenerator\PhpFile;
19+
use Nette\PhpGenerator\PhpNamespace;
20+
use Nette\PhpGenerator\Property;
21+
use Nette\PhpGenerator\PropertyHook;
22+
use Nette\PhpGenerator\TraitType;
23+
use Nette\PhpGenerator\TraitUse;
24+
use Nette\Utils\Type;
25+
use function PHPStan\Testing\assertType;
26+
27+
28+
function testParameterGetType(Parameter $param): void
29+
{
30+
assertType('string|null', $param->getType());
31+
assertType('string|null', $param->getType(false));
32+
assertType(Type::class . '|null', $param->getType(true));
33+
}
34+
35+
36+
function testPropertyGetType(Property $prop): void
37+
{
38+
assertType('string|null', $prop->getType());
39+
assertType('string|null', $prop->getType(false));
40+
assertType(Type::class . '|null', $prop->getType(true));
41+
}
42+
43+
44+
function testMethodGetReturnType(Method $method): void
45+
{
46+
assertType('string|null', $method->getReturnType());
47+
assertType('string|null', $method->getReturnType(false));
48+
assertType(Type::class . '|null', $method->getReturnType(true));
49+
}
50+
51+
52+
function testEnumGetCases(EnumType $enum): void
53+
{
54+
assertType('array<string, ' . EnumCase::class . '>', $enum->getCases());
55+
}
56+
57+
58+
function testClosureGetUses(Closure $closure): void
59+
{
60+
assertType('list<' . Parameter::class . '>', $closure->getUses());
61+
}
62+
63+
64+
function testPropertyHookGetParameters(PropertyHook $hook): void
65+
{
66+
assertType('array<string, ' . Parameter::class . '>', $hook->getParameters());
67+
}
68+
69+
70+
function testPropertyGetHooks(Property $prop): void
71+
{
72+
assertType('array<string, ' . PropertyHook::class . '>', $prop->getHooks());
73+
}
74+
75+
76+
function testMethodGetVisibility(Method $method): void
77+
{
78+
assertType("'private'|'protected'|'public'|null", $method->getVisibility());
79+
}
80+
81+
82+
function testPropertyGetVisibility(Property $prop): void
83+
{
84+
assertType("'private'|'protected'|'public'|null", $prop->getVisibility());
85+
}
86+
87+
88+
function testClassTypeCollections(ClassType $class): void
89+
{
90+
assertType('array<string, ' . Method::class . '>', $class->getMethods());
91+
assertType('array<string, ' . Property::class . '>', $class->getProperties());
92+
assertType('array<string, ' . Constant::class . '>', $class->getConstants());
93+
assertType('array<string, ' . TraitUse::class . '>', $class->getTraits());
94+
}
95+
96+
97+
function testPhpFileCollections(PhpFile $file): void
98+
{
99+
assertType('array<string, ' . PhpNamespace::class . '>', $file->getNamespaces());
100+
assertType('array<string, ' . ClassType::class . '|' . EnumType::class . '|' . InterfaceType::class . '|' . TraitType::class . '>', $file->getClasses());
101+
assertType('array<string, ' . GlobalFunction::class . '>', $file->getFunctions());
102+
}
103+
104+
105+
function testPhpNamespaceCollections(PhpNamespace $ns): void
106+
{
107+
assertType('array<string, ' . ClassType::class . '|' . EnumType::class . '|' . InterfaceType::class . '|' . TraitType::class . '>', $ns->getClasses());
108+
assertType('array<string, ' . GlobalFunction::class . '>', $ns->getFunctions());
109+
assertType('array<string, string>', $ns->getUses());
110+
}
111+
112+
113+
function testTraitUseGetResolutions(TraitUse $trait): void
114+
{
115+
assertType('list<string>', $trait->getResolutions());
116+
}
117+
118+
119+
function testGlobalFunctionGetParameters(GlobalFunction $fn): void
120+
{
121+
assertType('array<string, ' . Parameter::class . '>', $fn->getParameters());
122+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
require __DIR__ . '/../bootstrap.php';
6+
7+
use Nette\PHPStan\Tester\TypeAssert;
8+
9+
TypeAssert::assertTypes(__DIR__ . '/php-generator-types.php');

0 commit comments

Comments
 (0)