From 711be643c63ac6a3adb8ba7cf0d3ad59fead02f3 Mon Sep 17 00:00:00 2001 From: ralila <> Date: Fri, 3 Dec 2021 20:29:06 +0100 Subject: [PATCH] Import instead of using fqn exceptions --- phpcs.xml | 2 +- src/Psalm/Codebase.php | 7 +- src/Psalm/Config/ErrorLevelFileFilter.php | 9 ++- src/Psalm/Config/IssueHandler.php | 5 +- src/Psalm/Config/ProjectFileFilter.php | 3 +- .../Internal/Analyzer/AlgebraAnalyzer.php | 3 +- .../Internal/Analyzer/ProjectAnalyzer.php | 27 +++---- .../Block/IfConditionalAnalyzer.php | 5 +- .../Block/IfElse/ElseIfAnalyzer.php | 8 +- .../Statements/Block/IfElseAnalyzer.php | 8 +- .../Statements/Block/LoopAnalyzer.php | 3 +- .../Statements/Block/SwitchCaseAnalyzer.php | 5 +- .../Expression/BinaryOp/OrAnalyzer.php | 8 +- .../Fetch/ClassConstFetchAnalyzer.php | 5 +- .../Statements/Expression/IncludeAnalyzer.php | 3 +- .../Expression/SimpleTypeInferer.php | 3 +- .../Statements/Expression/TernaryAnalyzer.php | 3 +- .../Analyzer/Statements/StaticAnalyzer.php | 3 +- .../Internal/Analyzer/StatementsAnalyzer.php | 5 +- src/Psalm/Internal/Cli/Psalm.php | 13 ++-- src/Psalm/Internal/Cli/Psalter.php | 3 +- src/Psalm/Internal/CliUtils.php | 6 +- .../Codebase/ConstantTypeResolver.php | 3 +- .../LanguageServer/Server/TextDocument.php | 9 ++- .../Reflector/FunctionLikeNodeScanner.php | 3 +- .../Internal/PhpVisitor/ReflectorVisitor.php | 3 +- .../ArrayFilterReturnTypeProvider.php | 3 +- .../Internal/Type/AssertionReconciler.php | 5 +- src/Psalm/Internal/Type/TypeExpander.php | 5 +- src/Psalm/Type/Atomic.php | 7 +- tests/AnnotationTest.php | 9 ++- tests/ArrayAccessTest.php | 13 ++-- tests/BadFormatTest.php | 13 ++-- tests/BinaryOperationTest.php | 5 +- tests/ClassLikeStringTest.php | 5 +- tests/CodebaseTest.php | 3 +- tests/Config/ConfigTest.php | 7 +- tests/Config/PluginTest.php | 21 +++--- tests/DocumentationTest.php | 3 +- tests/FileUpdates/ErrorAfterUpdateTest.php | 3 +- tests/ForbiddenCodeTest.php | 17 +++-- tests/IncludeTest.php | 3 +- tests/IssueSuppressionTest.php | 15 ++-- tests/MagicMethodAnnotationTest.php | 7 +- tests/MethodSignatureTest.php | 11 +-- tests/PropertyTypeTest.php | 7 +- tests/StubTest.php | 22 +++--- tests/TaintTest.php | 3 +- tests/ThrowsAnnotationTest.php | 17 +++-- tests/ThrowsInGlobalScopeTest.php | 9 ++- tests/Traits/InvalidCodeAnalysisTestTrait.php | 3 +- tests/TypeParseTest.php | 75 ++++++++++--------- tests/UnusedCodeTest.php | 3 +- tests/UnusedVariableTest.php | 3 +- tests/VariadicTest.php | 3 +- 55 files changed, 258 insertions(+), 197 deletions(-) diff --git a/phpcs.xml b/phpcs.xml index c1a87c510..ebdb6106d 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -78,7 +78,7 @@ --> - + diff --git a/src/Psalm/Codebase.php b/src/Psalm/Codebase.php index 525edd838..dcc2896d4 100644 --- a/src/Psalm/Codebase.php +++ b/src/Psalm/Codebase.php @@ -11,6 +11,7 @@ use LanguageServerProtocol\Range; use LanguageServerProtocol\SignatureInformation; use LanguageServerProtocol\TextEdit; use PhpParser; +use Psalm\Exception\UnanalyzedFileException; use Psalm\Internal\Analyzer\NamespaceAnalyzer; use Psalm\Internal\Analyzer\ProjectAnalyzer; use Psalm\Internal\Analyzer\Statements\Block\ForeachAnalyzer; @@ -1196,7 +1197,7 @@ class Codebase $is_open = $this->file_provider->isOpen($file_path); if (!$is_open) { - throw new \Psalm\Exception\UnanalyzedFileException($file_path . ' is not open'); + throw new UnanalyzedFileException($file_path . ' is not open'); } $file_contents = $this->getFileContents($file_path); @@ -1249,7 +1250,7 @@ class Codebase $is_open = $this->file_provider->isOpen($file_path); if (!$is_open) { - throw new \Psalm\Exception\UnanalyzedFileException($file_path . ' is not open'); + throw new UnanalyzedFileException($file_path . ' is not open'); } $file_contents = $this->getFileContents($file_path); @@ -1385,7 +1386,7 @@ class Codebase $is_open = $this->file_provider->isOpen($file_path); if (!$is_open) { - throw new \Psalm\Exception\UnanalyzedFileException($file_path . ' is not open'); + throw new UnanalyzedFileException($file_path . ' is not open'); } $file_contents = $this->getFileContents($file_path); diff --git a/src/Psalm/Config/ErrorLevelFileFilter.php b/src/Psalm/Config/ErrorLevelFileFilter.php index 7509f1d44..fd25a84d6 100644 --- a/src/Psalm/Config/ErrorLevelFileFilter.php +++ b/src/Psalm/Config/ErrorLevelFileFilter.php @@ -2,6 +2,7 @@ namespace Psalm\Config; use Psalm\Config; +use Psalm\Exception\ConfigException; use SimpleXMLElement; use function in_array; @@ -27,10 +28,10 @@ class ErrorLevelFileFilter extends FileFilter $filter->error_level = (string) $config['type']; if (!in_array($filter->error_level, Config::$ERROR_LEVELS, true)) { - throw new \Psalm\Exception\ConfigException('Unexpected error level ' . $filter->error_level); + throw new ConfigException('Unexpected error level ' . $filter->error_level); } } else { - throw new \Psalm\Exception\ConfigException(' element expects a level'); + throw new ConfigException(' element expects a level'); } return $filter; @@ -50,10 +51,10 @@ class ErrorLevelFileFilter extends FileFilter $filter->error_level = (string) $e['type']; if (!in_array($filter->error_level, Config::$ERROR_LEVELS, true)) { - throw new \Psalm\Exception\ConfigException('Unexpected error level ' . $filter->error_level); + throw new ConfigException('Unexpected error level ' . $filter->error_level); } } else { - throw new \Psalm\Exception\ConfigException(' element expects a level'); + throw new ConfigException(' element expects a level'); } return $filter; diff --git a/src/Psalm/Config/IssueHandler.php b/src/Psalm/Config/IssueHandler.php index 49f343524..6aa06e502 100644 --- a/src/Psalm/Config/IssueHandler.php +++ b/src/Psalm/Config/IssueHandler.php @@ -2,6 +2,7 @@ namespace Psalm\Config; use Psalm\Config; +use Psalm\Exception\ConfigException; use SimpleXMLElement; use function array_filter; @@ -34,7 +35,7 @@ class IssueHandler $handler->error_level = (string) $e['errorLevel']; if (!in_array($handler->error_level, Config::$ERROR_LEVELS, true)) { - throw new \Psalm\Exception\ConfigException('Unexpected error level ' . $handler->error_level); + throw new ConfigException('Unexpected error level ' . $handler->error_level); } } @@ -57,7 +58,7 @@ class IssueHandler public function setErrorLevel(string $error_level): void { if (!in_array($error_level, Config::$ERROR_LEVELS, true)) { - throw new \Psalm\Exception\ConfigException('Unexpected error level ' . $error_level); + throw new ConfigException('Unexpected error level ' . $error_level); } $this->error_level = $error_level; diff --git a/src/Psalm/Config/ProjectFileFilter.php b/src/Psalm/Config/ProjectFileFilter.php index dc03681f0..b97b4b1e7 100644 --- a/src/Psalm/Config/ProjectFileFilter.php +++ b/src/Psalm/Config/ProjectFileFilter.php @@ -1,6 +1,7 @@ ignoreFiles)) { if (!$inclusive) { - throw new \Psalm\Exception\ConfigException('Cannot nest ignoreFiles inside itself'); + throw new ConfigException('Cannot nest ignoreFiles inside itself'); } /** @var \SimpleXMLElement $e->ignoreFiles */ diff --git a/src/Psalm/Internal/Analyzer/AlgebraAnalyzer.php b/src/Psalm/Internal/Analyzer/AlgebraAnalyzer.php index 98a68319c..67c16daec 100644 --- a/src/Psalm/Internal/Analyzer/AlgebraAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/AlgebraAnalyzer.php @@ -3,6 +3,7 @@ namespace Psalm\Internal\Analyzer; use PhpParser; use Psalm\CodeLocation; +use Psalm\Exception\ComplicatedExpressionException; use Psalm\Internal\Algebra; use Psalm\Internal\Clause; use Psalm\Issue\ParadoxicalCondition; @@ -40,7 +41,7 @@ class AlgebraAnalyzer ): void { try { $negated_formula2 = Algebra::negateFormula($formula_2); - } catch (\Psalm\Exception\ComplicatedExpressionException $e) { + } catch (ComplicatedExpressionException $e) { return; } diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index f1317dc7d..30b43d956 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -5,6 +5,7 @@ use Amp\Loop; use Psalm\Codebase; use Psalm\Config; use Psalm\Context; +use Psalm\Exception\RefactorException; use Psalm\Exception\UnsupportedIssueToFixException; use Psalm\FileManipulation; use Psalm\Internal\Codebase\TaintFlowGraph; @@ -735,14 +736,14 @@ class ProjectAnalyzer $destination_parts = explode('::', $destination); if (!$this->codebase->classlikes->hasFullyQualifiedClassName($source_parts[0])) { - throw new \Psalm\Exception\RefactorException( + throw new RefactorException( 'Source class ' . $source_parts[0] . ' doesn’t exist' ); } if (count($source_parts) === 1 && count($destination_parts) === 1) { if ($this->codebase->classlikes->hasFullyQualifiedClassName($destination_parts[0])) { - throw new \Psalm\Exception\RefactorException( + throw new RefactorException( 'Destination class ' . $destination_parts[0] . ' already exists' ); } @@ -784,13 +785,13 @@ class ProjectAnalyzer strtolower($destination_parts[1]) ) )) { - throw new \Psalm\Exception\RefactorException( + throw new RefactorException( 'Destination method ' . $destination . ' already exists' ); } if (!$this->codebase->classlikes->classExists($destination_parts[0])) { - throw new \Psalm\Exception\RefactorException( + throw new RefactorException( 'Destination class ' . $destination_parts[0] . ' doesn’t exist' ); } @@ -806,7 +807,7 @@ class ProjectAnalyzer $destination_class_storage->parent_classes[strtolower($source_method_id->fq_class_name)] ) ) { - throw new \Psalm\Exception\RefactorException( + throw new RefactorException( 'Cannot move non-static method ' . $source . ' into unrelated class ' . $destination_parts[0] ); @@ -823,25 +824,25 @@ class ProjectAnalyzer if ($source_parts[1][0] === '$') { if ($destination_parts[1][0] !== '$') { - throw new \Psalm\Exception\RefactorException( + throw new RefactorException( 'Destination property must be of the form Foo::$bar' ); } if (!$this->codebase->properties->propertyExists($source, true)) { - throw new \Psalm\Exception\RefactorException( + throw new RefactorException( 'Property ' . $source . ' does not exist' ); } if ($this->codebase->properties->propertyExists($destination, true)) { - throw new \Psalm\Exception\RefactorException( + throw new RefactorException( 'Destination property ' . $destination . ' already exists' ); } if (!$this->codebase->classlikes->classExists($destination_parts[0])) { - throw new \Psalm\Exception\RefactorException( + throw new RefactorException( 'Destination class ' . $destination_parts[0] . ' doesn’t exist' ); } @@ -852,7 +853,7 @@ class ProjectAnalyzer $source_storage = $this->codebase->properties->getStorage($source); if (!$source_storage->is_static) { - throw new \Psalm\Exception\RefactorException( + throw new RefactorException( 'Cannot move non-static property ' . $source ); } @@ -873,7 +874,7 @@ class ProjectAnalyzer if (isset($source_class_constants[$source_parts[1]])) { if (!$this->codebase->classlikes->hasFullyQualifiedClassName($destination_parts[0])) { - throw new \Psalm\Exception\RefactorException( + throw new RefactorException( 'Destination class ' . $destination_parts[0] . ' doesn’t exist' ); } @@ -884,7 +885,7 @@ class ProjectAnalyzer ); if (isset($destination_class_constants[$destination_parts[1]])) { - throw new \Psalm\Exception\RefactorException( + throw new RefactorException( 'Destination constant ' . $destination . ' already exists' ); } @@ -901,7 +902,7 @@ class ProjectAnalyzer continue; } - throw new \Psalm\Exception\RefactorException( + throw new RefactorException( 'Psalm cannot locate ' . $source ); } diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php index f91e22f49..3494d5688 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php @@ -5,6 +5,7 @@ use PhpParser; use Psalm\CodeLocation; use Psalm\Codebase; use Psalm\Context; +use Psalm\Exception\ScopeAnalysisException; use Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer; use Psalm\Internal\Analyzer\StatementsAnalyzer; use Psalm\Internal\Clause; @@ -116,7 +117,7 @@ class IfConditionalAnalyzer $externally_applied_if_cond_expr, $outer_context ) === false) { - throw new \Psalm\Exception\ScopeAnalysisException(); + throw new ScopeAnalysisException(); } } @@ -164,7 +165,7 @@ class IfConditionalAnalyzer $if_conditional_context->inside_conditional = true; if (ExpressionAnalyzer::analyze($statements_analyzer, $cond, $if_conditional_context) === false) { - throw new \Psalm\Exception\ScopeAnalysisException(); + throw new ScopeAnalysisException(); } $if_conditional_context->inside_conditional = false; diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php index d87d6dd5a..482842d08 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php @@ -5,6 +5,8 @@ use PhpParser; use Psalm\CodeLocation; use Psalm\Codebase; use Psalm\Context; +use Psalm\Exception\ComplicatedExpressionException; +use Psalm\Exception\ScopeAnalysisException; use Psalm\Internal\Algebra; use Psalm\Internal\Algebra\FormulaGenerator; use Psalm\Internal\Analyzer\AlgebraAnalyzer; @@ -62,7 +64,7 @@ class ElseIfAnalyzer $cond_referenced_var_ids = $if_conditional_scope->cond_referenced_var_ids; $assigned_in_conditional_var_ids = $if_conditional_scope->assigned_in_conditional_var_ids; $entry_clauses = $if_conditional_scope->entry_clauses; - } catch (\Psalm\Exception\ScopeAnalysisException $e) { + } catch (ScopeAnalysisException $e) { return false; } @@ -191,7 +193,7 @@ class ElseIfAnalyzer $negated_elseif_types = Algebra::getTruthsFromFormula( Algebra::negateFormula($elseif_clauses) ); - } catch (\Psalm\Exception\ComplicatedExpressionException $e) { + } catch (ComplicatedExpressionException $e) { $reconcilable_elseif_types = []; $negated_elseif_types = []; } @@ -424,7 +426,7 @@ class ElseIfAnalyzer Algebra::negateFormula($elseif_clauses) ) ); - } catch (\Psalm\Exception\ComplicatedExpressionException $e) { + } catch (ComplicatedExpressionException $e) { $if_scope->negated_clauses = []; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php index 40d8385b5..7ecd0aec2 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php @@ -4,6 +4,8 @@ namespace Psalm\Internal\Analyzer\Statements\Block; use PhpParser; use Psalm\CodeLocation; use Psalm\Context; +use Psalm\Exception\ComplicatedExpressionException; +use Psalm\Exception\ScopeAnalysisException; use Psalm\Internal\Algebra; use Psalm\Internal\Algebra\FormulaGenerator; use Psalm\Internal\Analyzer\AlgebraAnalyzer; @@ -103,7 +105,7 @@ class IfElseAnalyzer $post_if_context = $if_conditional_scope->post_if_context; $cond_referenced_var_ids = $if_conditional_scope->cond_referenced_var_ids; $assigned_in_conditional_var_ids = $if_conditional_scope->assigned_in_conditional_var_ids; - } catch (\Psalm\Exception\ScopeAnalysisException $e) { + } catch (ScopeAnalysisException $e) { return false; } @@ -198,7 +200,7 @@ class IfElseAnalyzer try { $if_scope->negated_clauses = Algebra::negateFormula($if_clauses); - } catch (\Psalm\Exception\ComplicatedExpressionException $e) { + } catch (ComplicatedExpressionException $e) { try { $if_scope->negated_clauses = FormulaGenerator::getFormula( $cond_object_id, @@ -209,7 +211,7 @@ class IfElseAnalyzer $codebase, false ); - } catch (\Psalm\Exception\ComplicatedExpressionException $e) { + } catch (ComplicatedExpressionException $e) { $if_scope->negated_clauses = []; } } diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/LoopAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/LoopAnalyzer.php index b7c680ace..25e24cd46 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/LoopAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/LoopAnalyzer.php @@ -5,6 +5,7 @@ use PhpParser; use Psalm\CodeLocation; use Psalm\Config; use Psalm\Context; +use Psalm\Exception\ComplicatedExpressionException; use Psalm\Internal\Algebra; use Psalm\Internal\Algebra\FormulaGenerator; use Psalm\Internal\Analyzer\ScopeAnalyzer; @@ -494,7 +495,7 @@ class LoopAnalyzer try { $negated_pre_condition_clauses = Algebra::negateFormula(array_merge(...$pre_condition_clauses)); - } catch (\Psalm\Exception\ComplicatedExpressionException $e) { + } catch (ComplicatedExpressionException $e) { $negated_pre_condition_clauses = []; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php index a070a5552..febf52e10 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php @@ -5,6 +5,7 @@ use PhpParser; use Psalm\CodeLocation; use Psalm\Codebase; use Psalm\Context; +use Psalm\Exception\ComplicatedExpressionException; use Psalm\Internal\Algebra; use Psalm\Internal\Algebra\FormulaGenerator; use Psalm\Internal\Analyzer\AlgebraAnalyzer; @@ -431,7 +432,7 @@ class SwitchCaseAnalyzer if ($case_clauses && $case_equality_expr) { try { $negated_case_clauses = Algebra::negateFormula($case_clauses); - } catch (\Psalm\Exception\ComplicatedExpressionException $e) { + } catch (ComplicatedExpressionException $e) { $case_equality_expr_id = \spl_object_id($case_equality_expr); try { @@ -445,7 +446,7 @@ class SwitchCaseAnalyzer false, false ); - } catch (\Psalm\Exception\ComplicatedExpressionException $e) { + } catch (ComplicatedExpressionException $e) { $negated_case_clauses = []; } } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/OrAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/OrAnalyzer.php index 903de1ea1..0824c1af6 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/OrAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/OrAnalyzer.php @@ -4,6 +4,8 @@ namespace Psalm\Internal\Analyzer\Statements\Expression\BinaryOp; use PhpParser; use Psalm\CodeLocation; use Psalm\Context; +use Psalm\Exception\ComplicatedExpressionException; +use Psalm\Exception\ScopeAnalysisException; use Psalm\Internal\Algebra; use Psalm\Internal\Algebra\FormulaGenerator; use Psalm\Internal\Analyzer\Statements\Block\IfConditionalAnalyzer; @@ -81,7 +83,7 @@ class OrAnalyzer if ($stmt->left instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr) { $post_leaving_if_context = clone $context; } - } catch (\Psalm\Exception\ScopeAnalysisException $e) { + } catch (ScopeAnalysisException $e) { return false; } } else { @@ -139,7 +141,7 @@ class OrAnalyzer try { $negated_left_clauses = Algebra::negateFormula($left_clauses); - } catch (\Psalm\Exception\ComplicatedExpressionException $e) { + } catch (ComplicatedExpressionException $e) { try { $negated_left_clauses = FormulaGenerator::getFormula( $left_cond_id, @@ -150,7 +152,7 @@ class OrAnalyzer $codebase, false ); - } catch (\Psalm\Exception\ComplicatedExpressionException $e) { + } catch (ComplicatedExpressionException $e) { return false; } } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ClassConstFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ClassConstFetchAnalyzer.php index 7488a1083..aef5e4163 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ClassConstFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ClassConstFetchAnalyzer.php @@ -4,6 +4,7 @@ namespace Psalm\Internal\Analyzer\Statements\Expression\Fetch; use PhpParser; use Psalm\CodeLocation; use Psalm\Context; +use Psalm\Exception\CircularReferenceException; use Psalm\FileManipulation; use Psalm\Internal\Analyzer\ClassLikeAnalyzer; use Psalm\Internal\Analyzer\ClassLikeNameOptions; @@ -234,7 +235,7 @@ class ClassConstFetchAnalyzer ); } catch (\InvalidArgumentException $_) { return true; - } catch (\Psalm\Exception\CircularReferenceException $e) { + } catch (CircularReferenceException $e) { IssueBuffer::maybeAdd( new CircularReference( 'Constant ' . $const_id . ' contains a circular reference', @@ -521,7 +522,7 @@ class ClassConstFetchAnalyzer ); } catch (\InvalidArgumentException $_) { return true; - } catch (\Psalm\Exception\CircularReferenceException $e) { + } catch (CircularReferenceException $e) { IssueBuffer::maybeAdd( new CircularReference( 'Constant ' . $const_id . ' contains a circular reference', diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php index 7b0140508..e09feaabc 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php @@ -6,6 +6,7 @@ use Psalm\CodeLocation; use Psalm\Config; use Psalm\Context; use Psalm\Exception\FileIncludeException; +use Psalm\Exception\UnpreparedAnalysisException; use Psalm\Internal\Analyzer\FileAnalyzer; use Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer; use Psalm\Internal\Analyzer\StatementsAnalyzer; @@ -202,7 +203,7 @@ class IncludeAnalyzer $context, $global_context ); - } catch (\Psalm\Exception\UnpreparedAnalysisException $e) { + } catch (UnpreparedAnalysisException $e) { if ($config->skip_checks_on_unresolvable_includes) { $context->check_classes = false; $context->check_variables = false; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/SimpleTypeInferer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/SimpleTypeInferer.php index e7c90fc83..9eaac4ab3 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/SimpleTypeInferer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/SimpleTypeInferer.php @@ -4,6 +4,7 @@ namespace Psalm\Internal\Analyzer\Statements\Expression; use PhpParser; use Psalm\Aliases; use Psalm\Codebase; +use Psalm\Exception\CircularReferenceException; use Psalm\FileSource; use Psalm\Internal\Analyzer\ClassLikeAnalyzer; use Psalm\Internal\Analyzer\Statements\Expression\BinaryOp\ArithmeticOpAnalyzer; @@ -286,7 +287,7 @@ class SimpleTypeInferer } return null; - } catch (\InvalidArgumentException | \Psalm\Exception\CircularReferenceException $e) { + } catch (\InvalidArgumentException | CircularReferenceException $e) { return null; } } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php index a4106d1cc..cd4fea3fb 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php @@ -4,6 +4,7 @@ namespace Psalm\Internal\Analyzer\Statements\Expression; use PhpParser; use Psalm\CodeLocation; use Psalm\Context; +use Psalm\Exception\ScopeAnalysisException; use Psalm\Internal\Algebra; use Psalm\Internal\Algebra\FormulaGenerator; use Psalm\Internal\Analyzer\AlgebraAnalyzer; @@ -54,7 +55,7 @@ class TernaryAnalyzer $cond_referenced_var_ids = $if_conditional_scope->cond_referenced_var_ids; $assigned_in_conditional_var_ids = $if_conditional_scope->assigned_in_conditional_var_ids; - } catch (\Psalm\Exception\ScopeAnalysisException $e) { + } catch (ScopeAnalysisException $e) { return false; } diff --git a/src/Psalm/Internal/Analyzer/Statements/StaticAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/StaticAnalyzer.php index f56bb794f..3796969f1 100644 --- a/src/Psalm/Internal/Analyzer/Statements/StaticAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/StaticAnalyzer.php @@ -5,6 +5,7 @@ use PhpParser; use Psalm\CodeLocation; use Psalm\Context; use Psalm\Exception\DocblockParseException; +use Psalm\Exception\IncorrectDocblockException; use Psalm\Internal\Analyzer\CommentAnalyzer; use Psalm\Internal\Analyzer\StatementsAnalyzer; use Psalm\Internal\ReferenceConstraint; @@ -60,7 +61,7 @@ class StaticAnalyzer $statements_analyzer->getSource()->getAliases(), $statements_analyzer->getSource()->getTemplateTypeMap() ); - } catch (\Psalm\Exception\IncorrectDocblockException $e) { + } catch (IncorrectDocblockException $e) { IssueBuffer::maybeAdd( new MissingDocblockType( $e->getMessage(), diff --git a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php index a59ee0924..1d8abe0ad 100644 --- a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php @@ -7,6 +7,7 @@ use Psalm\Codebase; use Psalm\Context; use Psalm\DocComment; use Psalm\Exception\DocblockParseException; +use Psalm\Exception\IncorrectDocblockException; use Psalm\FileManipulation; use Psalm\Internal\Analyzer\Statements\Block\DoAnalyzer; use Psalm\Internal\Analyzer\Statements\Block\ForAnalyzer; @@ -458,14 +459,14 @@ class StatementsAnalyzer extends SourceAnalyzer $template_type_map, $file_storage->type_aliases ); - } catch (\Psalm\Exception\IncorrectDocblockException $e) { + } catch (IncorrectDocblockException $e) { IssueBuffer::maybeAdd( new MissingDocblockType( $e->getMessage(), new CodeLocation($statements_analyzer->getSource(), $stmt) ) ); - } catch (\Psalm\Exception\DocblockParseException $e) { + } catch (DocblockParseException $e) { IssueBuffer::maybeAdd( new InvalidDocblock( $e->getMessage(), diff --git a/src/Psalm/Internal/Cli/Psalm.php b/src/Psalm/Internal/Cli/Psalm.php index 1c91bb56c..ec7668bf6 100644 --- a/src/Psalm/Internal/Cli/Psalm.php +++ b/src/Psalm/Internal/Cli/Psalm.php @@ -6,6 +6,7 @@ use Composer\Autoload\ClassLoader; use Psalm\Config; use Psalm\Config\Creator; use Psalm\ErrorBaseline; +use Psalm\Exception\ConfigCreationException; use Psalm\Exception\ConfigException; use Psalm\Internal\Analyzer\ProjectAnalyzer; use Psalm\Internal\CliUtils; @@ -531,7 +532,7 @@ final class Psalm $init_level, $vendor_dir ); - } catch (\Psalm\Exception\ConfigCreationException $e) { + } catch (ConfigCreationException $e) { die($e->getMessage() . PHP_EOL); } @@ -565,7 +566,7 @@ final class Psalm $config_level = (int) $options['error-level']; if (!in_array($config_level, [1, 2, 3, 4, 5, 6, 7, 8], true)) { - throw new \Psalm\Exception\ConfigException( + throw new ConfigException( 'Invalid error level ' . $config_level ); } @@ -645,7 +646,7 @@ final class Psalm new FileProvider, $options['set-baseline'] ); - } catch (\Psalm\Exception\ConfigException $e) { + } catch (ConfigException $e) { $issue_baseline = []; } @@ -701,7 +702,7 @@ final class Psalm echo str_repeat('-', 30) . "\n"; echo $total_fixed_issues . ' errors fixed' . "\n"; } - } catch (\Psalm\Exception\ConfigException $exception) { + } catch (ConfigException $exception) { fwrite(STDERR, 'Could not update baseline file: ' . $exception->getMessage() . PHP_EOL); exit(1); } @@ -768,7 +769,7 @@ final class Psalm $init_level, $vendor_dir ); - } catch (\Psalm\Exception\ConfigCreationException $e) { + } catch (ConfigCreationException $e) { die($e->getMessage() . PHP_EOL); } @@ -1049,7 +1050,7 @@ final class Psalm new FileProvider, $baseline_file_path ); - } catch (\Psalm\Exception\ConfigException $exception) { + } catch (ConfigException $exception) { fwrite(STDERR, 'Error while reading baseline: ' . $exception->getMessage() . PHP_EOL); exit(1); } diff --git a/src/Psalm/Internal/Cli/Psalter.php b/src/Psalm/Internal/Cli/Psalter.php index 5776b2d99..2acadcdac 100644 --- a/src/Psalm/Internal/Cli/Psalter.php +++ b/src/Psalm/Internal/Cli/Psalter.php @@ -5,6 +5,7 @@ namespace Psalm\Internal\Cli; use Composer\Autoload\ClassLoader; use Composer\XdebugHandler\XdebugHandler; use Psalm\Config; +use Psalm\Exception\UnsupportedIssueToFixException; use Psalm\Internal\Analyzer\ProjectAnalyzer; use Psalm\Internal\CliUtils; use Psalm\Internal\Composer; @@ -376,7 +377,7 @@ HELP; } else { try { $project_analyzer->setIssuesToFix($keyed_issues); - } catch (\Psalm\Exception\UnsupportedIssueToFixException $e) { + } catch (UnsupportedIssueToFixException $e) { fwrite(STDERR, $e->getMessage() . PHP_EOL); exit(1); } diff --git a/src/Psalm/Internal/CliUtils.php b/src/Psalm/Internal/CliUtils.php index 2a090ae88..d52bb186f 100644 --- a/src/Psalm/Internal/CliUtils.php +++ b/src/Psalm/Internal/CliUtils.php @@ -7,6 +7,8 @@ use PackageVersions\Versions; use Phar; use Psalm\Config; use Psalm\Config\Creator; +use Psalm\Exception\ConfigException; +use Psalm\Exception\ConfigNotFoundException; use Psalm\Internal\Analyzer\ProjectAnalyzer; use Psalm\Internal\Composer; use Psalm\Report; @@ -496,7 +498,7 @@ HELP; } else { try { $config = Config::getConfigForPath($current_dir, $current_dir); - } catch (\Psalm\Exception\ConfigNotFoundException $e) { + } catch (ConfigNotFoundException $e) { if (!$create_if_non_existent) { if (in_array($output_format, [Report::TYPE_CONSOLE, Report::TYPE_PHP_STORM])) { fwrite( @@ -517,7 +519,7 @@ HELP; ); } } - } catch (\Psalm\Exception\ConfigException $e) { + } catch (ConfigException $e) { fwrite( STDERR, $e->getMessage() . PHP_EOL diff --git a/src/Psalm/Internal/Codebase/ConstantTypeResolver.php b/src/Psalm/Internal/Codebase/ConstantTypeResolver.php index 3d4c4b906..315ba1359 100644 --- a/src/Psalm/Internal/Codebase/ConstantTypeResolver.php +++ b/src/Psalm/Internal/Codebase/ConstantTypeResolver.php @@ -1,6 +1,7 @@ codebase->getReferenceAtPosition($file_path, $position); - } catch (\Psalm\Exception\UnanalyzedFileException $e) { + } catch (UnanalyzedFileException $e) { $this->codebase->file_provider->openFile($file_path); $this->server->queueFileAnalysis($file_path, $textDocument->uri); @@ -209,7 +210,7 @@ class TextDocument try { $reference_location = $this->codebase->getReferenceAtPosition($file_path, $position); - } catch (\Psalm\Exception\UnanalyzedFileException $e) { + } catch (UnanalyzedFileException $e) { $this->codebase->file_provider->openFile($file_path); $this->server->queueFileAnalysis($file_path, $textDocument->uri); @@ -265,7 +266,7 @@ class TextDocument try { $completion_data = $this->codebase->getCompletionDataAtPosition($file_path, $position); - } catch (\Psalm\Exception\UnanalyzedFileException $e) { + } catch (UnanalyzedFileException $e) { $this->codebase->file_provider->openFile($file_path); $this->server->queueFileAnalysis($file_path, $textDocument->uri); @@ -311,7 +312,7 @@ class TextDocument try { $argument_location = $this->codebase->getFunctionArgumentAtPosition($file_path, $position); - } catch (\Psalm\Exception\UnanalyzedFileException $e) { + } catch (UnanalyzedFileException $e) { $this->codebase->file_provider->openFile($file_path); $this->server->queueFileAnalysis($file_path, $textDocument->uri); diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php index be889b146..309e81b9d 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php @@ -11,6 +11,7 @@ use Psalm\Aliases; use Psalm\CodeLocation; use Psalm\Codebase; use Psalm\Config; +use Psalm\Exception\ComplicatedExpressionException; use Psalm\Exception\DocblockParseException; use Psalm\Exception\IncorrectDocblockException; use Psalm\Internal\Algebra; @@ -311,7 +312,7 @@ class FunctionLikeNodeScanner try { $negated_formula = Algebra::negateFormula($if_clauses); - } catch (\Psalm\Exception\ComplicatedExpressionException $e) { + } catch (ComplicatedExpressionException $e) { $var_assertions = []; break; } diff --git a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php index 1f2b0f0ee..3f6f713d9 100644 --- a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php @@ -5,6 +5,7 @@ use PhpParser; use Psalm\Aliases; use Psalm\CodeLocation; use Psalm\Codebase; +use Psalm\Exception\CodeException; use Psalm\Exception\DocblockParseException; use Psalm\Exception\TypeParseTreeException; use Psalm\FileSource; @@ -573,7 +574,7 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements FileSour ? $e->getJourneyMessage() : $e->message; - throw new \Psalm\Exception\CodeException( + throw new CodeException( 'Error with core stub file docblocks: ' . $issue_type . ' - ' . $e->getShortLocationWithPrevious() diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php index fd0861fe7..68c4e273d 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php @@ -3,6 +3,7 @@ namespace Psalm\Internal\Provider\ReturnTypeProvider; use PhpParser; use Psalm\CodeLocation; +use Psalm\Exception\ComplicatedExpressionException; use Psalm\Internal\Algebra; use Psalm\Internal\Algebra\FormulaGenerator; use Psalm\Internal\Analyzer\Statements\Expression\CallAnalyzer; @@ -256,7 +257,7 @@ class ArrayFilterReturnTypeProvider implements FunctionReturnTypeProviderInterfa $statements_source, $codebase ); - } catch (\Psalm\Exception\ComplicatedExpressionException $e) { + } catch (ComplicatedExpressionException $e) { $filter_clauses = []; } diff --git a/src/Psalm/Internal/Type/AssertionReconciler.php b/src/Psalm/Internal/Type/AssertionReconciler.php index 0eeaece4d..78323f8cc 100644 --- a/src/Psalm/Internal/Type/AssertionReconciler.php +++ b/src/Psalm/Internal/Type/AssertionReconciler.php @@ -3,6 +3,7 @@ namespace Psalm\Internal\Type; use Psalm\CodeLocation; use Psalm\Codebase; +use Psalm\Exception\TypeParseTreeException; use Psalm\Internal\Analyzer\Statements\Expression\Fetch\VariableFetchAnalyzer; use Psalm\Internal\Analyzer\StatementsAnalyzer; use Psalm\Internal\Analyzer\TraitAnalyzer; @@ -192,7 +193,7 @@ class AssertionReconciler extends Reconciler try { $new_type = Type::parseString($assertion, null, $template_type_map); - } catch (\Psalm\Exception\TypeParseTreeException $e) { + } catch (TypeParseTreeException $e) { $new_type = Type::getMixed(); } } @@ -341,7 +342,7 @@ class AssertionReconciler extends Reconciler } else { $new_type_part = Atomic::create($assertion, null, $template_type_map); } - } catch (\Psalm\Exception\TypeParseTreeException $e) { + } catch (TypeParseTreeException $e) { $new_type_part = new TMixed(); if ($code_location) { diff --git a/src/Psalm/Internal/Type/TypeExpander.php b/src/Psalm/Internal/Type/TypeExpander.php index 04baa6234..56a4515d3 100644 --- a/src/Psalm/Internal/Type/TypeExpander.php +++ b/src/Psalm/Internal/Type/TypeExpander.php @@ -2,6 +2,7 @@ namespace Psalm\Internal\Type; use Psalm\Codebase; +use Psalm\Exception\CircularReferenceException; use Psalm\Internal\Type\SimpleAssertionReconciler; use Psalm\Internal\Type\SimpleNegatedAssertionReconciler; use Psalm\Internal\Type\TypeParser; @@ -247,7 +248,7 @@ class TypeExpander $matching_constant, \ReflectionProperty::IS_PRIVATE ); - } catch (\Psalm\Exception\CircularReferenceException $e) { + } catch (CircularReferenceException $e) { $class_constant = null; } @@ -337,7 +338,7 @@ class TypeExpander $return_type->const_name, \ReflectionProperty::IS_PRIVATE ); - } catch (\Psalm\Exception\CircularReferenceException $e) { + } catch (CircularReferenceException $e) { $class_constant_type = null; } diff --git a/src/Psalm/Type/Atomic.php b/src/Psalm/Type/Atomic.php index cbcdbdb3e..36c198ee8 100644 --- a/src/Psalm/Type/Atomic.php +++ b/src/Psalm/Type/Atomic.php @@ -2,6 +2,7 @@ namespace Psalm\Type; use Psalm\Codebase; +use Psalm\Exception\TypeParseTreeException; use Psalm\Internal\Analyzer\StatementsAnalyzer; use Psalm\Internal\Type\TemplateResult; use Psalm\Internal\Type\TypeAlias; @@ -289,11 +290,11 @@ abstract class Atomic implements TypeNode } if (strpos($value, '-') && strpos($value, 'OCI-') !== 0) { - throw new \Psalm\Exception\TypeParseTreeException('Unrecognized type ' . $value); + throw new TypeParseTreeException('Unrecognized type ' . $value); } if (is_numeric($value[0])) { - throw new \Psalm\Exception\TypeParseTreeException('First character of type cannot be numeric'); + throw new TypeParseTreeException('First character of type cannot be numeric'); } if (isset($template_type_map[$value])) { @@ -313,7 +314,7 @@ abstract class Atomic implements TypeNode return new TTypeAlias($type_alias->declaring_fq_classlike_name, $type_alias->alias_name); } - throw new \Psalm\Exception\TypeParseTreeException('Invalid type alias ' . $value . ' provided'); + throw new TypeParseTreeException('Invalid type alias ' . $value . ' provided'); } return new TNamedObject($value); diff --git a/tests/AnnotationTest.php b/tests/AnnotationTest.php index d0700c3db..53146b123 100644 --- a/tests/AnnotationTest.php +++ b/tests/AnnotationTest.php @@ -3,6 +3,7 @@ namespace Psalm\Tests; use Psalm\Config; use Psalm\Context; +use Psalm\Exception\CodeException; use const DIRECTORY_SEPARATOR; @@ -141,7 +142,7 @@ class AnnotationTest extends TestCase public function testPhpStormGenericsInvalidArgument(): void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('InvalidScalarArgument'); Config::getInstance()->allow_phpstorm_generics = true; @@ -163,7 +164,7 @@ class AnnotationTest extends TestCase public function testPhpStormGenericsNoTypehint(): void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('PossiblyInvalidMethodCall'); Config::getInstance()->allow_phpstorm_generics = true; @@ -182,7 +183,7 @@ class AnnotationTest extends TestCase public function testInvalidParamDefault(): void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('InvalidParamDefault'); $this->addFile( @@ -219,7 +220,7 @@ class AnnotationTest extends TestCase public function testInvalidTypehintParamDefaultButAllowedInConfig(): void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('InvalidParamDefault'); Config::getInstance()->add_param_default_to_docblock_type = true; diff --git a/tests/ArrayAccessTest.php b/tests/ArrayAccessTest.php index ce28ed19b..086a8f527 100644 --- a/tests/ArrayAccessTest.php +++ b/tests/ArrayAccessTest.php @@ -3,6 +3,7 @@ namespace Psalm\Tests; use Psalm\Config; use Psalm\Context; +use Psalm\Exception\CodeException; use const DIRECTORY_SEPARATOR; @@ -13,7 +14,7 @@ class ArrayAccessTest extends TestCase public function testEnsureArrayOffsetsExist(): void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('PossiblyUndefinedStringArrayOffset'); Config::getInstance()->ensure_array_string_offsets_exist = true; @@ -88,7 +89,7 @@ class ArrayAccessTest extends TestCase public function testComplainAfterFirstIsset(): void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('PossiblyUndefinedStringArrayOffset'); Config::getInstance()->ensure_array_string_offsets_exist = true; @@ -106,7 +107,7 @@ class ArrayAccessTest extends TestCase public function testEnsureArrayIntOffsetsExist(): void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('PossiblyUndefinedIntArrayOffset'); Config::getInstance()->ensure_array_int_offsets_exist = true; @@ -186,7 +187,7 @@ class ArrayAccessTest extends TestCase { Config::getInstance()->ensure_array_int_offsets_exist = true; - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('PossiblyUndefinedIntArrayOffset'); $this->addFile( @@ -296,7 +297,7 @@ class ArrayAccessTest extends TestCase { Config::getInstance()->ensure_array_int_offsets_exist = true; - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('PossiblyUndefinedIntArrayOffset'); $this->addFile( @@ -319,7 +320,7 @@ class ArrayAccessTest extends TestCase { Config::getInstance()->ensure_array_int_offsets_exist = true; - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('PossiblyUndefinedIntArrayOffset'); $this->addFile( diff --git a/tests/BadFormatTest.php b/tests/BadFormatTest.php index 8e7c6fbea..a0f8f73ee 100644 --- a/tests/BadFormatTest.php +++ b/tests/BadFormatTest.php @@ -2,13 +2,14 @@ namespace Psalm\Tests; use Psalm\Context; +use Psalm\Exception\CodeException; class BadFormatTest extends TestCase { public function testMissingSemicolon(): void { $this->expectExceptionMessage('ParseError - somefile.php:9'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->addFile( 'somefile.php', 'expectExceptionMessage('ParseError - somefile.php:3'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->addFile( 'somefile.php', 'expectExceptionMessage('ParseError - somefile.php:3'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->addFile( 'somefile.php', 'expectExceptionMessage('ParseError - somefile.php:5'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->addFile( 'somefile.php', 'expectExceptionMessage('ParseError - somefile.php:6'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->addFile( 'somefile.php', 'expectExceptionMessage('ParseError - somefile.php:2'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->addFile( 'somefile.php', 'expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('RedundantIdentityWithTrue'); $this->analyzeFile('somefile.php', new Context()); @@ -122,7 +123,7 @@ class BinaryOperationTest extends TestCase }' ); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('RedundantIdentityWithTrue'); $this->analyzeFile('somefile.php', new Context()); diff --git a/tests/ClassLikeStringTest.php b/tests/ClassLikeStringTest.php index 553152484..d2fb25274 100644 --- a/tests/ClassLikeStringTest.php +++ b/tests/ClassLikeStringTest.php @@ -3,6 +3,7 @@ namespace Psalm\Tests; use Psalm\Config; use Psalm\Context; +use Psalm\Exception\CodeException; class ClassLikeStringTest extends TestCase { @@ -12,7 +13,7 @@ class ClassLikeStringTest extends TestCase public function testDontAllowStringStandInForNewClass(): void { $this->expectExceptionMessage('InvalidStringClass'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); Config::getInstance()->allow_string_standin_for_class = false; $this->addFile( @@ -31,7 +32,7 @@ class ClassLikeStringTest extends TestCase public function testDontAllowStringStandInForStaticMethodCall(): void { $this->expectExceptionMessage('InvalidStringClass'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); Config::getInstance()->allow_string_standin_for_class = false; $this->addFile( diff --git a/tests/CodebaseTest.php b/tests/CodebaseTest.php index 3a67b9886..7ad11f2c2 100644 --- a/tests/CodebaseTest.php +++ b/tests/CodebaseTest.php @@ -5,6 +5,7 @@ use PhpParser\Node\Name; use PhpParser\Node\Stmt\Class_; use Psalm\Codebase; use Psalm\Context; +use Psalm\Exception\UnpopulatedClasslikeException; use Psalm\Plugin\EventHandler\AfterClassLikeVisitInterface; use Psalm\Plugin\EventHandler\Event\AfterClassLikeVisitEvent; use Psalm\PluginRegistrationSocket; @@ -202,7 +203,7 @@ class CodebaseTest extends TestCase $this->codebase->classlike_storage_provider->create('A'); $this->codebase->classlike_storage_provider->create('B'); - $this->expectException(\Psalm\Exception\UnpopulatedClasslikeException::class); + $this->expectException(UnpopulatedClasslikeException::class); $this->codebase->classExtends('A', 'B'); } diff --git a/tests/Config/ConfigTest.php b/tests/Config/ConfigTest.php index 6375dd3f4..8ee81e479 100644 --- a/tests/Config/ConfigTest.php +++ b/tests/Config/ConfigTest.php @@ -5,6 +5,7 @@ use Composer\Autoload\ClassLoader; use Psalm\Config; use Psalm\Config\IssueHandler; use Psalm\Context; +use Psalm\Exception\CodeException; use Psalm\Exception\ConfigException; use Psalm\Internal\Analyzer\FileAnalyzer; use Psalm\Internal\Analyzer\ProjectAnalyzer; @@ -936,7 +937,7 @@ class ConfigTest extends TestCase public function testValidThrowInvalidCatch(): void { $this->expectExceptionMessage('InvalidCatch'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), @@ -984,7 +985,7 @@ class ConfigTest extends TestCase public function testInvalidThrowValidCatch(): void { $this->expectExceptionMessage('InvalidThrow'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), @@ -1266,7 +1267,7 @@ class ConfigTest extends TestCase public function testNotIgnoredException() : void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('MissingThrowsDocblock'); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( diff --git a/tests/Config/PluginTest.php b/tests/Config/PluginTest.php index 62f674fcd..811aa1ce5 100644 --- a/tests/Config/PluginTest.php +++ b/tests/Config/PluginTest.php @@ -7,6 +7,7 @@ use PhpParser\Node\Stmt\ClassLike; use Psalm\Codebase; use Psalm\Config; use Psalm\Context; +use Psalm\Exception\CodeException; use Psalm\FileSource; use Psalm\Internal\Analyzer\ProjectAnalyzer; use Psalm\Internal\IncludeCollector; @@ -83,7 +84,7 @@ class PluginTest extends TestCase public function testStringAnalyzerPlugin(): void { $this->expectExceptionMessage('InvalidClass'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2) . DIRECTORY_SEPARATOR, @@ -117,7 +118,7 @@ class PluginTest extends TestCase public function testStringAnalyzerPluginWithClassConstant(): void { $this->expectExceptionMessage('InvalidClass'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2) . DIRECTORY_SEPARATOR, @@ -155,7 +156,7 @@ class PluginTest extends TestCase public function testStringAnalyzerPluginWithClassConstantConcat(): void { $this->expectExceptionMessage('UndefinedMethod'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2) . DIRECTORY_SEPARATOR, @@ -226,7 +227,7 @@ class PluginTest extends TestCase public function testEchoAnalyzerPluginWithUnescapedConcatenatedString(): void { $this->expectExceptionMessage('TypeCoercion'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2) . DIRECTORY_SEPARATOR, @@ -264,7 +265,7 @@ class PluginTest extends TestCase public function testEchoAnalyzerPluginWithUnescapedString(): void { $this->expectExceptionMessage('TypeCoercion'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2) . DIRECTORY_SEPARATOR, @@ -398,7 +399,7 @@ class PluginTest extends TestCase public function testFloatCheckerPlugin(): void { $this->expectExceptionMessage('NoFloatAssignment'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2) . DIRECTORY_SEPARATOR, @@ -819,7 +820,7 @@ class PluginTest extends TestCase public function testPropertyProviderHooksInvalidAssignment(): void { $this->expectExceptionMessage('InvalidPropertyAssignmentValue'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); require_once __DIR__ . '/Plugin/PropertyPlugin.php'; $this->project_analyzer = $this->getProjectAnalyzerWithConfig( @@ -860,7 +861,7 @@ class PluginTest extends TestCase public function testMethodProviderHooksInvalidArg(): void { $this->expectExceptionMessage('InvalidScalarArgument'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); require_once __DIR__ . '/Plugin/MethodPlugin.php'; $this->project_analyzer = $this->getProjectAnalyzerWithConfig( @@ -903,7 +904,7 @@ class PluginTest extends TestCase public function testFunctionProviderHooksInvalidArg(): void { $this->expectExceptionMessage('InvalidScalarArgument'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); require_once __DIR__ . '/Plugin/FunctionPlugin.php'; $this->project_analyzer = $this->getProjectAnalyzerWithConfig( @@ -1146,7 +1147,7 @@ class PluginTest extends TestCase $this->project_analyzer->trackTaintedInputs(); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessageRegExp('/TaintedHtml/'); $this->analyzeFile($file_path, new Context()); diff --git a/tests/DocumentationTest.php b/tests/DocumentationTest.php index 07bfdba7b..55454b60f 100644 --- a/tests/DocumentationTest.php +++ b/tests/DocumentationTest.php @@ -10,6 +10,7 @@ use Psalm\Config; use Psalm\Config\IssueHandler; use Psalm\Context; use Psalm\DocComment; +use Psalm\Exception\CodeException; use Psalm\Internal\Analyzer\ProjectAnalyzer; use Psalm\Internal\Provider\FakeFileProvider; use Psalm\Internal\Provider\Providers; @@ -225,7 +226,7 @@ class DocumentationTest extends TestCase $this->project_analyzer->getCodebase()->config->setCustomErrorLevel($error_level, Config::REPORT_SUPPRESS); } - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessageRegExp('/\b' . preg_quote($error_message, '/') . '\b/'); $codebase = $this->project_analyzer->getCodebase(); diff --git a/tests/FileUpdates/ErrorAfterUpdateTest.php b/tests/FileUpdates/ErrorAfterUpdateTest.php index d481f4506..95fa23d08 100644 --- a/tests/FileUpdates/ErrorAfterUpdateTest.php +++ b/tests/FileUpdates/ErrorAfterUpdateTest.php @@ -1,6 +1,7 @@ file_provider->registerFile($file_path, $contents); } - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessageRegExp('/\b' . preg_quote($error_message, '/') . '\b/'); $codebase->reloadFiles($this->project_analyzer, array_keys($end_files)); diff --git a/tests/ForbiddenCodeTest.php b/tests/ForbiddenCodeTest.php index c1ecc4de0..8aef351f1 100644 --- a/tests/ForbiddenCodeTest.php +++ b/tests/ForbiddenCodeTest.php @@ -4,6 +4,7 @@ namespace Psalm\Tests; use Psalm\Config; use Psalm\Context; +use Psalm\Exception\CodeException; use Psalm\Internal\Analyzer\ProjectAnalyzer; use Psalm\Internal\Provider\Providers; use Psalm\Tests\Internal\Provider; @@ -97,7 +98,7 @@ class ForbiddenCodeTest extends TestCase public function testForbiddenEchoFunctionViaFunctions(): void { $this->expectExceptionMessage('ForbiddenCode'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), @@ -124,7 +125,7 @@ class ForbiddenCodeTest extends TestCase public function testForbiddenEchoFunctionViaFlag(): void { $this->expectExceptionMessage('ForbiddenEcho'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), @@ -168,7 +169,7 @@ class ForbiddenCodeTest extends TestCase public function testForbiddenPrintFunction(): void { $this->expectExceptionMessage('ForbiddenCode'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), @@ -217,7 +218,7 @@ class ForbiddenCodeTest extends TestCase public function testForbiddenVarExportFunction(): void { $this->expectExceptionMessage('ForbiddenCode'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), @@ -245,7 +246,7 @@ class ForbiddenCodeTest extends TestCase public function testForbiddenEmptyFunction(): void { $this->expectExceptionMessage('ForbiddenCode'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), @@ -272,7 +273,7 @@ class ForbiddenCodeTest extends TestCase public function testForbiddenExitFunction(): void { $this->expectExceptionMessage('ForbiddenCode'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), @@ -300,7 +301,7 @@ class ForbiddenCodeTest extends TestCase public function testForbiddenDieFunction(): void { $this->expectExceptionMessage('ForbiddenCode'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), @@ -328,7 +329,7 @@ class ForbiddenCodeTest extends TestCase public function testForbiddenEvalExpression(): void { $this->expectExceptionMessage('ForbiddenCode'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), diff --git a/tests/IncludeTest.php b/tests/IncludeTest.php index 818c225d8..4f9156157 100644 --- a/tests/IncludeTest.php +++ b/tests/IncludeTest.php @@ -2,6 +2,7 @@ namespace Psalm\Tests; use Psalm\Config; +use Psalm\Exception\CodeException; use Psalm\Internal\Analyzer\FileAnalyzer; use function getcwd; @@ -85,7 +86,7 @@ class IncludeTest extends TestCase $config = $codebase->config; $config->skip_checks_on_unresolvable_includes = false; - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessageRegExp('/\b' . preg_quote($error_message, '/') . '\b/'); $codebase->scanFiles(); diff --git a/tests/IssueSuppressionTest.php b/tests/IssueSuppressionTest.php index e2fb63be0..49900770f 100644 --- a/tests/IssueSuppressionTest.php +++ b/tests/IssueSuppressionTest.php @@ -3,6 +3,7 @@ namespace Psalm\Tests; use Psalm\Config; use Psalm\Context; +use Psalm\Exception\CodeException; use function getcwd; @@ -15,7 +16,7 @@ class IssueSuppressionTest extends TestCase public function testIssueSuppressedOnFunction(): void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); $this->addFile( @@ -39,7 +40,7 @@ class IssueSuppressionTest extends TestCase public function testIssueSuppressedOnStatement(): void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); $this->addFile( @@ -54,7 +55,7 @@ class IssueSuppressionTest extends TestCase public function testUnusedSuppressAllOnFunction(): void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); @@ -72,7 +73,7 @@ class IssueSuppressionTest extends TestCase public function testUnusedSuppressAllOnStatement(): void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); $this->addFile( @@ -111,7 +112,7 @@ class IssueSuppressionTest extends TestCase public function testMissingThrowsDocblockSuppressedWithoutThrow(): void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); Config::getInstance()->check_for_throws_docblock = true; @@ -131,7 +132,7 @@ class IssueSuppressionTest extends TestCase public function testMissingThrowsDocblockSuppressedDuplicate(): void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); Config::getInstance()->check_for_throws_docblock = true; @@ -178,7 +179,7 @@ class IssueSuppressionTest extends TestCase public function testUncaughtThrowInGlobalScopeSuppressedWithoutThrow(): void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); Config::getInstance()->check_for_throws_in_global_scope = true; diff --git a/tests/MagicMethodAnnotationTest.php b/tests/MagicMethodAnnotationTest.php index ec1fcd0ee..ce14df7cf 100644 --- a/tests/MagicMethodAnnotationTest.php +++ b/tests/MagicMethodAnnotationTest.php @@ -3,6 +3,7 @@ namespace Psalm\Tests; use Psalm\Config; use Psalm\Context; +use Psalm\Exception\CodeException; use const DIRECTORY_SEPARATOR; @@ -71,7 +72,7 @@ class MagicMethodAnnotationTest extends TestCase public function testAnnotationWithoutCallConfig(): void { $this->expectExceptionMessage('UndefinedMethod'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); Config::getInstance()->use_phpdoc_method_without_magic_or_parent = false; $this->addFile( @@ -948,7 +949,7 @@ class MagicMethodAnnotationTest extends TestCase ); $error_message = 'UndefinedMagicMethod'; - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage($error_message); $this->analyzeFile('somefile.php', new Context()); } @@ -1085,7 +1086,7 @@ class MagicMethodAnnotationTest extends TestCase ); $error_message = 'UndefinedMagicMethod'; - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage($error_message); $this->analyzeFile('somefile.php', new Context()); } diff --git a/tests/MethodSignatureTest.php b/tests/MethodSignatureTest.php index 0d302855e..cd13057f3 100644 --- a/tests/MethodSignatureTest.php +++ b/tests/MethodSignatureTest.php @@ -2,6 +2,7 @@ namespace Psalm\Tests; use Psalm\Context; +use Psalm\Exception\CodeException; use function class_exists; @@ -101,7 +102,7 @@ class MethodSignatureTest extends TestCase public function testMismatchingCovariantReturnIn73(): void { $this->expectExceptionMessage('MethodSignatureMismatch'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer->setPhpVersion('7.3', 'tests'); @@ -152,7 +153,7 @@ class MethodSignatureTest extends TestCase public function testMismatchingCovariantReturnIn73WithSelf(): void { $this->expectExceptionMessage('MethodSignatureMismatch'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer->setPhpVersion('7.3', 'tests'); @@ -199,7 +200,7 @@ class MethodSignatureTest extends TestCase public function testMismatchingCovariantParamIn73(): void { $this->expectExceptionMessage('MethodSignatureMismatch'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer->setPhpVersion('7.3', 'tests'); @@ -244,7 +245,7 @@ class MethodSignatureTest extends TestCase public function testExtendDocblockParamTypeWithWrongDocblockParam(): void { $this->expectExceptionMessage('ImplementedParamTypeMismatch'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); if (class_exists('SoapClient') === false) { $this->markTestSkipped('Cannot run test, base class "SoapClient" does not exist!'); } @@ -279,7 +280,7 @@ class MethodSignatureTest extends TestCase public function testExtendDocblockParamTypeWithWrongParam() : void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('MethodSignatureMismatch'); if (class_exists('SoapClient') === false) { diff --git a/tests/PropertyTypeTest.php b/tests/PropertyTypeTest.php index 3e50b842b..305a442ce 100644 --- a/tests/PropertyTypeTest.php +++ b/tests/PropertyTypeTest.php @@ -3,6 +3,7 @@ namespace Psalm\Tests; use Psalm\Config; use Psalm\Context; +use Psalm\Exception\CodeException; use const DIRECTORY_SEPARATOR; @@ -14,7 +15,7 @@ class PropertyTypeTest extends TestCase public function testForgetPropertyAssignments(): void { $this->expectExceptionMessage('NullableReturnStatement'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); Config::getInstance()->remember_property_assignments_after_call = false; $this->addFile( @@ -193,7 +194,7 @@ class PropertyTypeTest extends TestCase Config::getInstance()->remember_property_assignments_after_call = false; $this->expectExceptionMessage('TypeDoesNotContainNull - somefile.php:22:29'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->addFile( 'somefile.php', @@ -231,7 +232,7 @@ class PropertyTypeTest extends TestCase Config::getInstance()->remember_property_assignments_after_call = false; $this->expectExceptionMessage('TypeDoesNotContainNull - somefile.php:18:29'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->addFile( 'somefile.php', diff --git a/tests/StubTest.php b/tests/StubTest.php index cce2c296f..7d7a4ca85 100644 --- a/tests/StubTest.php +++ b/tests/StubTest.php @@ -3,6 +3,10 @@ namespace Psalm\Tests; use Psalm\Config; use Psalm\Context; +use Psalm\Exception\CodeException; +use Psalm\Exception\ConfigException; +use Psalm\Exception\InvalidClasslikeOverrideException; +use Psalm\Exception\InvalidMethodOverrideException; use Psalm\Internal\Analyzer\ProjectAnalyzer; use Psalm\Internal\IncludeCollector; use Psalm\Internal\Provider\FakeFileProvider; @@ -62,7 +66,7 @@ class StubTest extends TestCase public function testNonexistentStubFile(): void { - $this->expectException(\Psalm\Exception\ConfigException::class); + $this->expectException(ConfigException::class); $this->expectExceptionMessage('Cannot resolve stubfile path'); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( Config::loadFromXML( @@ -395,7 +399,7 @@ class StubTest extends TestCase public function testStubVariadicFunctionWrongArgType(): void { $this->expectExceptionMessage('InvalidScalarArgument'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), @@ -428,7 +432,7 @@ class StubTest extends TestCase public function testUserVariadicWithFalseVariadic(): void { $this->expectExceptionMessage('TooManyArguments'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), @@ -651,7 +655,7 @@ class StubTest extends TestCase public function testNoStubFunction(): void { $this->expectExceptionMessage('UndefinedFunction - /src/somefile.php:2:22 - Function barBar does not exist'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), @@ -984,7 +988,7 @@ class StubTest extends TestCase public function testStubFileWithPartialClassDefinitionWithCoercion(): void { $this->expectExceptionMessage('TypeCoercion'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), @@ -1029,7 +1033,7 @@ class StubTest extends TestCase public function testStubFileWithPartialClassDefinitionGeneralReturnType(): void { $this->expectExceptionMessage('InvalidReturnStatement'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), @@ -1194,7 +1198,7 @@ class StubTest extends TestCase echo "hello";' ); - $this->expectException(\Psalm\Exception\InvalidClasslikeOverrideException::class); + $this->expectException(InvalidClasslikeOverrideException::class); $this->analyzeFile($file_path, new Context()); } @@ -1225,7 +1229,7 @@ class StubTest extends TestCase echo "hello";' ); - $this->expectException(\Psalm\Exception\InvalidMethodOverrideException::class); + $this->expectException(InvalidMethodOverrideException::class); $this->analyzeFile($file_path, new Context()); } @@ -1291,7 +1295,7 @@ class StubTest extends TestCase }' ); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('A|null'); $this->analyzeFile($file_path, new Context()); diff --git a/tests/TaintTest.php b/tests/TaintTest.php index d78ac743d..880ce40ef 100644 --- a/tests/TaintTest.php +++ b/tests/TaintTest.php @@ -2,6 +2,7 @@ namespace Psalm\Tests; use Psalm\Context; +use Psalm\Exception\CodeException; use Psalm\Internal\Analyzer\IssueData; use Psalm\IssueBuffer; @@ -44,7 +45,7 @@ class TaintTest extends TestCase $this->markTestSkipped(); } - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessageRegExp('/\b' . \preg_quote($error_message, '/') . '\b/'); $file_path = self::$src_dir_path . 'somefile.php'; diff --git a/tests/ThrowsAnnotationTest.php b/tests/ThrowsAnnotationTest.php index 1b54853a4..31dbbb806 100644 --- a/tests/ThrowsAnnotationTest.php +++ b/tests/ThrowsAnnotationTest.php @@ -3,13 +3,14 @@ namespace Psalm\Tests; use Psalm\Config; use Psalm\Context; +use Psalm\Exception\CodeException; class ThrowsAnnotationTest extends TestCase { public function testUndefinedClassAsThrows() : void { $this->expectExceptionMessage('UndefinedDocblockClass - somefile.php:3:28'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->addFile( 'somefile.php', @@ -28,7 +29,7 @@ class ThrowsAnnotationTest extends TestCase public function testNonThrowableClassAsThrows() : void { $this->expectExceptionMessage('InvalidThrow'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->addFile( 'somefile.php', @@ -69,7 +70,7 @@ class ThrowsAnnotationTest extends TestCase public function testUndocumentedThrow(): void { $this->expectExceptionMessage('MissingThrowsDocblock'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( @@ -177,7 +178,7 @@ class ThrowsAnnotationTest extends TestCase public function testUndocumentedThrowInFunctionCall(): void { $this->expectExceptionMessage('MissingThrowsDocblock'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( @@ -323,7 +324,7 @@ class ThrowsAnnotationTest extends TestCase public function testUncaughtThrowInFunctionCall(): void { $this->expectExceptionMessage('MissingThrowsDocblock'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( @@ -362,7 +363,7 @@ class ThrowsAnnotationTest extends TestCase public function testEmptyThrows(): void { $this->expectExceptionMessage('MissingDocblockType'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( @@ -548,7 +549,7 @@ class ThrowsAnnotationTest extends TestCase public function testDocumentedThrowInInterfaceWithOverriddenDocblock(): void { $this->expectExceptionMessage('MissingThrowsDocblock'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( @@ -583,7 +584,7 @@ class ThrowsAnnotationTest extends TestCase public function testDocumentedThrowInsideCatch(): void { $this->expectExceptionMessage('MissingThrowsDocblock'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( diff --git a/tests/ThrowsInGlobalScopeTest.php b/tests/ThrowsInGlobalScopeTest.php index 98f3032f2..dd0071fd0 100644 --- a/tests/ThrowsInGlobalScopeTest.php +++ b/tests/ThrowsInGlobalScopeTest.php @@ -3,12 +3,13 @@ namespace Psalm\Tests; use Psalm\Config; use Psalm\Context; +use Psalm\Exception\CodeException; class ThrowsInGlobalScopeTest extends TestCase { public function testUncaughtDocumentedThrowCall(): void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('UncaughtThrowInGlobalScope'); Config::getInstance()->check_for_throws_in_global_scope = true; @@ -102,7 +103,7 @@ class ThrowsInGlobalScopeTest extends TestCase public function testUncaughtDocumentedThrowCallInNamespace(): void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('UncaughtThrowInGlobalScope'); Config::getInstance()->check_for_throws_in_global_scope = true; @@ -136,7 +137,7 @@ class ThrowsInGlobalScopeTest extends TestCase public function testUncaughtThrow(): void { - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessage('UncaughtThrowInGlobalScope'); Config::getInstance()->check_for_throws_in_global_scope = true; @@ -270,7 +271,7 @@ class ThrowsInGlobalScopeTest extends TestCase public function testUncaughtDocumentedThrowCallWhenSuppressingFirst(): void { $this->expectExceptionMessage('UncaughtThrowInGlobalScope'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); Config::getInstance()->check_for_throws_in_global_scope = true; $this->addFile( diff --git a/tests/Traits/InvalidCodeAnalysisTestTrait.php b/tests/Traits/InvalidCodeAnalysisTestTrait.php index 937c60ba7..89537510c 100644 --- a/tests/Traits/InvalidCodeAnalysisTestTrait.php +++ b/tests/Traits/InvalidCodeAnalysisTestTrait.php @@ -3,6 +3,7 @@ namespace Psalm\Tests\Traits; use Psalm\Config; use Psalm\Context; +use Psalm\Exception\CodeException; use function is_int; use function preg_quote; @@ -72,7 +73,7 @@ trait InvalidCodeAnalysisTestTrait // $error_message = preg_replace('/ src[\/\\\\]somefile\.php/', ' src/somefile.php', $error_message); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); if (\method_exists($this, 'expectExceptionMessageMatches')) { $this->expectExceptionMessageMatches('/\b' . preg_quote($error_message, '/') . '\b/'); diff --git a/tests/TypeParseTest.php b/tests/TypeParseTest.php index c8dd4b7f1..ffe0639e0 100644 --- a/tests/TypeParseTest.php +++ b/tests/TypeParseTest.php @@ -2,6 +2,7 @@ namespace Psalm\Tests; use Psalm\Codebase; +use Psalm\Exception\TypeParseTreeException; use Psalm\Internal\Analyzer\ProjectAnalyzer; use Psalm\Internal\Codebase\InternalCallMapHandler; use Psalm\Internal\Provider\FakeFileProvider; @@ -82,13 +83,13 @@ class TypeParseTest extends TestCase public function testBadNullableCharacterInUnion(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('int|array|?'); } public function testBadNullableCharacterInUnionWithFollowing(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('int|array|?|bool'); } @@ -99,7 +100,7 @@ class TypeParseTest extends TestCase public function testArrayWithoutClosingBracket(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('arrayexpectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('array{a: string}&array{a: int}'); } public function testIntersectionOfTwoRegularArrays() : void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('string[]&array'); } @@ -224,13 +225,13 @@ class TypeParseTest extends TestCase public function testIntersectionOfUnionOfTKeyedArray(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('array{a: int}&array{a: string}|array{b: int}'); } public function testIntersectionOfTKeyedArrayAndObject(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('array{a: int}&T1'); } @@ -294,13 +295,13 @@ class TypeParseTest extends TestCase public function testInvalidType(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('array(A)'); } public function testBracketedUnionAndIntersection(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('(A|B)&C'); } @@ -327,7 +328,7 @@ class TypeParseTest extends TestCase public function testTKeyedArrayWithClassConstantKey(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('array{self::FOO: string}'); } @@ -338,13 +339,13 @@ class TypeParseTest extends TestCase public function testTKeyedArrayWithoutClosingBracket(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('array{a: int, b: string'); } public function testTKeyedArrayInType(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('array{a:[]}'); } @@ -413,7 +414,7 @@ class TypeParseTest extends TestCase public function testCallableWithoutClosingBracket(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('callable(int, string'); } @@ -545,7 +546,7 @@ class TypeParseTest extends TestCase public function testConditionalTypeWithCallableElseBool(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('(T is string ? callable() : bool)', null, ['T' => ['' => Type::getArray()]]); } @@ -595,13 +596,13 @@ class TypeParseTest extends TestCase public function testCallableWithTrailingColon(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('callable(int):'); } public function testCallableWithAnotherBadVariadic(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('callable(int, string..) : void'); } @@ -615,85 +616,85 @@ class TypeParseTest extends TestCase public function testCallableWithVariadicAndDefault(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('callable(int, string...=) : void'); } public function testBadVariadic(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('string...'); } public function testBadFullStop(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('string.'); } public function testBadSemicolon(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('string;'); } public function testBadGenericString(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('string'); } public function testBadAmpersand(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('&array'); } public function testBadColon(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString(':array'); } public function testBadBrackets(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('max(a)'); } public function testMoreBadBrackets(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('max(a):void'); } public function testGeneratorWithWBadBrackets(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('Generator{string, A}'); } public function testBadEquals(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('=array'); } public function testBadBar(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('|array'); } public function testBadColonDash(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('array|string:-'); } public function testDoubleBar(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('PDO||Closure|numeric'); } @@ -942,7 +943,7 @@ class TypeParseTest extends TestCase public function testIntMaskWithInvalidClassConstant(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('int-mask'); } @@ -956,7 +957,7 @@ class TypeParseTest extends TestCase public function testIntMaskOfWithInvalidClassConstant(): void { - $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + $this->expectException(TypeParseTreeException::class); Type::parseString('int-mask-of'); } @@ -1021,7 +1022,7 @@ class TypeParseTest extends TestCase try { Type::parseString($return_type); - } catch (\Psalm\Exception\TypeParseTreeException $e) { + } catch (TypeParseTreeException $e) { self::assertTrue(false, $e . ' | ' . print_r($signature, true)); } } @@ -1033,7 +1034,7 @@ class TypeParseTest extends TestCase try { Type::parseString($param_type_1); - } catch (\Psalm\Exception\TypeParseTreeException $e) { + } catch (TypeParseTreeException $e) { self::assertTrue(false, $e . ' | ' . print_r($signature, true)); } } @@ -1041,7 +1042,7 @@ class TypeParseTest extends TestCase if ($param_type_2 && $param_type_2 !== 'mixed') { try { Type::parseString($param_type_2); - } catch (\Psalm\Exception\TypeParseTreeException $e) { + } catch (TypeParseTreeException $e) { self::assertTrue(false, $e . ' | ' . print_r($signature, true)); } } @@ -1049,7 +1050,7 @@ class TypeParseTest extends TestCase if ($param_type_3 && $param_type_3 !== 'mixed') { try { Type::parseString($param_type_3); - } catch (\Psalm\Exception\TypeParseTreeException $e) { + } catch (TypeParseTreeException $e) { self::assertTrue(false, $e . ' | ' . print_r($signature, true)); } } @@ -1057,7 +1058,7 @@ class TypeParseTest extends TestCase if ($param_type_4 && $param_type_4 !== 'mixed') { try { Type::parseString($param_type_4); - } catch (\Psalm\Exception\TypeParseTreeException $e) { + } catch (TypeParseTreeException $e) { self::assertTrue(false, $e . ' | ' . print_r($signature, true)); } } diff --git a/tests/UnusedCodeTest.php b/tests/UnusedCodeTest.php index c91471247..396481ebb 100644 --- a/tests/UnusedCodeTest.php +++ b/tests/UnusedCodeTest.php @@ -3,6 +3,7 @@ namespace Psalm\Tests; use Psalm\Config; use Psalm\Context; +use Psalm\Exception\CodeException; use Psalm\Internal\Analyzer\ProjectAnalyzer; use Psalm\Internal\Provider\FakeFileProvider; use Psalm\Internal\Provider\Providers; @@ -85,7 +86,7 @@ class UnusedCodeTest extends TestCase $this->markTestSkipped(); } - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessageRegExp('/\b' . \preg_quote($error_message, '/') . '\b/'); $file_path = self::$src_dir_path . 'somefile.php'; diff --git a/tests/UnusedVariableTest.php b/tests/UnusedVariableTest.php index abc06a709..0fc7cddc9 100644 --- a/tests/UnusedVariableTest.php +++ b/tests/UnusedVariableTest.php @@ -3,6 +3,7 @@ namespace Psalm\Tests; use Psalm\Config; use Psalm\Context; +use Psalm\Exception\CodeException; use Psalm\Internal\Analyzer\ProjectAnalyzer; use Psalm\Internal\Provider\FakeFileProvider; use Psalm\Internal\Provider\Providers; @@ -79,7 +80,7 @@ class UnusedVariableTest extends TestCase $this->markTestSkipped(); } - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->expectExceptionMessageRegExp('/\b' . preg_quote($error_message, '/') . '\b/'); $file_path = self::$src_dir_path . 'somefile.php'; diff --git a/tests/VariadicTest.php b/tests/VariadicTest.php index bf5a60693..44f536d53 100644 --- a/tests/VariadicTest.php +++ b/tests/VariadicTest.php @@ -3,6 +3,7 @@ namespace Psalm\Tests; use Psalm\Config; use Psalm\Context; +use Psalm\Exception\CodeException; use Psalm\Internal\Analyzer\ProjectAnalyzer; use Psalm\Internal\IncludeCollector; use Psalm\Internal\Provider\Providers; @@ -18,7 +19,7 @@ class VariadicTest extends TestCase public function testVariadicArrayBadParam(): void { $this->expectExceptionMessage('InvalidScalarArgument'); - $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectException(CodeException::class); $this->addFile( 'somefile.php', '