Skip to content

Commit

Permalink
Raise PHPStan level to 10
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-helmich committed Dec 8, 2024
1 parent db931bc commit 311d134
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 9
level: 10
reportUnmatchedIgnoredErrors: false
paths:
- src
4 changes: 4 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class Application extends SymfonyApplication

public function __construct(Container $container)
{
// TODO: Drop these and declare const type once we move to PHP 8.3
assert(is_string(static::APP_NAME));
assert(is_string(static::APP_VERSION));

$this->container = $container;
parent::__construct(static::APP_NAME, static::APP_VERSION);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Linter/LinterConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public function getConfigTreeBuilder(): TreeBuilder
$root = $treeBuilder->root('typoscript-lint'); // @phpstan-ignore-line
}

// This is a mess; I won't bother teaching PHPStan how to interpret this
// @phpstan-ignore-next-line
$root
->children()
->arrayNode('paths')
Expand Down
2 changes: 2 additions & 0 deletions src/Linter/Sniff/DeadCodeSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public function __construct(array $parameters)
*/
public function sniff(array $tokens, File $file, LinterConfiguration $configuration): void
{
assert(is_string(static::ANNOTATION_COMMENT));

foreach ($tokens as $token) {
if (!($token->getType() === TokenInterface::TYPE_COMMENT_ONELINE
|| $token->getType() === TokenInterface::TYPE_COMMENT_MULTILINE)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Linter/Sniff/NestingConsistencySniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(array $parameters)
{
parent::__construct($parameters);

if (array_key_exists('commonPathPrefixThreshold', $parameters)) {
if (array_key_exists('commonPathPrefixThreshold', $parameters) && is_int($parameters['commonPathPrefixThreshold'])) {
$this->commonPathPrefixThreshold = $parameters['commonPathPrefixThreshold'];
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/Linter/Sniff/SniffLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class SniffLocator
*
* @return SniffInterface[]
* @throws Exception
*
* @psalm-return array<int, SniffInterface>
*/
private function loadSniffs(LinterConfiguration $configuration): array
{
Expand Down
5 changes: 3 additions & 2 deletions src/Linter/Sniff/Visitor/NestingConsistencyVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Helmich\TypoScriptLint\Linter\Sniff\NestingConsistencySniff;
use Helmich\TypoScriptParser\Parser\AST\ConditionalStatement;
use Helmich\TypoScriptParser\Parser\AST\NestedAssignment;
use Helmich\TypoScriptParser\Parser\AST\ObjectPath;
use Helmich\TypoScriptParser\Parser\AST\Operator\Assignment;
use Helmich\TypoScriptParser\Parser\AST\Statement;

Expand Down Expand Up @@ -63,7 +64,7 @@ private function walkStatementList(array $statements): void
// Step 2: Discover all plain assignments and determine whether any of them
// can be moved within one of the nested assignments.
foreach ($statements as $statement) {
if (!isset($statement->object)) {
if (!isset($statement->object) || !($statement->object instanceof ObjectPath)) {
continue;
}

Expand Down Expand Up @@ -158,7 +159,7 @@ private function getAssignedObjectPathsFromStatementList(array $statements): arr

// Step 1: Discover all nested object assignment statements.
foreach ($statements as $statement) {
if (!isset($statement->object)) {
if (!isset($statement->object) || !($statement->object instanceof ObjectPath)) {
continue;
}

Expand Down
1 change: 1 addition & 0 deletions src/Util/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function getFilenames(

$matchesPatternList = fn(array $patterns): callable => function (string $file) use ($patterns): bool {
foreach ($patterns as $pattern) {
assert(is_string($pattern));
if (fnmatch($pattern, $file)) {
return true;
}
Expand Down

0 comments on commit 311d134

Please sign in to comment.