Skip to content

Commit

Permalink
Fix issues from review.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrolGenhald committed Feb 20, 2022
1 parent af7a357 commit f22d248
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 28 deletions.
Expand Up @@ -257,7 +257,6 @@ private static function analyzeCatch(

$fq_catch_classes = [];

assert(!empty($catch->types));
foreach ($catch->types as $catch_type_stmt) {
$fq_catch_class = ClassLikeAnalyzer::getFQCLNFromNameObject(
$catch_type_stmt,
Expand Down
1 change: 0 additions & 1 deletion src/Psalm/Internal/Analyzer/Statements/BreakAnalyzer.php
Expand Up @@ -16,7 +16,6 @@
class BreakAnalyzer
{
public static function analyze(
StatementsAnalyzer $_statements_analyzer,
PhpParser\Node\Stmt\Break_ $stmt,
Context $context
): void {
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
Expand Up @@ -567,7 +567,7 @@ private static function analyzeStatement(
} elseif ($stmt instanceof PhpParser\Node\Stmt\Switch_) {
SwitchAnalyzer::analyze($statements_analyzer, $stmt, $context);
} elseif ($stmt instanceof PhpParser\Node\Stmt\Break_) {
BreakAnalyzer::analyze($statements_analyzer, $stmt, $context);
BreakAnalyzer::analyze($stmt, $context);
} elseif ($stmt instanceof PhpParser\Node\Stmt\Continue_) {
ContinueAnalyzer::analyze($statements_analyzer, $stmt, $context);
} elseif ($stmt instanceof PhpParser\Node\Stmt\Static_) {
Expand Down
62 changes: 47 additions & 15 deletions stubs/phpparser.phpstub
@@ -1,22 +1,54 @@
<?php declare(strict_types=1);

namespace PhpParser\Node\Expr;
namespace PhpParser\Node\Expr {
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt;
use PhpParser\Node\VariadicPlaceholder;

use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\VariadicPlaceholder;
abstract class CallLike extends Expr {
/**
* @return list<Arg|VariadicPlaceholder>
*/
abstract public function getRawArgs(): array;

abstract class CallLike extends Expr {
/**
* @return list<Arg|VariadicPlaceholder>
*/
abstract public function getRawArgs(): array;
public function isFirstClassCallable(): bool {}

public function isFirstClassCallable(): bool {}
/**
* @psalm-pure
* @return list<Arg>
*/
public function getArgs(): array{}
}
}

namespace PhpParser\Node\Stmt {
use PhpParser\Node;
use PhpParser\Node\Expr;

class Catch_ extends Node\Stmt
{
/** @var non-empty-list<Node\Name> Types of exceptions to catch */
public $types;
/** @var Expr\Variable|null Variable for exception */
public $var;
/** @var list<Node\Stmt> Statements */
public $stmts;

/**
* Constructs a catch node.
*
* @param non-empty-list<Name> $types Types of exceptions to catch
* @param Expr\Variable|null $var Variable for exception
* @param list<Stmt> $stmts Statements
* @param array $attributes Additional attributes
*/
public function __construct(
array $types, Expr\Variable $var = null, array $stmts = [], array $attributes = []
) {}

/**
* @psalm-pure
* @return list<Arg>
*/
public function getArgs(): array{}
/** @return list<string> */
public function getSubNodeNames() : array {}
}
}
1 change: 0 additions & 1 deletion tests/DocumentationTest.php
Expand Up @@ -65,7 +65,6 @@ class DocumentationTest extends TestCase
* annotations that we don’t want documented
*/
private const INTENTIONALLY_UNDOCUMENTED_ANNOTATIONS = [
'@psalm-check-type', // Used internally for testing try-catch-finally, not sure if we want to support it
'@psalm-self-out', // Not documented as it's a legacy alias of @psalm-this-out
'@psalm-variadic',
];
Expand Down
8 changes: 4 additions & 4 deletions tests/TryCatchTest.php
Expand Up @@ -44,7 +44,7 @@ class CustomException extends Exception implements CustomThrowable {}
'code' => '<?php
try {
$worked = true;
} catch (\Throwable $e) {
} catch (\Exception $e) {
$worked = false;
}',
'assertions' => [
Expand Down Expand Up @@ -141,7 +141,7 @@ function test(): string {
try {
$var = test();
} catch (Throwable $e) {
} catch (Exception $e) {
return;
}
Expand All @@ -159,7 +159,7 @@ function test(): string {
try {
$var = test();
} catch (Throwable $e) {
} catch (Exception $e) {
$var = "bad";
}
Expand Down Expand Up @@ -257,7 +257,7 @@ function example() : void {
try {
$str = "a";
} catch (Throwable $e) {
} catch (Exception $e) {
example();
}
ord($str);',
Expand Down
10 changes: 5 additions & 5 deletions tests/UnusedVariableTest.php
Expand Up @@ -444,7 +444,7 @@ function dangerous(): string {
function callDangerous(): void {
try {
$s = dangerous();
} catch (Throwable $e) {
} catch (Exception $e) {
echo $e->getMessage();
$s = "hello";
}
Expand All @@ -470,7 +470,7 @@ function callDangerous(): void {
} else {
try {
$t = dangerous();
} catch (Throwable $e) {
} catch (Exception $e) {
echo $e->getMessage();
$t = "hello";
}
Expand Down Expand Up @@ -500,7 +500,7 @@ function callDangerous(): void {
} catch (E1 $e) {
echo $e->getMessage();
$s = false;
} catch (Throwable $_) {
} catch (Exception $_) {
return;
}
Expand Down Expand Up @@ -592,7 +592,7 @@ function main() : void {
if (!$s) {
echo "Failed to get string\n";
}
} catch (Throwable $_) {
} catch (Exception $_) {
$s = "fallback";
}
printf("s is %s\n", $s);
Expand Down Expand Up @@ -2875,7 +2875,7 @@ function callDangerous(): void {
} else {
try {
$t = dangerous();
} catch (Throwable $e) {
} catch (Exception $e) {
echo $e->getMessage();
$t = "hello";
}
Expand Down

0 comments on commit f22d248

Please sign in to comment.