1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 12:55:26 +01:00

Fix Psalm errors in Psalm

This commit is contained in:
Matthew Brown 2016-11-13 11:24:46 -05:00
parent 6d7dc41756
commit 38daca5edd
11 changed files with 52 additions and 21 deletions

View File

@ -220,8 +220,9 @@ abstract class ClassLikeChecker implements StatementsSource
}
/**
* @param bool $check_methods
* @param Context|null $class_context
* @param bool $check_methods
* @param Context|null $class_context
* @param bool $update_docblocks
* @return false|null
*/
public function check($check_methods = true, Context $class_context = null, $update_docblocks = false)
@ -858,7 +859,11 @@ abstract class ClassLikeChecker implements StatementsSource
*/
public function getAliasedClassesFlipped()
{
return $this->source->getAliasedClassesFlipped();
if ($this->source instanceof NamespaceChecker || $this->source instanceof FileChecker) {
return $this->source->getAliasedClassesFlipped();
}
return [];
}
/**

View File

@ -155,6 +155,7 @@ class FileChecker implements StatementsSource
* @param bool $check_functions
* @param Context|null $file_context
* @param bool $cache
* @param bool $update_docblocks
* @return array|null
*/
public function check(
@ -281,7 +282,7 @@ class FileChecker implements StatementsSource
if ($update_docblocks && isset(self::$docblock_return_types[$this->short_file_name])) {
$line_upset = 0;
$file_lines = explode(PHP_EOL, file_get_contents($this->real_file_name));
$file_lines = explode(PHP_EOL, (string)file_get_contents($this->real_file_name));
$file_docblock_updates = self::$docblock_return_types[$this->short_file_name];
@ -902,9 +903,10 @@ class FileChecker implements StatementsSource
/**
* Adds a docblock to the given file
* @param string $file_name
* @param int $line_number
* @param string $new_type
* @param string $file_name
* @param int $line_number
* @param string $new_type
* @return void
*/
public static function addDocblockReturnType($file_name, $line_number, $docblock, $new_type)
{
@ -917,6 +919,7 @@ class FileChecker implements StatementsSource
* @param array<int, string> $file_lines
* @param int $line_number
* @param int $line_upset
* @param string $existing_docblock
* @param string $type
* @return void
*/

View File

@ -355,7 +355,11 @@ abstract class FunctionLikeChecker implements StatementsSource
*/
public function getAliasedClassesFlipped()
{
return $this->source->getAliasedClassesFlipped();
if ($this->source instanceof NamespaceChecker || $this->source instanceof FileChecker || $this->source instanceof ClassLikeChecker) {
return $this->source->getAliasedClassesFlipped();
}
return [];
}
/**
@ -509,7 +513,7 @@ abstract class FunctionLikeChecker implements StatementsSource
$inferred_return_type = $inferred_yield_type;
}
if (!$method_return_types && $update_docblock) {
if (!$method_return_types) {
if ($inferred_return_type && !$inferred_return_type->isMixed()) {
FileChecker::addDocblockReturnType(
$this->file_name,

View File

@ -64,6 +64,7 @@ class NamespaceChecker implements StatementsSource
/**
* @param bool $check_classes
* @param bool $check_class_statements
* @param bool $update_docblocks
* @return void
*/
public function check($check_classes = true, $check_class_statements = true, $update_docblocks = false)

View File

@ -33,6 +33,7 @@ class ProjectChecker
/**
* @param boolean $debug
* @param boolean $is_diff
* @param boolean $update_docblocks
* @return void
*/
public static function check($debug = false, $is_diff = false, $update_docblocks = false)
@ -97,6 +98,7 @@ class ProjectChecker
/**
* @param string $dir_name
* @param boolean $debug
* @param boolean $update_docblocks
* @return void
*/
public static function checkDir($dir_name, $debug = false, $update_docblocks = false)
@ -119,6 +121,7 @@ class ProjectChecker
* @param string $dir_name
* @param Config $config
* @param bool $debug
* @param bool $update_docblocks
* @return void
*/
protected static function checkDirWithConfig($dir_name, Config $config, $debug, $update_docblocks)
@ -263,7 +266,8 @@ class ProjectChecker
/**
* @param string $file_name
* @param boolean $debug
* @param bool $debug
* @param bool $update_docblocks
* @return void
*/
public static function checkFile($file_name, $debug = false, $update_docblocks = false)

View File

@ -157,11 +157,11 @@ class StatementsChecker
break;
}
/*
if (isset($context->vars_in_scope['$columns'])) {
var_dump($stmt->getLine() . ' ' . $context->vars_in_scope['$columns']);
///*
if (isset($context->vars_in_scope['$value_types'])) {
var_dump($stmt->getLine() . ' ' . $context->vars_in_scope['$value_types']);
}
*/
//*/
if ($stmt instanceof PhpParser\Node\Stmt\If_) {
IfChecker::check($this, $stmt, $context, $loop_context);

View File

@ -446,7 +446,7 @@ abstract class Type
throw new \InvalidArgumentException('You must pass at least one type to combineTypes');
}
/** @var array<string, array<string, Union|null>> */
/** @var array<string, array<string, Union>> */
$key_types = [];
/** @var array<string, array<string, Union|null>> */
@ -548,7 +548,7 @@ abstract class Type
/**
* @param Atomic $type
* @param array<string, array<string, Union|null>> &$key_types
* @param array<string, array<string, Union>> &$key_types
* @param array<string, array<string, Union|null>> &$value_types
* @return null|Union
*/

View File

@ -30,6 +30,11 @@ class Atomic extends Type
return $this->value;
}
/**
* @param array<string> $aliased_classes
* @param string $this_class
* @return string
*/
public function toNamespacedString(array $aliased_classes, $this_class)
{
if ($this->value === $this_class) {

View File

@ -30,8 +30,8 @@ class Generic extends Atomic
implode(
', ',
array_map(
function ($type_param) {
return (string) $type_param;
function (Union $type_param) {
return (string)$type_param;
},
$this->type_params
)
@ -40,6 +40,8 @@ class Generic extends Atomic
}
/**
* @param array<string> $aliased_classes
* @param string $this_class
* @return string
*/
public function toNamespacedString(array $aliased_classes, $this_class)
@ -49,7 +51,7 @@ class Generic extends Atomic
implode(
', ',
array_map(
function ($type_param) use ($aliased_classes, $this_class) {
function (Union $type_param) use ($aliased_classes, $this_class) {
return $type_param->toNamespacedString($aliased_classes, $this_class);
},
$this->type_params

View File

@ -45,6 +45,8 @@ class ObjectLike extends Atomic
}
/**
* @param array<string> $aliased_classes
* @param string $this_class
* @return string
*/
public function toNamespacedString(array $aliased_classes, $this_class)
@ -54,7 +56,7 @@ class ObjectLike extends Atomic
implode(
', ',
array_map(
function ($name, $type) use ($aliased_classes, $this_class) {
function ($name, Union $type) use ($aliased_classes, $this_class) {
return $name . ':' . $type->toNamespacedString($aliased_classes, $this_class);
},
array_keys($this->properties),

View File

@ -41,12 +41,17 @@ class Union extends Type
);
}
/**
* @param array<string> $aliased_classes
* @param string $this_class
* @return string
*/
public function toNamespacedString(array $aliased_classes, $this_class)
{
return implode(
'|',
array_map(
function ($type) use ($aliased_classes, $this_class) {
function (Atomic $type) use ($aliased_classes, $this_class) {
return $type->toNamespacedString($aliased_classes, $this_class);
},
$this->types