1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-03 18:17:55 +01:00
Commit Graph

3772 Commits

Author SHA1 Message Date
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
Bruce Weirdan
578046da4a
Merge pull request #10651 from edsrzf/missing-override 2024-02-05 07:16:40 -04:00
Bruce Weirdan
c40f232d31
Merge pull request #10629 from edsrzf/analyze-dynamic-fetches 2024-02-05 07:16:03 -04:00
Evan Shaw
a827806709 ParseError for dynamic constants before PHP 8.3 2024-02-05 21:49:40 +13:00
Bruce Weirdan
52eadab971
Late binding of enum cases
Resolves a number of long-standing bugs ('Failed to infer case value ...')

Fixes vimeo/psalm#10374
Fixes vimeo/psalm#10560
Fixes vimeo/psalm#10643
Fixes vimeo/psalm#8978
2024-02-05 04:12:19 +01:00
Bruce Weirdan
b2a2cd7884
Allow adding Closure as a native property type 2024-02-04 19:20:54 +01:00
Bruce Weirdan
e8b47f7d42
Do not add callable as a native property type
It's invalid in all PHP versions: https://3v4l.org/bXWo2

Also see php.net/manual/en/language.types.declarations.php#language.types.declarations.base.function

Fixes vimeo/psalm#10650
2024-02-04 18:52:20 +01:00
Evan Shaw
8396360d30 Emit MissingOverrideAttribute 2024-02-04 21:07:27 +13:00
Evan Shaw
ea9cb44699 Emit InvalidOverride 2024-02-04 09:01:30 +13:00
robchett
9d4fd4011d Support user defined types for psalm-check-type 2024-02-03 18:26:20 +00:00
robchett
526013e77e Fix check-type when using reserved types from within a namespace 2024-02-03 18:09:23 +00:00
robchett
421cb0f7a1
Allow enum cases to be global constants 2024-02-01 18:38:46 +01:00
Evan Shaw
88c2e00d02 Analyze dynamic class const names 2024-02-01 17:40:25 +13:00
Evan Shaw
a66aace523 Analyze dynamic static property names 2024-02-01 17:31:15 +13:00
Bruce Weirdan
6140f6881c
Allow typedef imports from any classlike type
All we really need is for the source to be autoloadable, and it includes
all classlikes (interfaces, classes, enums and traits at the time of
writing).
2024-01-31 23:07:23 +01:00
Bruce Weirdan
04ba9358e3
Merge pull request #10605 from edsrzf/php-parser-tweaks 2024-01-30 18:52:27 -04:00
Bruce Weirdan
ca9a12ddda
Report MissingConstructor for natively typed mixed properties
Fixes vimeo/psalm#10589
2024-01-30 17:24:27 +01:00
Bruce Weirdan
f045730927
Merge pull request #10598 from weirdan/key_exists-is-an-alias-for-array_key_exists 2024-01-29 16:23:35 -04:00
Bruce Weirdan
fd1294eef4
Merge pull request #10599 from weirdan/allow-properties-on-intersections-with-enum-interfaces 2024-01-29 16:23:20 -04:00
Bruce Weirdan
872cf58236
Merge pull request #10601 from weirdan/do-not-validate-callable-arguments-in-lenient-contexts 2024-01-29 16:22:47 -04:00
Evan Shaw
98d98be443 Re-work CheckTrivialExprVisitor
In php-parser 5.0, `ClosureUse` is no longer considered an expression.
This requires changes to Psalm's `CheckTrivialExprVisitor`, which stores
an array of "non-trivial" `Expr` nodes.

However the only use of this array is to count whether or not it's
empty. Instead of keeping the array, we can keep a boolean, and avoid
needing to change the types in this class when we upgrade to php-parser
5.0.
2024-01-29 13:25:25 +13:00
Evan Shaw
361ba65af0 Use flags key instead of type for ClassMethod 2024-01-28 14:12:26 +13:00
Bruce Weirdan
67a91e05b2
Do not validate callable arguments in lenient contexts
Fixes vimeo/psalm#10453
2024-01-27 16:38:37 +01:00
Bruce Weirdan
c1e22ddcaa
Allow properties on intersections with enum interfaces
Fixes vimeo/psalm#10585
2024-01-27 14:37:26 +01:00
Bruce Weirdan
6e2effaf9a
key_exists() is an alias for array_key_exists()
Fixes vimeo/psalm#10346
2024-01-27 13:41:43 +01:00
Evan Shaw
68a1d1e2b4 Switch condition order
This change is for forward-compatibility with nikic/php-parser 5.0,
where `InterpolatedStringPart` (née `EncapsedStringPart`) is no longer an expression.
Thus we can't pass it to `NodeTypeProvider::getType()` anymore. Since that call
returns `null` anyway, we can swap the condition order. Everything still
works and Psalm type-checking is happy.

This also might be a tiny performance improvement since it lets the
common, cheap instanceof check come before a method call, but I haven't actually
benchmarked it.
2024-01-24 15:38:39 -10:00
f7edaa66ac Fix #10552 2024-01-18 20:33:54 +01:00
kkmuffme
2414070849 simplify and remove redundant variable 2024-01-15 10:11:22 +01:00
kkmuffme
19b1a33a20 fix possibly undefined array key in keyed array doesnt include null when not validated
Fix https://psalm.dev/r/b153d0d248 to return 'a'|null instead of 'a' - this is required as otherwise empty would report RedundantCondition errors now which would bring back https://github.com/vimeo/psalm/issues/2681
2024-01-15 10:11:22 +01:00
kkmuffme
fb93aede12 create a separate issue type 2024-01-15 10:11:21 +01:00
kkmuffme
f3543ca9ab add the fix for empty() too and fix empty returning bool on true/false only cases hiding errors when functions called 2024-01-15 10:11:21 +01:00
kkmuffme
d5b713e439 Fix https://github.com/vimeo/psalm/issues/10501 - report error for non-strict comparison on truthy+falsy union 2024-01-15 10:11:21 +01:00
orklah
b9583493b0
Merge pull request #10499 from kkmuffme/fix-empty-string-becomes-non-empty-string-when-literal-strings-disabled
Fix empty literal string becomes non-empty-string
2024-01-14 23:41:50 +01:00
kkmuffme
02467fbb6a add support for extract to set variables for keyed arrays and respect EXTR_SKIP 2024-01-14 10:54:02 +01:00