PHPackages                             qafoolabs/php-refactoring-browser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. qafoolabs/php-refactoring-browser

Abandoned → [rector/rector](/?search=rector%2Frector)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

qafoolabs/php-refactoring-browser
=================================

Refactoring Browser for PHP

v0.1(11y ago)54725139[23 issues](https://github.com/QafooLabs/php-refactoring-browser/issues)[5 PRs](https://github.com/QafooLabs/php-refactoring-browser/pulls)Apache2PHP

Since Apr 3Pushed 8y ago37 watchersCompare

[ Source](https://github.com/QafooLabs/php-refactoring-browser)[ Packagist](https://packagist.org/packages/qafoolabs/php-refactoring-browser)[ RSS](/packages/qafoolabs-php-refactoring-browser/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (3)Dependencies (11)Versions (6)Used By (0)

PHP Refactoring Browser
=======================

[](#php-refactoring-browser)

```
Note: This software is under development and in alpha state. Refactorings
do not contain all necessary pre-conditions and might mess up your code.
Check the diffs carefully before applying the patches.

```

[![Build Status](https://camo.githubusercontent.com/632699102551b1ace8d34946f1635d720fb093c4020b1685dc59241e6c5a1a7d/68747470733a2f2f7472617669732d63692e6f72672f5161666f6f4c6162732f7068702d7265666163746f72696e672d62726f777365722e706e67)](https://travis-ci.org/QafooLabs/php-refactoring-browser)

Automatic Refactorings for PHP Code by generating diffs that describe the refactorings steps. To prevent simple mistakes during refactorings, an automated tool is a great.

See a [screenshot of extract-method in action](docs/extract_method.png).

The library is standing on the shoulder of giants, using multiple existing libraries:

- [PHP Parser](https://github.com/nikic/PHP-Parser) by Nikic
- [PHP Token Reflection](https://github.com/Andrewsville/PHP-Token-Reflection) from Ondřej Nešpor

Based on data from these sources the Refactoring Browser consists of two distinct components:

- `Patches` allows to build patches based on change operations on a file.
- `Refactoring` contains the actual Refactoring domain and adapters to third party libraries.
- `Collections` adds some collection semantics on top of PHP arrays. Currently contains a Set type.

Install &amp; Basic Usage
-------------------------

[](#install--basic-usage)

[Download PHAR](https://github.com/QafooLabs/php-refactoring-browser/releases)

The refactoring browser is used with:

```
php refactor.phar  ...

```

It outputs a diff to the screen and you can apply it to your code by piping it to `patch -p1`:

```
php refactor.phar  ... | patch -p1

```

### Editor Plugins

[](#editor-plugins)

There are third-party plugins available for using PHP refactorings within different text editors. These separately maintained projects can be found at the links below:

- vim :
- emacs :

Why?
----

[](#why)

Users of PHPStorm (or Netbeans) might wonder why this project exists, all the refactorings are available in this IDE. We feel there are several reasons to have such a tool in PHP natively:

- We are VIM users and don't want to use an IDE for refactorings. Also we are independent of an IDE and users of any (non PHP Storm) editor can now benefit from the practice of automated refactorings.
- The non-existence of a simple refactoring tool leads to programmers not refactoring "just to be safe". This hurts long time maintainability of code. Refactoring is one of the most important steps during development and just come easy.
- Generating patches for refactorings before applying them allows to easily verify the operation yourself or sending it to a colleague.
- The libraries (see above) to build such a tool are available, so why not do it.
- The project is an academic of sorts as well, as you can see in the Design Goals we try to be very strict about the Ports and Adapters architecture and a Domain Driven Design.

Refactorings
------------

[](#refactorings)

### Extract Method

[](#extract-method)

Extract a range of lines into a new method and call this method from the original location:

```
php refactor.phar extract-method

```

This refactoring automatically detects all necessary inputs and outputs from the function and generates the argument list and return statement accordingly.

### Rename Local Variable

[](#rename-local-variable)

Rename a local variable from one to another name:

```
php refactor.phar rename-local-variable

```

### Convert Local to Instance Variable

[](#convert-local-to-instance-variable)

Converts a local variable into an instance variable, creates the property and renames all the occurrences in the selected method to use the instance variable:

```
php refactor.phar convert-local-to-instance-variable

```

### Rename Class and Namespaces

[](#rename-class-and-namespaces)

Batch Operation to rename classes and namespaces by syncing class-names (IS-state) to filesystem names (SHOULD-state) based on the assumption of PSR-0.

Fix class and namespace names to correspond to the current filesystem layout, given that the project uses PSR-0. This means you can use this tool to rename classes and namespaces by renaming folders and files and then applying the command to fix class and namespaces.

```
php refactor.phar fix-class-names

```

### Optimize use statements

[](#optimize-use-statements)

Optimizes the use of Fully qualified names in a file so that FQN is imported with "use" at the top of the file and the FQN is replaced with its classname.

All other use statements will be untouched, only new ones will be added.

```
php refactor.phar optimize-use

```

Roadmap
-------

[](#roadmap)

Not prioritized.

Integration:

- Vim Plugin to apply refactorings from within Vim.

List of Refactorings to implement:

- Extract Method (Prototype Done)
- Rename Local Variable (Prototype Done)
- Optimize use statements (Done)
- Convert Local Variable to Instance Variable (Prototype Done)
- Rename Class PSR-0 aware (Done)
- Rename Namespace PSR-0 aware (Done)
- Convert Magic Value to Constant
- Rename Method
    - Private Methods Only first
- Rename Instance Variable
    - Private Variables Only First
- Extract Interface

Internals
---------

[](#internals)

### Design Goals

[](#design-goals)

- Be independent of third-party libraries and any Type Inference Engine (PDepend, PHP Analyzer) via Ports+Adapters
- Apply Domain-Driven-Design and find suitable Bounded Contexts and Ubiquitous Language within them
- Avoid primitive obsession by introducing value objects for useful constructs in the domain

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community27

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~185 days

Total

5

Last Release

4049d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/892698bb1d3f6dae0e3a44abe3e26920ddb4eb000c6c583c87b4db5e5027e166?d=identicon)[beberlei](/maintainers/beberlei)

---

Top Contributors

[![beberlei](https://avatars.githubusercontent.com/u/26936?v=4)](https://github.com/beberlei "beberlei (200 commits)")[![pscheit](https://avatars.githubusercontent.com/u/488189?v=4)](https://github.com/pscheit "pscheit (28 commits)")[![AdrianSchneider](https://avatars.githubusercontent.com/u/117682?v=4)](https://github.com/AdrianSchneider "AdrianSchneider (3 commits)")[![tobyS](https://avatars.githubusercontent.com/u/187140?v=4)](https://github.com/tobyS "tobyS (3 commits)")[![tomphp](https://avatars.githubusercontent.com/u/1959183?v=4)](https://github.com/tomphp "tomphp (3 commits)")[![trq](https://avatars.githubusercontent.com/u/32683?v=4)](https://github.com/trq "trq (2 commits)")[![david0](https://avatars.githubusercontent.com/u/1685610?v=4)](https://github.com/david0 "david0 (1 commits)")[![rouffj](https://avatars.githubusercontent.com/u/24047?v=4)](https://github.com/rouffj "rouffj (1 commits)")[![shimooka](https://avatars.githubusercontent.com/u/133541?v=4)](https://github.com/shimooka "shimooka (1 commits)")[![keelerm84](https://avatars.githubusercontent.com/u/1922716?v=4)](https://github.com/keelerm84 "keelerm84 (1 commits)")[![pborreli](https://avatars.githubusercontent.com/u/77759?v=4)](https://github.com/pborreli "pborreli (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/qafoolabs-php-refactoring-browser/health.svg)

```
[![Health](https://phpackages.com/badges/qafoolabs-php-refactoring-browser/health.svg)](https://phpackages.com/packages/qafoolabs-php-refactoring-browser)
```

###  Alternatives

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M568](/packages/symfony-maker-bundle)[coenjacobs/mozart

Composes all dependencies as a package inside a WordPress plugin

4723.6M20](/packages/coenjacobs-mozart)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M82](/packages/symplify-monorepo-builder)[roave/backward-compatibility-check

Tool to compare two revisions of a public API to check for BC breaks

5953.3M56](/packages/roave-backward-compatibility-check)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

96374.6k23](/packages/friendsoftypo3-content-blocks)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
