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

SelfStaticAccessorFixer - Introduction #4358

Open
wants to merge 10 commits into
base: master
from

Conversation

Projects
None yet
2 participants
@SpacePossum
Copy link
Member

SpacePossum commented Apr 4, 2019

$ php php-cs-fixer describe self_static_accessor
Description of self_static_accessor rule.
Inside a final class or anonymous class `self::X` should be preferred to `static::X`.

Fixing examples:
 * Example #1.
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,15 +1,15 @@
    <?php
    final class Sample
    {
        private static $A = 1;
    
        public function getBar()
        {
   -        return static::class.static::test().static::$A;
   +        return self::class.self::test().self::$A;
        }
    
        private static function test()
        {
            return 'test';
        }
    }
   
   ----------- end diff -----------

 * Example #2.
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,7 +1,7 @@
    <?php
    $a = new class() {
        public function getBar()
        {
   -        return static::class;
   +        return self::class;
        }
    };
   
   ----------- end diff -----------

following:

@gharlan
Copy link
Contributor

gharlan left a comment

static:: inside of anonymous functions should be ignored, because of bindTo.

@gharlan
Copy link
Contributor

gharlan left a comment

Should this fixer also fix new static(); and $foo instanceof static?

Show resolved Hide resolved src/Fixer/ClassNotation/SelfStaticAccessorFixer.php Outdated
Show resolved Hide resolved src/Fixer/ClassNotation/SelfStaticAccessorFixer.php Outdated
Show resolved Hide resolved src/Fixer/ClassNotation/SelfStaticAccessorFixer.php Outdated
@SpacePossum

This comment has been minimized.

Copy link
Member Author

SpacePossum commented Apr 15, 2019

new static();

done

$foo instanceof static

TODO, done! thanks for the review! :)

@SpacePossum SpacePossum force-pushed the SpacePossum:master_/SelfStaticAccessorFixer branch from da3da19 to 49243cb Apr 15, 2019

SpacePossum added some commits Apr 15, 2019

@SpacePossum SpacePossum removed the WIP label Apr 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.