From f46ccf0a5d9329a18507bfeabcc24c8715a9e22b Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Sun, 16 Jun 2019 12:39:07 -0400 Subject: [PATCH] Strip text from end of @psalm-type --- .../Expression/Fetch/ConstFetchAnalyzer.php | 8 +- tests/AnnotationTest.php | 91 ++++++++++++------- 2 files changed, 62 insertions(+), 37 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php index 00f2cf766..beab2b00a 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php @@ -135,7 +135,7 @@ class ConstFetchAnalyzer false, true ) === false) { - return false; + return; } } } @@ -183,7 +183,7 @@ class ConstFetchAnalyzer } if (!$stmt->name instanceof PhpParser\Node\Identifier) { - return null; + return; } $const_id = $fq_class_name . '::' . $stmt->name; @@ -248,7 +248,7 @@ class ConstFetchAnalyzer } } - return false; + return; } if ($context->calling_method_id) { @@ -352,7 +352,7 @@ class ConstFetchAnalyzer if ($stmt->class instanceof PhpParser\Node\Expr) { if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->class, $context) === false) { - return false; + return; } } diff --git a/tests/AnnotationTest.php b/tests/AnnotationTest.php index 077444cf3..acfea60fe 100644 --- a/tests/AnnotationTest.php +++ b/tests/AnnotationTest.php @@ -515,43 +515,68 @@ class AnnotationTest extends TestCase ], 'megaClosureAnnotationWithSpacing' => [ '|null), - b?: Closure() : array, - c?: Closure() : array, - d?: Closure() : array, - e?: Closure() : (array{ - f: null|string, - g: null|string, - h: null|string, - i: string, - j: mixed, - k: mixed, - l: mixed, - m: mixed, - n: bool, - o?: array{0:string} - }|null), - p?: Closure() : (array{ - f: null|string, - g: null|string, - h: null|string, - q: string, - i: string, - j: mixed, - k: mixed, - l: mixed, - m: mixed, - n: bool, - o?: array{0:string} - }|null), - r?: Closure() : (array|null), - s: array - } */ + /** + * @var array{ + * a: Closure() : (array|null), + * b?: Closure() : array, + * c?: Closure() : array, + * d?: Closure() : array, + * e?: Closure() : (array{ + * f: null|string, + * g: null|string, + * h: null|string, + * i: string, + * j: mixed, + * k: mixed, + * l: mixed, + * m: mixed, + * n: bool, + * o?: array{0:string} + * }|null), + * p?: Closure() : (array{ + * f: null|string, + * g: null|string, + * h: null|string, + * q: string, + * i: string, + * j: mixed, + * k: mixed, + * l: mixed, + * m: mixed, + * n: bool, + * o?: array{0:string} + * }|null), + * r?: Closure() : (array|null), + * s: array + * } + * + * Some text + */ $arr = []; $arr["a"]();', ], + 'multipeLineGenericArray' => [ + ', + * array + * > + * + * @psalm-type RuleArray = array{ + * rule: string, + * controller?: class-string<\Exception>, + * redirect?: string, + * code?: int, + * type?: string, + * middleware?: MiddlewareArray + * } + * + * Foo Bar + */ + class A {}', + ], 'slashAfter?' => [ '