All Projects → adoy → Vim Php Refactoring Toolbox

adoy / Vim Php Refactoring Toolbox

Licence: mit
VIM Php Refactoring Toolbox

Projects that are alternatives of or similar to Vim Php Refactoring Toolbox

Refactoring2 Zh
《重构 改善既有代码的设计第二版》中文翻译
Stars: ✭ 54 (-67.07%)
Mutual labels:  refactoring
Study Path
An organized learning path about Clean Code, Test-Driven Development, Legacy Code, Refactoring, Domain-Driven Design and Microservice Architecture
Stars: ✭ 1,357 (+727.44%)
Mutual labels:  refactoring
Xaml Code Experiences
A collection of the experiences I have collected during days of Xamarin and Wpf, while following the MVVM design pattern.
Stars: ✭ 114 (-30.49%)
Mutual labels:  refactoring
Dicas De Programacao Em Ruby
Dicas para iniciantes de boas práticas de desenvolvimento de software em Ruby
Stars: ✭ 59 (-64.02%)
Mutual labels:  refactoring
Vscode Glean
The extension provides refactoring tools for your React codebase
Stars: ✭ 1,194 (+628.05%)
Mutual labels:  refactoring
Typo3 Rector
Rector for TYPO3
Stars: ✭ 107 (-34.76%)
Mutual labels:  refactoring
Refactoring Aware Diff
RAID is a tool pipeline that seamlessly enriches GitHub diff results with refactoring information.
Stars: ✭ 50 (-69.51%)
Mutual labels:  refactoring
Cscout
C code refactoring browser
Stars: ✭ 139 (-15.24%)
Mutual labels:  refactoring
Refactoring101
The code here, represented as steps, is the progression of a refactoring on a legacy codebase. It is a PHP equivalent of the Java code shown in the Martin Fowler book "Refactoring".
Stars: ✭ 88 (-46.34%)
Mutual labels:  refactoring
Reftools
reftools - refactoring tools for Go
Stars: ✭ 113 (-31.1%)
Mutual labels:  refactoring
Scientist
A kotlin library for refactoring code. Port of GitHub's scientist.
Stars: ✭ 60 (-63.41%)
Mutual labels:  refactoring
Personal Goals
List of books I've read, projects I've done, videos I've seen, articles I've read or podcasts I've listened to.
Stars: ✭ 75 (-54.27%)
Mutual labels:  refactoring
Mort
Dead CSS detection
Stars: ✭ 109 (-33.54%)
Mutual labels:  refactoring
Cxxctp
DEPRECATED. USE INSTEAD github.com/blockspacer/flextool
Stars: ✭ 58 (-64.63%)
Mutual labels:  refactoring
Rewrite
Semantic code search and transformation
Stars: ✭ 134 (-18.29%)
Mutual labels:  refactoring
Experiment
A Go package for experimenting with and evaluating new code paths.
Stars: ✭ 51 (-68.9%)
Mutual labels:  refactoring
Splitjoin.vim
Switch between single-line and multiline forms of code
Stars: ✭ 1,383 (+743.29%)
Mutual labels:  refactoring
Refactoring Summary 2nd Javascript
Summary of "Refactoring: Improving the Design of Existing Code (2nd Edition)" by Martin Fowler
Stars: ✭ 142 (-13.41%)
Mutual labels:  refactoring
Piranha
A tool for refactoring code related to feature flag APIs
Stars: ✭ 1,840 (+1021.95%)
Mutual labels:  refactoring
Lemonj
一个面向 CSS/LESS/SCSS 的分析、坏味道检查和自动化重构工具。
Stars: ✭ 112 (-31.71%)
Mutual labels:  refactoring

VIM Php Refactoring Toolbox

License: MIT

PHP Refactoring Toolbox for VIM

  • Rename Local Variable
  • Rename Class Variable
  • Rename Method
  • Extract Use
  • Extract Const
  • Extract Class Property
  • Extract Method
  • Create Property
  • Detect Unused Use Statements
  • Align Assigns
  • Create setters and getters
  • Document all code

Installation

  • vim-plug: Plug 'adoy/vim-php-refactoring-toolbox'
  • vundle: Plugin 'adoy/vim-php-refactoring-toolbox'
  • pathogen: git clone https://github.com/adoy/vim-php-refactoring-toolbox.git ~/.vim/bundle/
  • or just copy the plugin/php-refactoring-toolbox.vim in your ~/.vim/plugin folder

If you want to disable the default mapping just add this line in your ~/.vimrc file

let g:vim_php_refactoring_use_default_mapping = 0

If you want to disable the user validation at the getter/setter creation, just add this line in your ~/.vimrc file

let g:vim_php_refactoring_auto_validate_sg = 1

If you want to disable the user validation at getter only creation, just add this line in your ~/.vimrc file

let g:vim_php_refactoring_auto_validate_g = 1

If you want to disable the user validation for all rename features, just add this line in your ~/.vimrc file

let g:vim_php_refactoring_auto_validate_rename = 1

If you want to disable the user validation for the visibility (private/public) add this line in your ~/.vimrc file

let g:vim_php_refactoring_auto_validate_visibility = 1

