aik099 / CodingStandard

The PHP_CodeSniffer coding standard I'm using on all of my projects
BSD 3-Clause "New" or "Revised" License
5 stars 2 forks source link

Enforce "self" usage #88

Open aik099 opened 8 years ago

aik099 commented 8 years ago

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.