1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 17:52:45 +01:00
Commit Graph

3805 Commits

Author SHA1 Message Date
kkmuffme
cd302f040b further improve string-int juggling handling which was previously already improved by me in https://github.com/vimeo/psalm/pull/10481
Also fix https://psalm.dev/r/3b401c6f88
2024-03-22 23:20:57 +01:00
kkmuffme
6030995d8d separate fix of https://github.com/vimeo/psalm/pull/10481 to a reusable function 2024-03-22 20:03:33 +01:00
Bruce Weirdan
4266a8e044
Merge pull request #10839 from kkmuffme/misc-class-callable-errors-not-reported 2024-03-20 05:51:34 +01:00
Bruce Weirdan
b47449fa89
Merge pull request #10817 from kkmuffme/promoted-properties-not-set-in-extended-constructor 2024-03-20 02:44:01 +01:00
Evan Shaw
86173d29c9 When inside isset, array fetch can return null
This prevents false positive for various types of issues inside empty,
such as RedundantConditionGivenDocblockType and TypeDoesNotContainType.
2024-03-20 02:18:31 +01:00
kkmuffme
9cfce37785 ParamNameMismatch not reported for __construct
Fix https://github.com/vimeo/psalm/issues/10784
2024-03-20 02:01:34 +01:00
Bruce Weirdan
98eab1fe23
Merge pull request #10822 from kkmuffme/report-param-name-mismatch-for-single-param-too 2024-03-20 01:34:53 +01:00
Bruce Weirdan
e3d55268f9
Merge pull request #10838 from kkmuffme/undefined-parent-not-reported-in-callable 2024-03-20 01:08:45 +01:00
kkmuffme
e83530a6c1 report invalid callable if callable cannot be called like this from current context
Fix https://github.com/vimeo/psalm/issues/10823
Fix https://github.com/vimeo/psalm/issues/8509
2024-03-20 01:02:54 +01:00
kkmuffme
a59248f5a1 self, parent and static in callable are deprecated since PHP 8.2
Fix https://github.com/vimeo/psalm/issues/10837
2024-03-20 01:02:54 +01:00
kkmuffme
ff168a9c7a Fix undefined parent not reported in callable
Fix https://github.com/vimeo/psalm/issues/10836
2024-03-16 21:45:24 +01:00
Ayesh Karunaratne
431977cb1d
[PHP 8.4] Fixes for implicit nullability deprecation
Fixes all issues that emits a deprecation notice on PHP 8.4.

