{"id":13610911,"url":"https://github.com/adoy/vim-php-refactoring-toolbox","last_synced_at":"2025-07-11T12:36:08.163Z","repository":{"id":20888564,"uuid":"24175902","full_name":"adoy/vim-php-refactoring-toolbox","owner":"adoy","description":"VIM Php Refactoring Toolbox","archived":false,"fork":false,"pushed_at":"2022-10-01T19:39:53.000Z","size":44,"stargazers_count":181,"open_issues_count":7,"forks_count":28,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-06-03T00:38:34.965Z","etag":null,"topics":["php","refactoring","refactoring-tools","vim"],"latest_commit_sha":null,"homepage":null,"language":"Vim script","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adoy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-18T05:59:37.000Z","updated_at":"2025-05-13T11:03:22.000Z","dependencies_parsed_at":"2023-01-11T21:00:44.802Z","dependency_job_id":null,"html_url":"https://github.com/adoy/vim-php-refactoring-toolbox","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/adoy/vim-php-refactoring-toolbox","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adoy%2Fvim-php-refactoring-toolbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adoy%2Fvim-php-refactoring-toolbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adoy%2Fvim-php-refactoring-toolbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adoy%2Fvim-php-refactoring-toolbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adoy","download_url":"https://codeload.github.com/adoy/vim-php-refactoring-toolbox/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adoy%2Fvim-php-refactoring-toolbox/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264808247,"owners_count":23666975,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","refactoring","refactoring-tools","vim"],"created_at":"2024-08-01T19:01:49.312Z","updated_at":"2025-07-11T12:36:08.123Z","avatar_url":"https://github.com/adoy.png","language":"Vim script","funding_links":[],"categories":["Vim Script"],"sub_categories":[],"readme":"# VIM Php Refactoring Toolbox\n\n[![License: MIT](https://img.shields.io/github/license/adoy/vim-php-refactoring-toolbox)](https://opensource.org/licenses/MIT)\n\nPHP Refactoring Toolbox for VIM\n\n* Rename Local Variable\n* Rename Class Variable\n* Rename Method\n* Extract Use\n* Extract Const\n* Extract Class Property\n* Extract Method\n* Create Property\n* Detect Unused Use Statements\n* Align Assigns\n* Create setters and getters\n* Document all code\n\n## Installation\n\n* [vim-plug](https://github.com/junegunn/vim-plug): `Plug 'adoy/vim-php-refactoring-toolbox'`\n* [vundle](https://github.com/gmarik/Vundle.vim): `Plugin 'adoy/vim-php-refactoring-toolbox'`\n* [pathogen](https://github.com/tpope/vim-pathogen): `git clone https://github.com/adoy/vim-php-refactoring-toolbox.git ~/.vim/bundle/`\n* or just copy the `plugin/php-refactoring-toolbox.vim` in your `~/.vim/plugin` folder\n\n\nIf you want to disable the default mapping just add this line in your `~/.vimrc` file\n\n```\nlet g:vim_php_refactoring_use_default_mapping = 0\n```\n\nIf you want to disable the user validation at the getter/setter creation, just add this line in your `~/.vimrc` file\n\n```\nlet g:vim_php_refactoring_auto_validate_sg = 1\n```\n\nIf you want to disable the user validation at getter only creation, just add this line in your `~/.vimrc` file\n\n```\nlet g:vim_php_refactoring_auto_validate_g = 1\n```\n\nIf you want to disable the user validation for all rename features, just add this line in your  `~/.vimrc` file\n\n```\nlet g:vim_php_refactoring_auto_validate_rename = 1\n```\n\nIf you want to disable the user validation for the visibility (private/public) add this line in your `~/.vimrc` file\n```\nlet g:vim_php_refactoring_auto_validate_visibility = 1\n```\n\nTo change the default visibility add one/both of those lines in your `~/.vimrc` file\n```\nlet g:vim_php_refactoring_default_property_visibility = 'private'\nlet g:vim_php_refactoring_default_method_visibility = 'private'\n```\n\nTo enable fluent setters add either of these lines to your `~/.vimrc` file\n```\n\" default is 0 -- disabled\n\n\" to enable for all setters\nlet g:vim_php_refactoring_make_setter_fluent = 1\n\n\" to enable but be prompted when creating the setter\nlet g:vim_php_refactoring_make_setter_fluent = 2\n```\n\n\n## Default Mappings\n\n    nnoremap \u003cunique\u003e \u003cLeader\u003erlv :call PhpRenameLocalVariable()\u003cCR\u003e\n    nnoremap \u003cunique\u003e \u003cLeader\u003ercv :call PhpRenameClassVariable()\u003cCR\u003e\n    nnoremap \u003cunique\u003e \u003cLeader\u003erm :call PhpRenameMethod()\u003cCR\u003e\n    nnoremap \u003cunique\u003e \u003cLeader\u003eeu :call PhpExtractUse()\u003cCR\u003e\n    vnoremap \u003cunique\u003e \u003cLeader\u003eec :call PhpExtractConst()\u003cCR\u003e\n    nnoremap \u003cunique\u003e \u003cLeader\u003eep :call PhpExtractClassProperty()\u003cCR\u003e\n    vnoremap \u003cunique\u003e \u003cLeader\u003eem :call PhpExtractMethod()\u003cCR\u003e\n    nnoremap \u003cunique\u003e \u003cLeader\u003enp :call PhpCreateProperty()\u003cCR\u003e\n    nnoremap \u003cunique\u003e \u003cLeader\u003edu :call PhpDetectUnusedUseStatements()\u003cCR\u003e\n    vnoremap \u003cunique\u003e \u003cLeader\u003e== :call PhpAlignAssigns()\u003cCR\u003e\n    nnoremap \u003cunique\u003e \u003cLeader\u003esg :call PhpCreateSettersAndGetters()\u003cCR\u003e\n    nnoremap \u003cunique\u003e \u003cLeader\u003ecog :call PhpCreateGetters()\u003cCR\u003e\n    nnoremap \u003cunique\u003e \u003cLeader\u003eda :call PhpDocAll()\u003cCR\u003e\n\n## Playground.php\n\nYou'll find in this project a `playground.php` file. You can use this file to start playing with this refactoring plugin.\n\n## Examples\n\n↑ Is the position of your cursor\n\n### Rename Local Variable\n\n``` php\n\u003c?php\nfunction helloWorld($foobar = null) {\n    echo \"Hello \" . $foobar;\n}                      ↑\n```\n\n`\u003cLeader\u003erlv` in normal mode, specify the new `$name`\n\n``` php\n\u003c?php\nfunction helloWorld($name = null) {\n    echo \"Hello \" . $name;\n}                      ↑\n```\n\n### Rename Class Variable\n\n``` php\n\u003c?php\nclass HelloWorld {\n    private $foobar;\n    public function __construct($name) {\n        $this-\u003efoobar = $name;\n    }\n    public function sayHello() {\n        echo $this-\u003efoobar;\n    }                 ↑\n}\n```\n\n`\u003cLeader\u003ercv` in normal mode, specify the new `$name`\n\n``` php\n\u003c?php\nclass HelloWorld {\n    private $name;\n    public function __construct($name) {\n        $this-\u003ename = $name;\n    }\n    public function sayHello() {\n        echo $this-\u003ename;\n    }\n}\n```\n\n### Rename method\n\n``` php\n\u003c?php\nclass HelloWorld {\n    public function sayHello() {\n        echo $this-\u003esayHello();\n    }                 ↑\n}\n```\n\n`\u003cLeader\u003erm` in normal mode, specify the new method name\n\n``` php\n\u003c?php\nclass HelloWorld {\n    public function newMethodName() {\n        echo $this-\u003enewMethodName();\n    }                 ↑\n}\n```\n\n### Extract Use Statement\n\n``` php\n\u003c?php\n$obj1 = new Foo\\Bar\\Baz;\n$obj2 = new Foo\\Bar\\Baz;\n                 ↑\n```\n\n`\u003cLeader\u003eeu` in normal mode\n\n``` php\n\u003c?php\n\nuse Foo\\Bar\\Baz;\n\n$obj1 = Baz;\n$obj2 = Baz;\n```\n\n### Extract Class Property\n\n``` php\n\u003c?php\n\nclass Dir {\n    public function __construct($path) {\n        $realpath = $path;\n    }       ↑\n}\n```\n\n`\u003cLeader\u003eep` in normal mode will extract the local variable and create a property inside the current class.\n\n``` php\n\u003c?php\n\nclass Dir {\n    private $realpath;\n    public function __construct($path) {\n        $this-\u003erealpath = $path;\n    }       ↑\n}\n```\n\n### Extract Method\n\n``` php\n\u003c?php\n\nclass HelloWorld {\n    public function sayHello($firstName = null) {\n        $sentence = 'Hello';\n        if ($firstName) {\n            $sentence .= ' ' . $firstName;\n        }\n        echo $sentence;\n    }\n}\n```\n\nSelect in visual mode (V) the code you want to extract in an other method and hit `\u003cLeader\u003eem`.\nYou'll be prompted for a method name. Enter a method name and press enter\n\n``` php\n\u003c?php\n\nclass HelloWorld {\n    public function sayHello($firstName = null) {\n        $sentence = $this-\u003eprepareSentence($firstName);\n        echo $sentence;\n    }\n\n    private function prepareSentence($firstName)\n    {\n        $sentence = 'Hello';\n        if ($firstName) {\n            $sentence .= ' ' . $firstName;\n        }\n        return $sentence;\n    }\n}\n```\n\n### Create Property\n\n`\u003cLeader\u003enp` will create a new property in your current class.\n\n### Detect unused \"use\" statements\n\n`\u003cLeader\u003edu` will detect all unused \"use\" statements in your code so that you can remove them.\n\n### Align assignments\n\n``` php\n\u003c?php\n\n$oneVar = 'Foo';\n$anOtherVar = 'Bar';\n$oneVar += 'Baz';\n```\n\nSelect the code you want to align and then hit `\u003cLeader\u003e==`\n\n``` php\n\u003c?php\n\n$oneVar     =  'Foo';\n$anOtherVar =  'Bar';\n$oneVar     += 'Baz';\n```\n\n### Create setters and getters\n\n``` php\n\u003c?php\n\nclass Foo {\n    private $bar;\n}\n```\n\nHit `\u003cLeader\u003esg` and you'll be prompted if you want to create setters and getters for existing properties and if you want to make the setter fluent.\n\n``` php\n\u003c?php\n\nclass Foo {\n    private $bar;\n\n    public function setBar($bar)\n    {\n        $this-\u003ebar = $bar;\n\n        return $this; // If you opted for a fluent setter at the prompt.\n    }\n\n    public function getBar()\n    {\n        return $this-\u003ebar;\n    }\n}\n```\n\n### Create only getters\n\n``` php\n\u003c?php\n\nclass Foo {\n    private $bar;\n}\n```\n\nHit `\u003cLeader\u003ecog` and you will be prompted if you want only getters for existing properties\n\n``` php\n\u003c?php\n\nclass Foo {\n    private $bar;\n\n    public function getBar()\n    {\n        return $this-\u003ebar;\n    }\n}\n```\n\n### Document all\n\n`\u003cLeader\u003eda` will call your documentation plugin (by default Php Documentor for vim https://github.com/tobyS/pdv) for every uncommented classes, methods, functions and properties.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadoy%2Fvim-php-refactoring-toolbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadoy%2Fvim-php-refactoring-toolbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadoy%2Fvim-php-refactoring-toolbox/lists"}