,error_levels?:string[]}> */ public function providerValidCodeParse(): iterable { return [ 'addThrowableInterfaceType' => [ 'getMessage(); }', ], 'rethrowInterfaceExceptionWithoutInvalidThrow' => [ ' [ ' [ '$worked' => 'bool', ], ], 'alwaysReturnsBecauseCatchDoesNothing' => [ ' [ ' [ 'getMessage(); // do nothing here either } finally { return true; } }', ], 'stopAnalysisAfterBadTryIssue' => [ 'bar(); } catch (\TypeError $e) { $foo = false; } if (!$foo) {}', 'assertions' => [], 'error_message' => [ 'UndefinedGlobalVariable' => \Psalm\Config::REPORT_INFO, 'MixedMethodCall' => \Psalm\Config::REPORT_INFO, ], ], 'issetAfterTryCatchWithoutAssignmentInCatch' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ 'getMessage();' ], 'varSetInOnlyCatchWithNull' => [ 'getMessage();' ], 'allowDoubleNestedLoop' => [ ' [ ' [ ' [ ' [ 'end = null; }', ], 'returnsInTry' => [ 'property) { return $arg; } try { return $arg; } finally { } } }' ], 'finallyArgMaybeUndefined' => [ 'startTransaction(); try { $this->workThatMayOrMayNotThrow(); $success = true; } finally { $this->endTransaction($success ?? false); } } private function workThatMayOrMayNotThrow(): void {} }' ], 'finallyArgIsNotUndefinedIfSet' => [ ' [ ' [ ' * @psalm-suppress MixedAssignment */ function fetchFromCache(mixed $m) { $data = []; try { $value = $m; } catch (Throwable $e) { $value = $m; } $data[] = $value; return $data; }', [], [], '8.0' ], ]; } /** * @return iterable */ public function providerInvalidCodeParse(): iterable { return [ 'invalidCatchClass' => [ ' 'InvalidCatch', ], 'invalidThrowClass' => [ ' 'InvalidThrow', ], 'theresNoCatch' => [ ' 'InvalidReturnType', ], 'catchDoesNotReturn' => [ ' 'InvalidReturnType', ], 'catchWithNoReturnAndFinallyDoesNotReturn' => [ 'getMessage(); // do nothing here either } finally { } }', 'error_message' => 'InvalidReturnType', ], 'catchWithNoReturnAndNoFinally' => [ 'getMessage(); // do nothing here either } }', 'error_message' => 'InvalidReturnType', ], 'preventPossiblyUndefinedVarInTry' => [ ' 'PossiblyUndefinedGlobalVariable', ], 'possiblyNullReturnInTry' => [ ' 'NullableReturnStatement' ], 'isAlwaysDefinedInFinally' => [ ' 'RedundantCondition' ], ]; } }