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

Squiz.Scope.StaticThisUsage incorrectly looking inside anon classes #1776

Closed
pajon opened this issue Dec 10, 2017 · 1 comment
Closed

Squiz.Scope.StaticThisUsage incorrectly looking inside anon classes #1776

pajon opened this issue Dec 10, 2017 · 1 comment
Milestone

Comments

@pajon
Copy link

pajon commented Dec 10, 2017

Hello,

there is false positive error in StaticThisUsageSniff. Anonymous class definition inside static method with using $this variable, the sniff consider it as mistake.

Example code:

private static function functionExample(array $data)
{
    return new class()
    {
        private $data;

        public function __construct(array $data)
        {
            $this->data = $data;
        }
    };
}

Result:
Usage of "$this" in static methods will cause runtime errors

@gsherwood gsherwood added this to the 3.2.0 milestone Dec 10, 2017
@gsherwood gsherwood changed the title Wrong StaticThisUsageSniff with anonymous class Squiz.Scope.StaticThisUsage incorrectly looking inside anon classes Dec 10, 2017
gsherwood added a commit that referenced this issue Dec 10, 2017
@gsherwood
Copy link
Member

Thanks for reporting this. The sniff now skips anon classes.

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

No branches or pull requests

2 participants