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

Constructor readonly properties not detected as a PHP 8.1 feature #374

Closed
1 task done
llaville opened this issue Apr 23, 2024 · 2 comments
Closed
1 task done

Constructor readonly properties not detected as a PHP 8.1 feature #374

llaville opened this issue Apr 23, 2024 · 2 comments
Assignees
Labels

Comments

@llaville
Copy link
Owner

Bug report category

  • Feature issue.

Summary

Constructor readonly properties not detected as a PHP 8.1 feature.
Learn more with https://php.watch/versions/8.1/readonly#constructor-readonly

Expected behaviour

Detect constructor readonly properties with Bartlett\CompatInfo\Application\Sniffs\Classes\ReadonlyPropertySniff

Actual behaviour

Only class property in AST (with Node\Stmt\Property) is analysed.
Should also analyse in AST (the param list of Node\FunctionLike)

@llaville llaville added the bug label Apr 23, 2024
@llaville llaville self-assigned this Apr 23, 2024
@llaville
Copy link
Owner Author

Tests with https://github.com/llaville/php-compatinfo/releases/tag/7.1.3 on following source code.

<?php
class Test {
    public function __construct(public readonly string $prop) {
    }
}

analyser:run command returns with console reporter

[OK] Requires PHP 8.0.0alpha1 (min)

and on details with rule reporter

Stats
-----

 PHP 70 :   1 rule(s) found
 PHP 80 :   1 rule(s) found

Rules
-----

         code : CA7008
  description : Parameters Type Declaration 'string' is available since PHP 7.0.0
        sniff : ParamTypeDeclarationSniff
      methods : (1)
 Test\__construct

         code : CA8003
  description : Constructor property promotion is available since PHP 8.0.0
        sniff : PropertyPromotionSniff
      methods : (1)
 Test\__construct

While CA8102 rule should also be detected

llaville added a commit that referenced this issue Apr 23, 2024
@llaville
Copy link
Owner Author

Verifications are now done. Closing this report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant