File tree Expand file tree Collapse file tree 3 files changed +26
-18
lines changed
Internal/Analyzer/Statements/Block/IfElse Expand file tree Collapse file tree 3 files changed +26
-18
lines changed Original file line number Diff line number Diff line change 34
34
use function array_keys ;
35
35
use function array_merge ;
36
36
use function array_reduce ;
37
- use function array_unique ;
38
37
use function count ;
39
38
use function in_array ;
40
39
use function preg_match ;
41
40
use function preg_quote ;
42
41
use function spl_object_id ;
43
- use function strpos ;
44
- use function substr ;
45
42
46
43
/**
47
44
* @internal
@@ -272,20 +269,6 @@ public static function analyze(
272
269
array_keys ($ if_scope ->negated_types ),
273
270
);
274
271
275
- $ extra_vars_to_update = [];
276
-
277
- // if there's an object-like array in there, we also need to update the root array variable
278
- foreach ($ vars_to_update as $ var_id ) {
279
- $ bracked_pos = strpos ($ var_id , '[ ' );
280
- if ($ bracked_pos !== false ) {
281
- $ extra_vars_to_update [] = substr ($ var_id , 0 , $ bracked_pos );
282
- }
283
- }
284
-
285
- if ($ extra_vars_to_update ) {
286
- $ vars_to_update = array_unique (array_merge ($ extra_vars_to_update , $ vars_to_update ));
287
- }
288
-
289
272
$ outer_context ->update (
290
273
$ old_if_context ,
291
274
$ if_context ,
Original file line number Diff line number Diff line change 20
20
use Psalm \Issue \TypeDoesNotContainType ;
21
21
use Psalm \IssueBuffer ;
22
22
use Psalm \Storage \Assertion ;
23
+ use Psalm \Storage \Assertion \ArrayKeyDoesNotExist ;
23
24
use Psalm \Storage \Assertion \ArrayKeyExists ;
24
25
use Psalm \Storage \Assertion \Empty_ ;
25
26
use Psalm \Storage \Assertion \Falsy ;
@@ -197,7 +198,9 @@ public static function reconcileKeyedTypes(
197
198
$ is_equality = $ is_equality
198
199
&& $ new_type_part_part instanceof IsIdentical;
199
200
200
- $ has_inverted_isset = $ has_inverted_isset || $ new_type_part_part instanceof IsNotIsset;
201
+ $ has_inverted_isset = $ has_inverted_isset
202
+ || $ new_type_part_part instanceof IsNotIsset
203
+ || $ new_type_part_part instanceof ArrayKeyDoesNotExist;
201
204
202
205
$ has_count_check = $ has_count_check
203
206
|| $ new_type_part_part instanceof NonEmptyCountable;
Original file line number Diff line number Diff line change @@ -46,6 +46,28 @@ function three(array $a): void {
46
46
echo $a["a"];
47
47
echo $a["b"];
48
48
} ' ,
49
+ ],
50
+ 'arrayKeyExistsNegation ' => [
51
+ 'code ' => '<?php
52
+ function getMethodName(array $data = []): void {
53
+ if (\array_key_exists("custom_name", $data) && $data["custom_name"] !== null) {
54
+ }
55
+ /** @psalm-check-type-exact $data = array<array-key, mixed> */
56
+ }
57
+ ' ,
58
+ ],
59
+ 'arrayKeyExistsNoSideEffects ' => [
60
+ 'code ' => '<?php
61
+ function getMethodName(array $ddata = []): void {
62
+ if (\array_key_exists("redirect", $ddata)) {
63
+ return;
64
+ }
65
+ if (random_int(0, 1)) {
66
+ $ddata["type"] = "test";
67
+ }
68
+ /** @psalm-check-type-exact $ddata = array<array-key, mixed> */
69
+ }
70
+ ' ,
49
71
],
50
72
'arrayKeyExistsTwice ' => [
51
73
'code ' => '<?php
You can’t perform that action at this time.
0 commit comments