Skip to content

Commit a69e3bc

Browse files
committed
Bleeding edge - check var tag type against native type
1 parent ce24c83 commit a69e3bc

18 files changed

+160
-20
lines changed

conf/bleedingEdge.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ parameters:
2727
invarianceComposition: true
2828
alwaysTrueAlwaysReported: true
2929
disableUnreachableBranchesRules: true
30+
varTagType: true

conf/config.level2.neon

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ rules:
4242
- PHPStan\Rules\PhpDoc\InvalidPhpDocTagValueRule
4343
- PHPStan\Rules\PhpDoc\InvalidPHPStanDocTagRule
4444
- PHPStan\Rules\PhpDoc\InvalidThrowsPhpDocValueRule
45-
- PHPStan\Rules\PhpDoc\WrongVariableNameInVarTagRule
4645
- PHPStan\Rules\Properties\AccessPrivatePropertyThroughStaticRule
4746

4847
conditionalTags:
@@ -75,3 +74,9 @@ services:
7574
checkMissingVarTagTypehint: %checkMissingVarTagTypehint%
7675
tags:
7776
- phpstan.rules.rule
77+
-
78+
class: PHPStan\Rules\PhpDoc\WrongVariableNameInVarTagRule
79+
arguments:
80+
checkTypeAgainstNativeType: %featureToggles.varTagType%
81+
tags:
82+
- phpstan.rules.rule

conf/config.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ parameters:
5757
invarianceComposition: false
5858
alwaysTrueAlwaysReported: false
5959
disableUnreachableBranchesRules: false
60+
varTagType: false
6061
fileExtensions:
6162
- php
6263
checkAdvancedIsset: false
@@ -280,6 +281,7 @@ parametersSchema:
280281
invarianceComposition: bool()
281282
alwaysTrueAlwaysReported: bool()
282283
disableUnreachableBranchesRules: bool()
284+
varTagType: bool()
283285
])
284286
fileExtensions: listOf(string())
285287
checkAdvancedIsset: bool()

phpstan-baseline.neon

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ parameters:
7676
count: 1
7777
path: src/Command/CommandHelper.php
7878

79+
-
80+
message: "#^PHPDoc tag @var with type array\\<callable\\>\\|false is not subtype of native type array\\.$#"
81+
count: 2
82+
path: src/Command/CommandHelper.php
83+
7984
-
8085
message: "#^Parameter \\#1 \\$path of function dirname expects string, string\\|false given\\.$#"
8186
count: 1
@@ -335,6 +340,11 @@ parameters:
335340
count: 1
336341
path: src/Reflection/InitializerExprTypeResolver.php
337342

343+
-
344+
message: "#^PHPDoc tag @var with type float\\|int is not subtype of native type int\\.$#"
345+
count: 1
346+
path: src/Reflection/InitializerExprTypeResolver.php
347+
338348
-
339349
message: "#^Creating new PHPStan\\\\Php8StubsMap is not covered by backward compatibility promise\\. The class might change in a minor PHPStan version\\.$#"
340350
count: 1
@@ -403,6 +413,16 @@ parameters:
403413
count: 1
404414
path: src/Testing/PHPStanTestCase.php
405415

416+
-
417+
message: "#^PHPDoc tag @var with type float\\|int is not subtype of native type int\\.$#"
418+
count: 3
419+
path: src/Type/Constant/ConstantArrayTypeBuilder.php
420+
421+
-
422+
message: "#^PHPDoc tag @var with type int\\|string is not subtype of native type string\\.$#"
423+
count: 1
424+
path: src/Type/Constant/ConstantStringType.php
425+
406426
-
407427
message: """
408428
#^Call to deprecated method getInstance\\(\\) of class PHPStan\\\\Broker\\\\Broker\\:

src/Command/CommandHelper.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PHPStan\Command;
44

5-
use Closure;
65
use Composer\XdebugHandler\XdebugHandler;
76
use Nette\DI\Helpers;
87
use Nette\DI\InvalidConfigurationException;
@@ -91,7 +90,6 @@ public static function begin(
9190
{
9291
$stdOutput = new SymfonyOutput($output, new SymfonyStyle(new ErrorsConsoleStyle($input, $output)));
9392

94-
/** @var Output $errorOutput */
9593
$errorOutput = (static function () use ($input, $output): Output {
9694
$symfonyErrorOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
9795
return new SymfonyOutput($symfonyErrorOutput, new SymfonyStyle(new ErrorsConsoleStyle($input, $symfonyErrorOutput)));
@@ -474,7 +472,6 @@ public static function begin(
474472
/** @var StubFilesProvider $stubFilesProvider */
475473
$stubFilesProvider = $container->getByType(StubFilesProvider::class);
476474

477-
/** @var Closure(): array{string[], bool} $filesCallback */
478475
$filesCallback = static function () use ($currentWorkingDirectoryFileHelper, $stubFilesProvider, $fileFinder, $pathRoutingParser, $paths): array {
479476
$fileFinderResult = $fileFinder->findFiles($paths);
480477
$files = $fileFinderResult->getFiles();

src/Command/FixerApplication.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function run(
120120
/** @var string $serverAddress */
121121
$serverAddress = $server->getAddress();
122122

123-
/** @var int $serverPort */
123+
/** @var int<0, 65535> $serverPort */
124124
$serverPort = parse_url($serverAddress, PHP_URL_PORT);
125125

126126
$reanalyseProcessQueue = new RunnableQueue(

src/File/FuzzyRelativePathHelper.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,11 @@ public function __construct(
6161
) {
6262
[$pathBeginning, $currentWorkingDirectory] = $trimBeginning($currentWorkingDirectory);
6363

64-
/** @var string[] $pathToTrimArray */
6564
$pathToTrimArray = explode($directorySeparator, $currentWorkingDirectory);
6665
}
6766
foreach ($analysedPaths as $pathNumber => $path) {
6867
[$tempPathBeginning, $path] = $trimBeginning($path);
6968

70-
/** @var string[] $pathArray */
7169
$pathArray = explode($directorySeparator, $path);
7270
$pathTempParts = [];
7371
$pathArraySize = count($pathArray);

src/Parallel/ParallelAnalyser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function analyse(
9999
/** @var string $serverAddress */
100100
$serverAddress = $server->getAddress();
101101

102-
/** @var int $serverPort */
102+
/** @var int<0, 65535> $serverPort */
103103
$serverPort = parse_url($serverAddress, PHP_URL_PORT);
104104

105105
$internalErrorsCount = 0;

src/Reflection/BetterReflection/SourceLocator/AutoloadSourceLocator.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ private function locateClassByName(string $className): ?array
334334
$this->silenceErrors();
335335

336336
try {
337-
/** @var array{string[], string, null}|null */
338337
$result = FileReadTrapStreamWrapper::withStreamWrapperOverride(
339338
static function () use ($className): ?array {
340339
$functions = spl_autoload_functions();

src/Reflection/FunctionVariantWithPhpDocs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(
3737
*/
3838
public function getParameters(): array
3939
{
40-
/** @var ParameterReflectionWithPhpDocs[] $parameters */
40+
/** @var array<int, ParameterReflectionWithPhpDocs> $parameters */
4141
$parameters = parent::getParameters();
4242

4343
return $parameters;

0 commit comments

Comments
 (0)