Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Dec 19, 2022
1 parent d90a9a2 commit 4052422
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 31 deletions.
1 change: 1 addition & 0 deletions config.xsd
Expand Up @@ -388,6 +388,7 @@
<xs:element name="PossiblyNullFunctionCall" type="IssueHandlerType" minOccurs="0" />
<xs:element name="PossiblyNullIterator" type="IssueHandlerType" minOccurs="0" />
<xs:element name="PossiblyNullOperand" type="IssueHandlerType" minOccurs="0" />
<xs:element name="LiteralKeyUnshapedArray" type="IssueHandlerType" minOccurs="0" />
<xs:element name="PossiblyNullPropertyAssignment" type="IssueHandlerType" minOccurs="0" />
<xs:element name="PossiblyNullPropertyAssignmentValue" type="PropertyIssueHandlerType" minOccurs="0" />
<xs:element name="PossiblyNullPropertyFetch" type="IssueHandlerType" minOccurs="0" />
Expand Down
1 change: 1 addition & 0 deletions psalm.xml.dist
Expand Up @@ -59,6 +59,7 @@

<issueHandlers>
<PossiblyNullOperand errorLevel="suppress"/>
<LiteralKeyUnshapedArray errorLevel="suppress"/>

<DeprecatedMethod>
<errorLevel type="suppress">
Expand Down
2 changes: 0 additions & 2 deletions src/Psalm/Internal/Diff/FileDiffer.php
Expand Up @@ -77,8 +77,6 @@ private static function extractDiff(array $trace, int $x, int $y, array $a, arra
{
$result = [];
for ($d = count($trace) - 1; $d >= 0; --$d) {
// Todo: fix integer ranges in fors
/** @var int<0, max> $d */
$v = $trace[$d];
$k = $x - $y;

Expand Down
Expand Up @@ -1032,6 +1032,7 @@ private static function handleReturn(
&& !$storage->signature_return_type
) {
$new = [];
/** @var SplQueue<array<Atomic>> */
$queue = new SplQueue;
$queue->enqueue($storage->return_type->getAtomicTypes());
$queue->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_DELETE);
Expand Down
Expand Up @@ -101,7 +101,6 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
} else {
return Type::getArray();
}
$unpacked_type_parts = $unpacked_type_parts->getAtomicTypes();
} else {
$unpacked_type_parts = [$type_part];
}
Expand Down
2 changes: 2 additions & 0 deletions src/Psalm/Internal/Provider/StatementsProvider.php
Expand Up @@ -4,6 +4,7 @@

use PhpParser;
use PhpParser\ErrorHandler\Collecting;
use PhpParser\Lexer\Emulative;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ArrayDimFetch;
Expand All @@ -15,6 +16,7 @@
use PhpParser\Node\Name;
use PhpParser\Node\Stmt;
use PhpParser\NodeVisitorAbstract;
use PhpParser\Parser;
use Psalm\CodeLocation\ParseErrorLocation;
use Psalm\Codebase;
use Psalm\Config;
Expand Down
9 changes: 2 additions & 7 deletions src/Psalm/Internal/Scope/IfScope.php
Expand Up @@ -62,19 +62,14 @@ class IfScope
*/
public ?array $negatable_if_types = null;

/**
* @var ClauseConjunction
*/
public array $negated_clauses = [];
public ClauseConjunction $negated_clauses;

/**
* These are the set of clauses that could be applied after the `if`
* statement, if the `if` statement contains branches with leaving statements,
* and the else leaves too
*
* @var ClauseConjunction
*/
public array $reasonable_clauses = [];
public ClauseConjunction $reasonable_clauses;

/**
* @var string[]
Expand Down
5 changes: 1 addition & 4 deletions src/Psalm/Internal/Scope/SwitchScope.php
Expand Up @@ -38,10 +38,7 @@ class SwitchScope

public ?PhpParser\Node\Expr $leftover_case_equality_expr = null;

/**
* @var ClauseConjunction
*/
public array $negated_clauses = [];
public ClauseConjunction $negated_clauses;

/**
* @var array<string, bool>|null
Expand Down
8 changes: 3 additions & 5 deletions tests/Traits/InvalidCodeAnalysisTestTrait.php
Expand Up @@ -47,12 +47,10 @@ public function testInvalidCode(
$code = str_replace("\n", "\r\n", $code);
}

foreach ($error_levels as $error_level) {
$issue_name = $error_level;
$error_level = Config::REPORT_SUPPRESS;

Config::getInstance()->setCustomErrorLevel($issue_name, $error_level);
foreach ($error_levels as $issue_name) {
Config::getInstance()->setCustomErrorLevel($issue_name, Config::REPORT_SUPPRESS);
}
Config::getInstance()->setCustomErrorLevel('LiteralKeyUnshapedArray', Config::REPORT_SUPPRESS);

$this->project_analyzer->setPhpVersion($php_version, 'tests');

Expand Down
2 changes: 2 additions & 0 deletions tests/Traits/ValidCodeAnalysisTestTrait.php
Expand Up @@ -59,6 +59,8 @@ public function testValidCode(
Config::getInstance()->setCustomErrorLevel($issue_name, Config::REPORT_SUPPRESS);
}

Config::getInstance()->setCustomErrorLevel('LiteralKeyUnshapedArray', Config::REPORT_SUPPRESS);

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$code = str_replace("\n", "\r\n", $code);
}
Expand Down
12 changes: 0 additions & 12 deletions tests/TypeReconciliation/RedundantConditionTest.php
Expand Up @@ -900,18 +900,6 @@ public function get(): ?stdClass{ return new stdClass;}
}
}',
],
'countWithNeverValuesInKeyedList' => [
'code' => '<?php
/** @var non-empty-list $report_data */
$report_data = [];
if ( array_key_exists( 2, $report_data ) ) {
} elseif ( !empty( $report_data[0]["type"] ) && rand(0,1) ) {
if ( rand(0,1) ) {}
if ( count( $report_data ) === 1 ) {
}
}',
],
'secondFalsyTwiceWithChange' => [
'code' => '<?php
/**
Expand Down

0 comments on commit 4052422

Please sign in to comment.