Skip to content
Permalink
Browse files

Fix Psalm errors

  • Loading branch information
muglug committed Nov 21, 2019
1 parent 06653f6 commit 78a38944031dcb7596a5643aae658619422d81a8
Showing with 30 additions and 38 deletions.
  1. +2 −2 src/Psalm/Internal/Analyzer/CommentAnalyzer.php
  2. +6 −4 src/Psalm/Type.php
  3. +22 −32 tests/AnnotationTest.php
@@ -227,7 +227,7 @@ public static function arrayToDocblocks(
*
* @throws DocblockParseException if there was a problem parsing the docblock
*
* @return array<string, array<int, array{0: string, 1: int}>>
* @return array<string, list<array{0: string, 1: int}>>
*/
public static function getTypeAliasesFromComment(
PhpParser\Comment\Doc $comment,
@@ -254,7 +254,7 @@ public static function getTypeAliasesFromComment(
*
* @throws DocblockParseException if there was a problem parsing the docblock
*
* @return array<string, array<int, array{0: string, 1: int}>>
* @return array<string, list<array{0: string, 1: int}>>
*/
private static function getTypeAliasesFromCommentLines(
array $type_alias_comment_lines,
@@ -111,7 +111,7 @@ abstract class Type
];
/**
* @var array<string, array<int, array{0: string, 1: int}>>
* @var array<string, list<array{0: string, 1: int}>>
*/
private static $memoized_tokens = [];
@@ -151,7 +151,7 @@ public static function parseTokens(
// Note: valid identifiers can include class names or $this
if (!preg_match('@^(\$this|\\\\?[a-zA-Z_\x7f-\xff][\\\\\-0-9a-zA-Z_\x7f-\xff]*)$@', $only_token[0])) {
if (!is_numeric($only_token)
if (!\is_numeric($only_token[0])
&& strpos($only_token[0], '\'') !== false
&& strpos($only_token[0], '"') !== false
) {
@@ -776,7 +776,7 @@ private static function getGenericParamClass(
* @param string $string_type
* @param bool $ignore_space
*
* @return array<int, array{0: string, 1: int}>
* @return list<array{0: string, 1: int}>
*/
public static function tokenize($string_type, $ignore_space = true)
{
@@ -946,14 +946,15 @@ public static function tokenize($string_type, $ignore_space = true)
self::$memoized_tokens[$string_type] = $type_tokens;
/** @var list<array{0: string, 1: int}> */
return $type_tokens;
}
/**
* @param array<string, mixed>|null $template_type_map
* @param array<string, array<int, array{0: string, 1: int}>>|null $type_aliases
*
* @return array<int, array{0: string, 1: int}>
* @return list<array{0: string, 1: int}>
*/
public static function fixUpLocalType(
string $string_type,
@@ -1065,6 +1066,7 @@ public static function fixUpLocalType(
}
}
/** @var list<array{0: string, 1: int}> */
return $type_tokens;
}
@@ -1011,6 +1011,27 @@ function foo(array $foo) : int {
*/
$foo = ["foo" => "", "bar" => "", "baz" => ""];',
],
'returnNumber' => [
'<?php
class C {
/**
* @return 1
*/
public static function barBar() {
return 1;
}
}',
],
'returnNumberForInterface' => [
'<?php
interface I {
/**
* @return 1
*/
public static function barBar();
}',
'error_message' => 'InvalidDocblock',
],
];
}
@@ -1032,18 +1053,7 @@ public function barBar() {
}',
'error_message' => 'MissingDocblockType',
],
'invalidClassMethodReturnClass' => [
'<?php
class C {
/**
* @return 1
*/
public static function barBar() {
return 1;
}
}',
'error_message' => 'InvalidDocblock',
],
'invalidClassMethodReturnBrackets' => [
'<?php
class C {
@@ -1066,16 +1076,6 @@ public static function barBar();
}',
'error_message' => 'MissingDocblockType',
],
'invalidInterfaceMethodReturnClass' => [
'<?php
interface I {
/**
* @return 1
*/
public static function barBar();
}',
'error_message' => 'InvalidDocblock',
],
'invalidInterfaceMethodReturnBrackets' => [
'<?php
interface I {
@@ -1086,16 +1086,6 @@ public static function barBar();
}',
'error_message' => 'InvalidDocblock',
],
'invalidPropertyClass' => [
'<?php
class A {
/**
* @var 1
*/
public $bar;
}',
'error_message' => 'InvalidDocblock',
],
'invalidPropertyBrackets' => [
'<?php
class A {

0 comments on commit 78a3894

Please sign in to comment.
You can’t perform that action at this time.