1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-11 08:49:52 +01:00
Commit Graph

14298 Commits

Author SHA1 Message Date
kkmuffme
4ac18720aa Revert https://github.com/vimeo/psalm/pull/10039 and fix type and test 2024-02-19 14:14:24 +01:00
kkmuffme
f035c00a21 Fix non-empty-lowercase-string handling with literal non-lowercase strings
* Fix https://github.com/vimeo/psalm/issues/9782 and related issues
* add explicit handling for non-falsy-string to not fallback non-falsy-string and 0 to string
2024-02-19 11:32:52 +01:00
Bruce Weirdan
d3c1222152
Merge pull request #10704 from issidorov/fix-detecting-magic-static-methods 2024-02-17 10:45:23 -04:00
Bruce Weirdan
5f2e9d1bd8
Merge branch '5.22.x' into 5.x 2024-02-15 23:54:45 +01:00
Bruce Weirdan
e9dad66e11
Merge pull request #10713 from weirdan/fix_psalm_type 2024-02-15 18:52:31 -04:00
Bruce Weirdan
03fcf68d9e
Allow multiple spaces between type name and type definition 2024-02-15 23:34:17 +01:00
893b60ed0d
Improve parsing of psalm-type 2024-02-15 23:34:16 +01:00
a05a3a8aa9
Merge pull request #10709 from vimeo/improve_randomizer
Improve randomizer stubs
2024-02-15 11:57:45 +01:00
b238bc7dc9 Improve randomizer stubs 2024-02-15 11:51:41 +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
5a66742e70 Failed and regression tests with suppression "UndefinedMethod"
Apply suggestions from code review.

Failed tests:
```
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
```

Co-authored-by: Bruce Weirdan <weirdan@gmail.com>
2024-02-14 22:17:26 +00:00
Ivan Sidorov
37240624f6 Fix description InvalidCodeAnalysisWithIssuesTestTrait
Co-authored-by: Bruce Weirdan <weirdan@gmail.com>
2024-02-14 22:17:26 +00:00
Ivan Sidorov
b7a20802da Fix description in InvalidCodeAnalysisWithIssuesTestTrait 2024-02-14 15:47:10 +00:00
Ivan Sidorov
08a479aede Rename to TestCase::assertHasIssue 2024-02-14 15:42:44 +00:00
Ivan Sidorov
cfd0fd1554 Use snake_case in TestCase::assertHasIssueType 2024-02-14 15:41:00 +00:00
Ivan Sidorov
db929912fe
Fix message in TestCase::assertHasIssueType
Apply suggestions from code review.

Co-authored-by: Bruce Weirdan <weirdan@gmail.com>
2024-02-14 09:57:24 +03:00
Ivan Sidorov
e940de5edd Resolve tests with creation of a list of issues
Resolved problems:
```
1) Psalm\Tests\MagicMethodAnnotationTest::testInvalidCodeWithIssues with data set "staticInvocationWithMagicMethodFoo"
UnexpectedValueException: Cannot get method params for A::foo

2) Psalm\Tests\MagicMethodAnnotationTest::testInvalidCodeWithIssues with data set "nonStaticSelfCallWithMagicMethodFoo"
UnexpectedValueException: Cannot get method params for B::foo
```
2024-02-13 17:25:16 +00:00
Ivan Sidorov
9b6ef8beef Failed and regression tests with creation of a list of issues
Failed tests:
```
1) Psalm\Tests\MagicMethodAnnotationTest::testInvalidCodeWithIssues with data set "staticInvocationWithMagicMethodFoo"
UnexpectedValueException: Cannot get method params for A::foo

2) Psalm\Tests\MagicMethodAnnotationTest::testInvalidCodeWithIssues with data set "nonStaticSelfCallWithMagicMethodFoo"
UnexpectedValueException: Cannot get method params for B::foo
```
2024-02-13 17:25:16 +00:00
Ivan Sidorov
d588b3d251 Support for testing with the creation of a list of issues
Description of motivation.

We currently have two different behaviors for the code related to
"CodeException":

```
$codebase->config->throw_exception = true; // or false
```

If "throw_exception" is set to `true`, code execution stops.

If "throw_exception" is set to `false`, the code may continue
to execute, and an error may potentially occur.

This commit allows testing for the second case, when the value of
"throw_exception" will be "false".
2024-02-13 17:25:16 +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
6f17469b24 Failed tests for StaticInvocation and NonStaticSelfCall
Failed tests:
```
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
6009631567 Fix invalid test
This test has been failed with an error "UndefinedMethod".
This error is being issued correctly.

But so that this error would not interfere with the test, it was suppressed.

Fixed 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
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
4fce0700bf Failed and regression tests with usage config
Failed test:
```
1) MagicMethodAnnotationTest::testAnnotationWithoutCallConfigWithExtendsWithStatic
Failed asserting that exception of type "Psalm\Exception\CodeException" is thrown.
```
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
Ivan Sidorov
29b4c38a94 Add argument with_pseudo for method finding 2024-02-13 17:25:16 +00:00
Ivan Sidorov
6e361aa9e6 Failed and regression tests for magic static methods
List failed tests:
```
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.
```
2024-02-13 17:25:16 +00:00
Bruce Weirdan
fe2c67ec89
Merge pull request #10699 from staabm/taint-doc 2024-02-13 10:22:51 -04:00
Markus Staab
f5fb9498de Use IssueBuffer::maybeAdd() instead of throwing 2024-02-13 09:11:11 +01:00
Markus Staab
c3526b4463 fix test 2024-02-12 14:04:50 +01:00
Markus Staab
da69803823 Report invalid number of arguments for psalm-taint-* 2024-02-12 10:46:45 +01: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
13ebb91caf
Merge pull request #10691 from weirdan/10170-reports-unknown-static-methods-in-first-class-callables 2024-02-11 16:28:23 -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
ceaea625f3
Merge pull request #10675 from robchett/prevent_nullable_mixed 2024-02-10 14:20:36 -04:00
Bruce Weirdan
2a063ff843
Merge pull request #10686 from weirdan/forbid-constructor-return-values 2024-02-09 20:56:17 -04:00
Bruce Weirdan
6b405937ab
Forbid constructors from returning any values
Fixes vimeo/psalm#9713
2024-02-10 01:34:51 +01:00
Bruce Weirdan
ba4e312594
Merge pull request #10678 from weirdan/10669-class-consts-in-shapes 2024-02-09 13:00:19 -04:00
robchett
5579fd469b Prevent mixed|null when function param is mixed with a null default value 2024-02-08 20:22:57 +00:00
Bruce Weirdan
2f0b85ff65
Support parsing constants in shapes
Fixes vimeo/psalm#10669
2024-02-08 04:30:42 +01:00
Bruce Weirdan
fa5f15058b
Merge pull request #10091 from vudaltsov/improve-refelection-stubs 2024-02-07 22:18:56 -04:00
Bruce Weirdan
f9a23149fe
Merge pull request #10679 from weirdan/8323-dont-show-backtrace-in-InvalidDocblock-issue-message 2024-02-07 22:00:01 -04:00
Bruce Weirdan
6b6bed5850
Don't show backtrace in InvalidDocblock issue message
Fixes vimeo/psalm#8323
2024-02-08 01:20:57 +01:00
Bruce Weirdan
aedea60827
Merge pull request #10677 from robchett/template_union_object_incorrect_assertions 2024-02-07 18:25:02 -04:00