Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix detecting magic static methods #10704

Merged
merged 22 commits into from Feb 17, 2024

Commits on Feb 13, 2024

  1. 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.
    ```
    issidorov committed Feb 13, 2024
    Configuration menu
    Copy the full SHA
    6e361aa View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    29b4c38 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    083b8e2 View commit details
    Browse the repository at this point in the history
  4. 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
         )
     )
    ```
    issidorov committed Feb 13, 2024
    Configuration menu
    Copy the full SHA
    2567a99 View commit details
    Browse the repository at this point in the history
  5. 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
         )
     )
     ```
    issidorov committed Feb 13, 2024
    Configuration menu
    Copy the full SHA
    df2067d View commit details
    Browse the repository at this point in the history
  6. 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
    ```
    issidorov committed Feb 13, 2024
    Configuration menu
    Copy the full SHA
    0ba346c View commit details
    Browse the repository at this point in the history
  7. Resolved all tests

    Resolved problem:
    
    ```
    1) MagicMethodAnnotationTest::testSealAllMethodsSetToFalseWithStatic
    Psalm\Exception\CodeException: UndefinedMagicMethod - somefile.php:8:15 - Magic method B::foo does not exist
    ```
    issidorov committed Feb 13, 2024
    Configuration menu
    Copy the full SHA
    5f89fa1 View commit details
    Browse the repository at this point in the history
  8. Failed and regression tests with usage config

    Failed test:
    ```
    1) MagicMethodAnnotationTest::testAnnotationWithoutCallConfigWithExtendsWithStatic
    Failed asserting that exception of type "Psalm\Exception\CodeException" is thrown.
    ```
    issidorov committed Feb 13, 2024
    Configuration menu
    Copy the full SHA
    4fce070 View commit details
    Browse the repository at this point in the history
  9. 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
    ```
    issidorov committed Feb 13, 2024
    Configuration menu
    Copy the full SHA
    14316f5 View commit details
    Browse the repository at this point in the history
  10. 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
    ```
    issidorov committed Feb 13, 2024
    Configuration menu
    Copy the full SHA
    6009631 View commit details
    Browse the repository at this point in the history
  11. 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.
    ```
    issidorov committed Feb 13, 2024
    Configuration menu
    Copy the full SHA
    6f17469 View commit details
    Browse the repository at this point in the history
  12. 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.
    ```
    issidorov committed Feb 13, 2024
    Configuration menu
    Copy the full SHA
    4c645e1 View commit details
    Browse the repository at this point in the history
  13. 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".
    issidorov committed Feb 13, 2024
    Configuration menu
    Copy the full SHA
    d588b3d View commit details
    Browse the repository at this point in the history
  14. 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
    ```
    issidorov committed Feb 13, 2024
    Configuration menu
    Copy the full SHA
    9b6ef8b View commit details
    Browse the repository at this point in the history
  15. 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
    ```
    issidorov committed Feb 13, 2024
    Configuration menu
    Copy the full SHA
    e940de5 View commit details
    Browse the repository at this point in the history

Commits on Feb 14, 2024

  1. Fix message in TestCase::assertHasIssueType

    Apply suggestions from code review.
    
    Co-authored-by: Bruce Weirdan <weirdan@gmail.com>
    issidorov and weirdan committed Feb 14, 2024
    Configuration menu
    Copy the full SHA
    db92991 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    cfd0fd1 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    08a479a View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    b7a2080 View commit details
    Browse the repository at this point in the history
  5. Fix description InvalidCodeAnalysisWithIssuesTestTrait

    Co-authored-by: Bruce Weirdan <weirdan@gmail.com>
    issidorov and weirdan committed Feb 14, 2024
    Configuration menu
    Copy the full SHA
    3724062 View commit details
    Browse the repository at this point in the history
  6. 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>
    issidorov and weirdan committed Feb 14, 2024
    Configuration menu
    Copy the full SHA
    5a66742 View commit details
    Browse the repository at this point in the history
  7. 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
    ```
    issidorov committed Feb 14, 2024
    Configuration menu
    Copy the full SHA
    8a70bc2 View commit details
    Browse the repository at this point in the history