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.
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>
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
```
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".
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.
```
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
```
Failed test:
```
1) MagicMethodAnnotationTest::testAnnotationWithoutCallConfigWithExtendsWithStatic
Failed asserting that exception of type "Psalm\Exception\CodeException" is thrown.
```
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.
```
List fail tests:
```
1) testMethodAnnotation with data set "static (string|int)[] getArray()"
Undefined array key 0
/workspaces/psalm/tests/ClassLikeDocblockParserTest.php:201
2) testMethodAnnotation with data set "static (callable() : string) getCallable()"
Undefined array key 0
/workspaces/psalm/tests/ClassLikeDocblockParserTest.php:201
```
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
Fixesvimeo/psalm#10650
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).
Filtering is not necessary. Clients using LSP should filter the results themselves.
That's what it says in the documentation.
This reverts commit d6faff2844.