To change the default visibility add one/both of those lines in your ~/.vimrc file

let g:vim_php_refactoring_default_property_visibility = 'private'
let g:vim_php_refactoring_default_method_visibility = 'private'

To enable fluent setters add either of these lines to your ~/.vimrc file

" default is 0 -- disabled

" to enable for all setters
let g:vim_php_refactoring_make_setter_fluent = 1

" to enable but be prompted when creating the setter
let g:vim_php_refactoring_make_setter_fluent = 2

Default Mappings

nnoremap <unique> <Leader>rlv :call PhpRenameLocalVariable()<CR>
nnoremap <unique> <Leader>rcv :call PhpRenameClassVariable()<CR>
nnoremap <unique> <Leader>rm :call PhpRenameMethod()<CR>
nnoremap <unique> <Leader>eu :call PhpExtractUse()<CR>
vnoremap <unique> <Leader>ec :call PhpExtractConst()<CR>
nnoremap <unique> <Leader>ep :call PhpExtractClassProperty()<CR>
vnoremap <unique> <Leader>em :call PhpExtractMethod()<CR>
nnoremap <unique> <Leader>np :call PhpCreateProperty()<CR>
nnoremap <unique> <Leader>du :call PhpDetectUnusedUseStatements()<CR>
vnoremap <unique> <Leader>== :call PhpAlignAssigns()<CR>
nnoremap <unique> <Leader>sg :call PhpCreateSettersAndGetters()<CR>
nnoremap <unique> <Leader>cog :call PhpCreateGetters()<CR>
nnoremap <unique> <Leader>da :call PhpDocAll()<CR>

Playground.php

You'll find in this project a playground.php file. You can use this file to start playing with this refactoring plugin.

Examples

↑ Is the position of your cursor

Rename Local Variable

<?php
function helloWorld($foobar = null) {
    echo "Hello " . $foobar;
}                      

<Leader>rlv in normal mode, specify the new $name

<?php
function helloWorld($name = null) {
    echo "Hello " . $name;
}                      

Rename Class Variable

<?php
class HelloWorld {
    private $foobar;
    public function __construct($name) {
        $this->foobar = $name;
    }
    public function sayHello() {
        echo $this->foobar;
    }                 
}

<Leader>rcv in normal mode, specify the new $name

<?php
class HelloWorld {
    private $name;
    public function __construct($name) {
        $this->name = $name;
    }
    public function sayHello() {
        echo $this->name;
    }
}

Rename method

<?php
class HelloWorld {
    public function sayHello() {
        echo $this->sayHello();
    }                 
}

<Leader>rm in normal mode, specify the new method name

<?php
class HelloWorld {
    public function newMethodName() {
        echo $this->newMethodName();
    }                 
}

Extract Use Statement

<?php
$obj1 = new Foo\Bar\Baz;
$obj2 = new Foo\Bar\Baz;
                 

<Leader>eu in normal mode

<?php

use Foo\Bar\Baz;

$obj1 = Baz;
$obj2 = Baz;

Extract Class Property

<?php

class Dir {
    public function __construct($path) {
        $realpath = $path;
    }       
}

<Leader>ep in normal mode will extract the local variable and create a property inside the current class.

<?php

class Dir {
    private $realpath;
    public function __construct($path) {
        $this->realpath = $path;
    }       
}

Extract Method

<?php

class HelloWorld {
    public function sayHello($firstName = null) {
        $sentence = 'Hello';
        if ($firstName) {
            $sentence .= ' ' . $firstName;
        }
        echo $sentence;
    }
}

Select in visual mode (V) the code you want to extract in an other method and hit <Leader>em. You'll be prompted for a method name. Enter a method name and press enter

<?php

class HelloWorld {
    public function sayHello($firstName = null) {
        $sentence = $this->prepareSentence($firstName);
        echo $sentence;
    }

    private function prepareSentence($firstName)
    {
        $sentence = 'Hello';
        if ($firstName) {
            $sentence .= ' ' . $firstName;
        }
        return $sentence;
    }
}

Create Property

<Leader>np will create a new property in your current class.

Detect unused "use" statements

<Leader>du will detect all unused "use" statements in your code so that you can remove them.

Align assignments

<?php

$oneVar = 'Foo';
$anOtherVar = 'Bar';
$oneVar += 'Baz';

Select the code you want to align and then hit <Leader>==

<?php

$oneVar     =  'Foo';
$anOtherVar =  'Bar';
$oneVar     += 'Baz';

Create setters and getters

<?php

class Foo {
    private $bar;
}

Hit <Leader>sg 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.

<?php

class Foo {
    private $bar;

    public function setBar($bar)
    {
        $this->bar = $bar;

        return $this; // If you opted for a fluent setter at the prompt.
    }

    public function getBar()
    {
        return $this->bar;
    }
}

Create only getters

<?php

class Foo {
    private $bar;
}

Hit <Leader>cog and you will be prompted if you want only getters for existing properties

<?php

class Foo {
    private $bar;

    public function getBar()
    {
        return $this->bar;
    }
}

Document all

<Leader>da will call your documentation plugin (by default Php Documentor for vim https://github.com/tobyS/pdv) for every uncommented classes, methods, functions and properties.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].