Skip to content
Permalink
Browse files

Identify invalid static property array assignment

  • Loading branch information
muglug committed Dec 27, 2019
1 parent 006f788 commit 2f2cd85a6aeb5ad36eaad4bd702f2c03e46b2b69
@@ -649,6 +649,16 @@ public static function updateArrayType(
return false;
}
}
} elseif ($root_array_expr instanceof PhpParser\Node\Expr\StaticPropertyFetch
&& $root_array_expr->name instanceof PhpParser\Node\Identifier
) {
PropertyAssignmentAnalyzer::analyzeStatic(
$statements_analyzer,
$root_array_expr,
null,
$root_type,
$context
);
} elseif ($root_var_id) {
$context->vars_in_scope[$root_var_id] = $root_type;
}
@@ -39,7 +39,8 @@
* snippet_from: int,
* snippet_to: int,
* column_from: int,
* column_to: int
* column_to: int,
* selected_text: string
* }
*
* @psalm-type TaggedCodeType = array<int, array{0: int, 1: string}>
@@ -34,7 +34,7 @@ class CallMap
private static $loaded_php_minor_version = null;

/**
* @var array<array<string,string>>|null
* @var array<array<int|string,string>>|null
*/
private static $call_map = null;

@@ -38,7 +38,8 @@
* snippet_from: int,
* snippet_to: int,
* column_from: int,
* column_to: int
* column_to: int,
* selected_text: string
* }
*
* @psalm-type PoolData = array{
@@ -25,7 +25,8 @@
* snippet_from: int,
* snippet_to: int,
* column_from: int,
* column_to: int
* column_to: int,
* selected_text: string
* }
*
* @psalm-type TaggedCodeType = array<int, array{0: int, 1: string}>
@@ -63,14 +64,7 @@ class FileReferenceProvider
private static $file_references_to_missing_class_members = [];

/**
* A lookup table used for getting all the files that reference any other file
*
* @var array<string,array<string,bool>>
*/
private static $referencing_files = [];

/**
* @var array<string, array<int,string>>
* @var array<string, array<string, true>>
*/
private static $files_inheriting_classes = [];

@@ -187,7 +181,6 @@ function ($file_name) {
*/
public function addFileReferenceToClass(string $source_file, string $fq_class_name_lc)
{
self::$referencing_files[$source_file] = true;
self::$file_references_to_classes[$fq_class_name_lc][$source_file] = true;
}

@@ -310,7 +303,7 @@ public function addMethodParamUse(string $method_id, int $offset, string $refere
/**
* @param string $file
*
* @return array
* @return array<int, string>
*/
private function calculateFilesReferencingFile(Codebase $codebase, $file)
{
@@ -333,7 +326,7 @@ private function calculateFilesReferencingFile(Codebase $codebase, $file)
/**
* @param string $file
*
* @return array
* @return array<int, string>
*/
private function calculateFilesInheritingFile(Codebase $codebase, $file)
{
@@ -1015,7 +1008,6 @@ public function getFileMaps()
public static function clearCache()
{
self::$file_references_to_classes = [];
self::$referencing_files = [];
self::$files_inheriting_classes = [];
self::$deleted_files = null;
self::$file_references = [];
@@ -349,7 +349,7 @@ public static function getErrorCount()
/**
* @param array<int, array{severity: string, line_from: int, line_to: int, type: string, message: string,
* file_name: string, file_path: string, snippet: string, from: int, to: int, snippet_from: int,
* snippet_to: int, column_from: int, column_to: int}> $issues_data
* snippet_to: int, column_from: int, column_to: int, selected_text: string}> $issues_data
*
* @return void
*/
@@ -952,9 +952,9 @@ public static function tokenize($string_type, $ignore_space = true)
$was_space = false;
}

/** @var list<array{0: string, 1: int}> $type_tokens */
self::$memoized_tokens[$string_type] = $type_tokens;

/** @var list<array{0: string, 1: int}> */
return $type_tokens;
}

@@ -2819,6 +2819,24 @@ function takesA(?A $a) : void {
}',
'error_message' => 'PossiblyNullArgument',
],
'catchBadArrayStaticProperty' => [
'<?php
namespace Bar;
class Foo {}
class A {
/** @var array<string, object> */
public array $map = [];
/**
* @param string $class
*/
public function get(string $class) : void {
$this->map[$class] = 5;
}
}',
'error_message' => 'InvalidPropertyAssignmentValue'
],
];
}
}

0 comments on commit 2f2cd85

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