Skip to content

Enforce "self" usage #88

@aik099

Description

@aik099

Detect class name usage inside that class declaration and suggest replacing it with self.

<?php

class TheExample
{
    const EXAMPLE = 1;

    public function createMe()
    {
        $instance = new TheExample();
        $constant = TheExample::EXAMPLE;
    }

}

Original idea came from Phabricator Xphast, where sniff was called Self Class Reference and in there only new ClassName constructs were checked. Error message was:

Use `self` to instantiate the current class.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions