Commit 0090471
Clean up redundant assignment-conditions and repeated getArgs() calls (#11888)
* Clean up redundant assignment-conditions and repeated getArgs() calls
These tidy-ups were surfaced by running pzoom over the Psalm codebase;
each is behaviour-preserving and removes a real (if minor) code smell.
Redundant assignment-in-condition (always-truthy test):
several call providers test the result of a @psalm-mutation-free,
non-falsable getter inside a condition, e.g.
`... && ($x = $type->getArray()) && ($x instanceof TArray || ...)`.
Since getArray()/getSingleAtomic() can never return a falsy value, the
`&& ($x = ...)` operand is always true. Fold the assignment into the
adjacent instanceof test so the binding stays but the dead truthiness
check is gone (ArgumentsAnalyzer, ArrayFilter/Pop/Rand/Reverse/Splice,
FilterInput, FilterUtils). For in_array the getAtomicTypes() result is
unconditional, so hoist it to a plain statement.
Repeated memoized getArgs() -> local:
IncludeAnalyzer (dirname) and FunctionCallReturnTypeFetcher (preg_replace)
guard on `getArgs()`/`count(getArgs())` and then index `getArgs()[n]`,
calling the memoized method several times. Bind `$args = $stmt->getArgs()`
once and reuse it so the non-empty / length narrowing flows to the
indexed accesses.
GitInfoCollector::collectBranch:
after `str_starts_with($result, '* ')`, `explode('* ', $result, 2)[1]`
always equals `substr($result, 2)` but reads as a possibly-undefined
offset (baselined). Use substr() and drop the stale baseline entry.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014CUuwJRfj6cG8rqz8a34d2
* Satisfy PHPCS: null coalesce in in_array provider, dedupe options access in FilterUtils
- InArrayReturnTypeProvider: use `$types['array'] ?? null` instead of the
isset()-ternary (ShortTernary / null-coalesce sniff).
- FilterUtils: capture `$atomic_type->properties['options']` once as
`$options_type` (used 5x in the block), which also brings the folded
elseif condition back under the 120-char line limit.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014CUuwJRfj6cG8rqz8a34d2
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent be7afcf commit 0090471
14 files changed
Lines changed: 28 additions & 37 deletions
File tree
- src/Psalm/Internal
- Analyzer/Statements/Expression
- Call
- ExecutionEnvironment
- Provider
- ParamsProvider
- ReturnTypeProvider
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1676 | 1676 | | |
1677 | 1677 | | |
1678 | 1678 | | |
1679 | | - | |
1680 | 1679 | | |
1681 | 1680 | | |
1682 | 1681 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1644 | 1644 | | |
1645 | 1645 | | |
1646 | 1646 | | |
1647 | | - | |
1648 | | - | |
| 1647 | + | |
1649 | 1648 | | |
1650 | 1649 | | |
1651 | 1650 | | |
| |||
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
626 | 626 | | |
627 | 627 | | |
628 | 628 | | |
629 | | - | |
630 | | - | |
631 | | - | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
632 | 633 | | |
633 | 634 | | |
634 | 635 | | |
| |||
Lines changed: 7 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
353 | 353 | | |
354 | 354 | | |
355 | 355 | | |
356 | | - | |
| 356 | + | |
| 357 | + | |
357 | 358 | | |
358 | 359 | | |
359 | | - | |
360 | | - | |
361 | | - | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
362 | 363 | | |
363 | 364 | | |
364 | | - | |
| 365 | + | |
365 | 366 | | |
366 | 367 | | |
367 | 368 | | |
| |||
374 | 375 | | |
375 | 376 | | |
376 | 377 | | |
377 | | - | |
| 378 | + | |
378 | 379 | | |
379 | 380 | | |
380 | 381 | | |
| |||
Lines changed: 2 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | | - | |
68 | | - | |
69 | | - | |
| 68 | + | |
70 | 69 | | |
71 | 70 | | |
72 | 71 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
126 | | - | |
| 125 | + | |
127 | 126 | | |
128 | 127 | | |
129 | 128 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
77 | | - | |
| 76 | + | |
78 | 77 | | |
79 | 78 | | |
80 | 79 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | | - | |
| 48 | + | |
50 | 49 | | |
51 | 50 | | |
52 | 51 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
| 45 | + | |
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
| 51 | + | |
53 | 52 | | |
54 | 53 | | |
55 | 54 | | |
| |||
0 commit comments