Skip to content

Commit

Permalink
Update to phpstan 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Nov 2, 2021
1 parent cde3645 commit c34bad8
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

.gitattributes export-ignore
.github/ export-ignore
stubs/ export-ignore
tests/ export-ignore
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"nexusphp/cs-config": "^3.2",
"phpstan/phpstan": "^0.12.82"
"phpstan/phpstan": "^1.0"
},
"config": {
"optimize-autoloader": true,
Expand Down
5 changes: 3 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
parameters:
tmpDir: build/phpstan
level: 8
level: 9
paths:
- src
- tests
bootstrapFiles:
- vendor/autoload.php
stubFiles:
- stubs/phpunit.stub
parallel:
processTimeout: 300.0
polluteScopeWithLoopInitialAssignments: false
Expand All @@ -16,7 +18,6 @@ parameters:
checkExplicitMixedMissingReturn: true
checkFunctionNameCase: true
checkInternalClassCaseSensitivity: true
checkMissingClosureNativeReturnTypehintRule: true
reportMaybesInMethodSignatures: true
reportStaticMethodSignatures: true
checkTooWideReturnTypesInProtectedAndPublicMethods: true
Expand Down
2 changes: 1 addition & 1 deletion src/Tachycardia.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ final class Tachycardia implements AfterLastTestHook, AfterSuccessfulTestHook, B
/**
* Instance of TimeState.
*
* @var \Nexus\PHPUnit\Extension\Util\TimeState
* @var null|\Nexus\PHPUnit\Extension\Util\TimeState
*/
private $timeState;

Expand Down
2 changes: 2 additions & 0 deletions src/Util/GithubMonitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public static function runningInGithubActions(): bool
*/
public function defibrillate(): void
{
/** @phpstan-var array{'label':string, 'time':float, 'limit':float} $test */
foreach ($this->tachycardia->getSlowTests() as $test) {
/** @phpstan-var class-string $class */
[$class, $method] = explode('::', $test['label'], 2);
Expand Down Expand Up @@ -124,6 +125,7 @@ public function warning(string $message, string $file = '', int $line = 1, int $
*/
private function recreateMessage(array $testDetails): string
{
// @phpstan-var array{'label':string, 'time':float, 'limit':float} $testDetails
['label' => $label, 'time' => $time, 'limit' => $limit] = $testDetails;
$precision = $this->tachycardia->getPrecision();

Expand Down
2 changes: 1 addition & 1 deletion src/Util/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class Parser
public const REGEX_TEST_CASE_NAME = '/^(?:(?P<class>[A-Z][A-Za-z0-9_\\\\]+)::(?P<name>\S+))(?:(?P<dataname> with data set (?:#\d+|"[^"]+"))\s\()?/u';

/**
* @var Parser
* @var null|Parser
*/
private static $instance;

Expand Down
9 changes: 4 additions & 5 deletions src/Util/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ public function getTestName(bool $withDataname = true): string
}

/**
* @return array<string, mixed>
* @phpstan-return array{'method': null|array<string, array<int, string>>, 'class':array<string, array<int, string>>}
*/
public function getAnnotations(): array
{
if ([] === $this->annotations) {
$this->annotations = TestUtil::parseTestMethodAnnotations($this->class, $this->name);
}

return $this->annotations;
return $this->annotations; // @phpstan-ignore-line
}

public function hasClassAnnotation(string $key): bool
Expand Down Expand Up @@ -125,14 +125,13 @@ public function getMethodAnnotation(string $key): array
throw new \InvalidArgumentException(sprintf('Key "%s" not found in the method annotations.', $key)); // @codeCoverageIgnore
}

// @phpstan-ignore-next-line
return $this->getAnnotations()['method'][$key];
}

private function hasAnnotation(string $type, string $key): bool
{
if (! \in_array($type, ['method', 'class'], true)) {
return false; // @codeCoverageIgnore
}
\assert(\in_array($type, ['method', 'class'], true));

return isset($this->getAnnotations()[$type][$key]);
}
Expand Down
11 changes: 11 additions & 0 deletions stubs/phpunit.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace PHPUnit\Util;

final class Test
{
/**
* @return array{'method': null|array<string, array<int, string>>, 'class':array<string, array<int, string>>}
*/
public static function parseTestMethodAnnotations(string $className, ?string $methodName = ''): array {}
}

0 comments on commit c34bad8

Please sign in to comment.