1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Add more descriptive exception messages

This commit is contained in:
Matthew Brown 2017-09-20 08:43:54 -04:00
parent 1a9592fc62
commit e42e590442
3 changed files with 25 additions and 13 deletions

View File

@ -201,7 +201,7 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
if ($this->class instanceof PhpParser\Node\Stmt\Class_) {
if ($this->class->extends) {
if (!$this->parent_fq_class_name) {
throw new \UnexpectedValueException('Parent class should be filled in');
throw new \UnexpectedValueException('Parent class should be filled in for ' . $fq_class_name);
}
$parent_reference_location = new CodeLocation($this, $this->class->extends);
@ -462,7 +462,9 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
}
if (!isset(self::$trait_checkers[strtolower($fq_trait_name)])) {
throw new \UnexpectedValueException('Expecting trait statements to exist');
throw new \UnexpectedValueException(
'Expecting trait statements to exist for ' . $fq_trait_name
);
}
$trait_checker = self::$trait_checkers[strtolower($fq_trait_name)];
@ -689,7 +691,9 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
);
if (!isset(self::$trait_checkers[strtolower($fq_trait_name)])) {
throw new \UnexpectedValueException('Expecting trait statements to exist');
throw new \UnexpectedValueException(
'Expecting trait statements to exist for ' . $fq_trait_name
);
}
$trait_checker = self::$trait_checkers[strtolower($fq_trait_name)];
@ -810,7 +814,9 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
);
if (!isset(self::$trait_checkers[strtolower($fq_trait_name)])) {
throw new \UnexpectedValueException('Expecting trait statements to exist');
throw new \UnexpectedValueException(
'Expecting trait statements to exist for ' . $fq_trait_name
);
}
$trait_checker = self::$trait_checkers[strtolower($fq_trait_name)];

View File

@ -152,7 +152,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
$declaring_method_id = MethodChecker::getDeclaringMethodId($project_checker, $method_id);
if (!is_string($declaring_method_id)) {
throw new \UnexpectedValueException('$declaring_method_id should be a string');
throw new \UnexpectedValueException('The declaring method of ' . $method_id . ' should not be null');
}
$fq_class_name = (string)$context->self;
@ -719,14 +719,16 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
$declaring_method_id = MethodChecker::getDeclaringMethodId($project_checker, $function_id);
if (!$declaring_method_id) {
throw new \UnexpectedValueException('This should never happen');
throw new \UnexpectedValueException('The declaring method of ' . $function_id . ' should not be null');
}
return MethodChecker::getStorage($project_checker, $declaring_method_id);
}
if (!$this->statements_checker) {
throw new \UnexpectedValueException('This should not happen either');
throw new \UnexpectedValueException(
'$this->statements_checker should be defined when getting storage for ' . $function_id
);
}
return FunctionChecker::getStorage($this->statements_checker, $function_id);
@ -1208,7 +1210,9 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
$function_param_options = FunctionChecker::getParamsFromCallMap($declaring_method_id ?: $method_id);
if ($function_param_options === null) {
throw new \UnexpectedValueException('Not expecting $function_param_options to be null');
throw new \UnexpectedValueException(
'Not expecting $function_param_options to be null for ' . $method_id
);
}
return self::getMatchingParamsFromCallMapOptions($project_checker, $function_param_options, $args);
@ -1228,7 +1232,9 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
$function_param_options = FunctionChecker::getParamsFromCallMap($method_id);
if ($function_param_options === null) {
throw new \UnexpectedValueException('Not expecting $function_param_options to be null');
throw new \UnexpectedValueException(
'Not expecting $function_param_options to be null for ' . $method_id
);
}
return self::getMatchingParamsFromCallMapOptions($project_checker, $function_param_options, $args);

View File

@ -85,7 +85,7 @@ class MethodChecker extends FunctionLikeChecker
$storage = self::getStorage($project_checker, $method_id);
if (!$storage) {
throw new \UnexpectedValueException('$storage should not be null');
throw new \UnexpectedValueException('$storage should not be null for ' . $method_id);
}
if ($storage->return_type) {
@ -129,7 +129,7 @@ class MethodChecker extends FunctionLikeChecker
$storage = self::getStorage($project_checker, $method_id);
if (!$storage) {
throw new \UnexpectedValueException('$storage should not be null');
throw new \UnexpectedValueException('$storage should not be null for ' . $method_id);
}
if (!$storage->return_type_location) {
@ -498,7 +498,7 @@ class MethodChecker extends FunctionLikeChecker
$storage = self::getStorage($project_checker, $declaring_method_id);
if (!$storage) {
throw new \UnexpectedValueException('$storage should not be null');
throw new \UnexpectedValueException('$storage should not be null for ' . $declaring_method_id);
}
switch ($storage->visibility) {
@ -684,7 +684,7 @@ class MethodChecker extends FunctionLikeChecker
$storage = self::getStorage($project_checker, $method_id);
if (!$storage) {
throw new \UnexpectedValueException('$storage should not be null');
throw new \UnexpectedValueException('$storage should not be null for ' . $method_id);
}
list($fq_class_name) = explode('::', $method_id);