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

14224 Commits

Author SHA1 Message Date
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
Bruce Weirdan
71707e6c4e
Merge pull request #10748 from weirdan/10747-fix-loading-stubs-from-phar-on-windows
Fix loading stubs from phar file on Windows
2024-02-25 14:35:17 +01:00
Bruce Weirdan
eb9e8d96cf
Merge pull request #10749 from weirdan/6449-skip-symlink-test-on-windows
Skip symlink test on Windows
2024-02-25 14:34:30 +01:00
Bruce Weirdan
57caade0d1 Skip symlink test on Windows
Fixes vimeo/psalm#6449

Symlinks on Windows are rare (and quite unreliable)
2024-02-25 14:29:20 +01:00
Bruce Weirdan
01dc2fef84 Fix loading stubs from phar file on Windows
Fixes vimeo/psalm#10747
2024-02-25 13:58:32 +01:00
Bruce Weirdan
6c10ad2355
Merge pull request #10746 from ohader/taint-kind-const-5.x
Use TaintKind/TaintKindGroup constants instead of string values
2024-02-25 11:11:55 +01: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
eeffee7aae
Merge branch '5.22.x' into 5.x 2024-02-23 00:41:03 +01:00
Bruce Weirdan
d768d91415
Merge pull request #10720 from vimeo/10706-catch-intersection-exceptions-during-scanning 2024-02-22 19:39:07 -04:00
Oliver Hader
4b827d3847
Add more tests for native intersection types in class properties 2024-02-23 00:33:46 +01:00
Bruce Weirdan
7bd35be5d5
Catch missing classlike exceptions during scanning
This may resolve #10706, although I'm not exactly convinced it's the
best way.
2024-02-23 00:33:42 +01:00
Bruce Weirdan
4a5f433831
Merge pull request #10729 from ohader/revert-10242-5.x 2024-02-21 17:07:02 -04:00
Bruce Weirdan
2b642804b7
Merge pull request #10734 from weirdan/override-attribute-in-pure-context
Allow `Override` attribute to be used in pure contexts
2024-02-21 15:55:32 -04:00
Bruce Weirdan
3cd9658d29
Allow Override attribute to be used in pure contexts
Fixes vimeo/psalm#10731
2024-02-21 12:25:30 +01:00
Bruce Weirdan
c401490265
Merge pull request #10733 from kkmuffme/fix-false-positive-riskytruthyfalsycomparison 2024-02-21 07:03:07 -04:00
kkmuffme
e482c078a7 code style whitespace fixes including for unrelated tests 2024-02-20 22:28:12 +01: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
Bruce Weirdan
503ccd8235
Merge pull request #10722 from kkmuffme/fix-uppercase-non-empty-lowercase-and-falsy-in-loop 2024-02-20 07:07:09 -04:00
Bruce Weirdan
6129891cc7
Merge pull request #10728 from ohader/10725-before-file-analysis-event-stmts 2024-02-19 19:37:42 -04: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
Bruce Weirdan
a97a121f1e
Merge pull request #10726 from gsteel/sensitive-parameter 2024-02-19 17:12:49 -04:00
George Steel
407c8b3084
Update PHP 8.2 stubs to include SensitiveParameterValue
Signed-off-by: George Steel <george@net-glue.co.uk>
2024-02-19 17:59:38 +00:00
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