See:
 - [RFC](https://wiki.php.net/rfc/deprecate-implicitly-nullable-types)
 - [PHP 8.4: Implicitly nullable parameter declarations deprecated](https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated)
2024-03-16 02:19:34 +07:00
kkmuffme
a2307aca81 report error for single param too since named args can even be used then 2024-03-13 19:27:57 +01:00
kkmuffme
9c5af0f494 Promoted properties missing in extended __construct should report PropertyNotSetInConstructor
Fix #10786
2024-03-13 14:57:20 +01:00
Ivan Sidorov
fe42e8821d
Resolve fail test #10807
Resolved problem:
```
Psalm\Tests\AssertAnnotationTest::testAssertsAllongCallStaticMethodWork
Psalm\Exception\CodeException: LessSpecificReturnStatement
The type 'string' is more general than the declared return type 'non-empty-string' for returnNonEmpty
```
2024-03-11 20:09:30 +01:00
Bruce Weirdan
8e1aa46195 CS fix
- trailing commas in calls with anon functions
- useless array docblock

Refs 8d0f603bef
Refs 6ea0278a67
2024-03-09 18:41:51 +01:00
Bruce Weirdan
6b9b4b523d Namespace anonymous classes
Fixes vimeo/psalm#10755
2024-03-03 16:21:20 +01:00
Theodore Brown
e357b972f6 Avoid duplicating code for RiskyTruthyFalsyComparison 2024-02-29 20:38:40 -06:00
Evan Shaw
22f32c1392 Set inside_isset = false when analyzing arguments 2024-02-27 22:30:10 +13:00
Bruce Weirdan
60badd0a93
Merge pull request #10752 from edsrzf/array-isset-disable-dim 2024-02-27 01:11:12 +01:00
Bruce Weirdan
0ce62a51ec Let's see what breaks without this hack 2024-02-27 01:04:03 +01:00
Bruce Weirdan
27461c98f6 Strip null used to signify completed iterations in foreach context
Even though `Generator::current()` can return `null` once generator is
exhausted, `foreach()` never iterates after iterator ends, so we can
safely remove `null` (unless, of course, generator can yield `null`).
2024-02-27 01:04:03 +01:00
Bruce Weirdan
8a0bc19fa6 Forbid iterating over generators with non-nullable send()
Fixes vimeo/psalm#6985
2024-02-27 01:04:03 +01:00
Bruce Weirdan
e9ea999f50
Merge pull request #10738 from MelechMizrachi/vimeo-fix-long-array-consts-false-flag 2024-02-27 00:40:20 +01:00
Evan Shaw
3535324842 Fix new errors 2024-02-26 21:47:05 +13:00
Evan Shaw
10ed0f3cd6 Set inside_isset false when analyzing ArrayDimFetch dim 2024-02-26 21:47:05 +13:00
Oliver Hader
de7b65ea8a
Use TaintKind/TaintKindGroup constants instead of string values 2024-02-24 16:31:52 +01:00
Melech Mizrachi
f553392454 Fix a false flag issue with InvalidConstantAssignmentValue being thrown for constants over a certain length. Usually happens with arrays or lists over 100+ entries in length.
Check if this type was defined via a dockblock or type hint otherwise the inferred type should always match the assigned type, and we don't even need to do additional checks
There is an issue with constants over a certain length where additional values are added to fallback_params in the assigned_type but not in const_storage_type which causes a false flag for this error to appear. Usually happens with arrays/lists.

Added two separate tests to cover both lists, and arrays to ensure this issue is fixed.
2024-02-23 11:25:34 -07:00
Bruce Weirdan
4a5f433831
Merge pull request #10729 from ohader/revert-10242-5.x 2024-02-21 17:07:02 -04:00
kkmuffme
9d8080096c Fix RiskyTruthyFalsyComparison reporting irrelevant errors when there is no explicit truthy/falsy type 2024-02-20 22:28:12 +01:00
Oliver Hader
679aaf0939
Revert "Allow tainted numerics except for 'html' and 'has_quotes'" 2024-02-20 13:55:31 +01:00
Oliver Hader
1ff41e68a0
Drop superfluous fetching of statements from event 2024-02-20 00:22:14 +01:00
Oliver Hader
2943cfe11d
Add list of statements to BeforeFileAnalysisEvent
Fixes: #10725
2024-02-20 00:00:27 +01:00
Ivan Sidorov
8a70bc2506 Resolve tests with suppression "UndefinedMethod"
Apply suggestions from code review.

Resolved problems:
```
1) MagicMethodAnnotationTest::testValidCode with data set "magicStaticMethodInheritanceWithoutCallStatic"
Psalm\Exception\CodeException: UnusedPsalmSuppress - src/somefile.php:9:58 - This suppression is never used

2) MagicMethodAnnotationTest::testValidCode with data set "magicStaticMethodInheritanceWithoutCallStatic_WithReturnAndManyArgs"
Psalm\Exception\CodeException: TooManyArguments - src/somefile.php:9:6 - Too many arguments for B::bar - expecting 0 but saw 2
```
2024-02-14 22:17:26 +00:00
Ivan Sidorov
4c645e186c Resolve tests for StaticInvocation and NonStaticSelfCall
The code has been moved from down to up.

Resolved problems:
```
1) MagicMethodAnnotationTest::testInvalidCode with data set "staticInvocationWithInstanceMethodFoo"
Failed asserting that exception of type "Psalm\Exception\CodeException" is thrown.

2) MagicMethodAnnotationTest::testInvalidCode with data set "nonStaticSelfCallWithInstanceMethodFoo"
Failed asserting that exception of type "Psalm\Exception\CodeException" is thrown.
```
2024-02-13 17:25:16 +00:00
Ivan Sidorov
14316f55ba Resolve testAnnotationWithoutCallConfigWithExtendsWithStatic
Resolved error:
```
MagicMethodAnnotationTest::testAnnotationWithoutCallConfigWithExtendsWithStatic
Failed asserting that exception of type "Psalm\Exception\CodeException" is thrown.
```

Appended problem:
```
MagicMethodAnnotationTest::testValidCode with data set "magicStaticMethodInheritanceWithoutCallStatic"
Psalm\Exception\CodeException: UndefinedMethod - src/somefile.php:9:32 - Method B::bar does not exist
```
2024-02-13 17:25:16 +00:00
Ivan Sidorov
5f89fa1730 Resolved all tests
Resolved problem:

```
1) MagicMethodAnnotationTest::testSealAllMethodsSetToFalseWithStatic
Psalm\Exception\CodeException: UndefinedMagicMethod - somefile.php:8:15 - Magic method B::foo does not exist
```
2024-02-13 17:25:16 +00:00
Ivan Sidorov
0ba346c5a0 Delete code of replacing variable method_id
The main task for deleting:
```
$method_id = new MethodIdentifier(
    $fq_class_name,
    '__callstatic',
);
```

List of resolved problems:
```
1) Psalm\Tests\MagicMethodAnnotationTest::testNoSealAllMethodsWithStatic
Failed asserting that exception of type "Psalm\Exception\CodeException" is thrown.

2) Psalm\Tests\MagicMethodAnnotationTest::testSealAllMethodsWithoutFooWithStatic
Failed asserting that exception of type "Psalm\Exception\CodeException" is thrown.

3) Psalm\Tests\MagicMethodAnnotationTest::testInvalidCode with data set "inheritSealedMethodsWithStatic"
Failed asserting that exception of type "Psalm\Exception\CodeException" is thrown.
```

Appended problem by that fix:
```
1) MagicMethodAnnotationTest::testSealAllMethodsSetToFalseWithStatic
Psalm\Exception\CodeException: UndefinedMagicMethod - somefile.php:8:15 - Magic method B::foo does not exist
```
2024-02-13 17:25:16 +00:00
Ivan Sidorov
df2067dd74 Resolve testReferencedMethods
Resolved problem:
```
FileReferenceTest::testReferencedMethods with data set "getClassReferences"
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
         'foo\b::__construct' => true
         'foo\c::foo' => true
     )
-    'foo\c::__construct' => Array &2 (
+    'foo\a::__callstatic' => Array &2 (
+        'foo\b::__construct' => true
+    )
+    'foo\c::__construct' => Array &3 (
         'foo\b::bar' => true
     )
 )
 ```
2024-02-13 17:25:16 +00:00
Ivan Sidorov
2567a99347 Extract checking method "__callStatic" from block "if"
Appended problem by that commit:
```
1) FileReferenceTest::testReferencedMethods with data set "getClassReferences"
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
         'foo\b::__construct' => true
         'foo\c::foo' => true
     )
-    'foo\c::__construct' => Array &2 (
+    'foo\a::__callstatic' => Array &2 (
+        'foo\b::__construct' => true
+    )
+    'foo\c::__construct' => Array &3 (
         'foo\b::bar' => true
     )
 )
```
2024-02-13 17:25:16 +00:00
Ivan Sidorov
083b8e26db Add issue message for magic methods 2024-02-13 17:25:16 +00:00
Bruce Weirdan
395f3f7862
Merge pull request #10690 from weirdan/9649-this-out-on-constructors 2024-02-11 16:34:25 -04:00
Bruce Weirdan
a8c093aea2
Handle taking references to unspecified magic methods 2024-02-11 02:45:24 +01:00
Bruce Weirdan
d10e384338
Report first class callables generated for unknown static methods
Fixes vimeo/psalm#10170
2024-02-11 02:24:27 +01:00
Bruce Weirdan
def0489b98
Process @psalm-this-out on __construct() as well
Fixes vimeo/psalm#9649
2024-02-11 01:53:30 +01:00
Bruce Weirdan
6b405937ab
Forbid constructors from returning any values
Fixes vimeo/psalm#9713
2024-02-10 01:34:51 +01:00
Bruce Weirdan
508da9abd4
Merge pull request #10661 from vimeo/10018-flag-stdclass-constructor-with-arguments 2024-02-05 20:31:26 -04:00
Bruce Weirdan
62b525993d
Flag stdClass::__construct() calls that have arguments
Fixes vimeo/psalm#10018
2024-02-06 01:24:18 +01:00
Bruce Weirdan
b822c3339d
Suppress UndefinedClass in whatever_exists()
Fixes vimeo/psalm#7395
2024-02-05 20:44:09 +01:00
Bruce Weirdan
f40e23faef
Merge pull request #10655 from weirdan/late-binding-of-enum-properties 2024-02-05 15:17:42 -04:00