PHPackages                             jhoff/phpeditor - 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. jhoff/phpeditor

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jhoff/phpeditor
===============

Library for editing PHP files

0.0.2(8y ago)16MITPHPPHP ^7.1

Since May 16Pushed 8y ago1 watchersCompare

[ Source](https://github.com/jhoff/phpeditor)[ Packagist](https://packagist.org/packages/jhoff/phpeditor)[ RSS](/packages/jhoff-phpeditor/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

PHP Editor
==========

[](#php-editor)

Simplified, opinionated php-based editor for [PSR-4](https://www.php-fig.org/psr/psr-4/) php files, leveraging the [nikic/PHP-Parser](https://github.com/nikic/PHP-Parser) library.

[![Latest Stable Version](https://camo.githubusercontent.com/3410501aeffb36236dd7de05999825f3fc40dbfc17930209949c9ed3f4b60b6d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6a686f66662f706870656469746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jhoff/phpeditor)[![Total Downloads](https://camo.githubusercontent.com/d5c86fe06faa96a09f3983aa38855beb70c73da3b15eb1de905cd09d7359b0dd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a686f66662f706870656469746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jhoff/phpeditor)[![MIT License](https://camo.githubusercontent.com/2854d46d15a092796d4543b57feeb2d3498616ee7273ceaa0fb05c743dea5f6a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a686f66662f706870656469746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jhoff/phpeditor)[![Build Status](https://camo.githubusercontent.com/23e984d63078a1b0608c11fffb09e6c21d0f26160ca1473a3a9f30f91b6396c8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a686f66662f706870656469746f722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jhoff/phpeditor/build-status/master)[![Code Coverage](https://camo.githubusercontent.com/62215e1dec93090b71de578b80184592f703cecaa152d5530b7a79f29a1c0f87/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a686f66662f706870656469746f722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jhoff/phpeditor/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/0a0ba57fa931a2c2293b0b4118b524e1d163a73d7f2d880c81b2ec9626c04459/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a686f66662f706870656469746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.coem/g/jhoff/phpeditor/?branch=master)

- [About](#about)
- [Installation](#installation)
- [Usage](#usage)
- [Docblocks](#docblocks)

About
-----

[](#about)

The PHPEditor library is useful for making minor changes to existing PSR4 PHP files. It's assumed that each file will have a single namespaced class. New methods will be added to the end of the class. Use statements will automatically be de-duplicated and sorted by length.

Installation
------------

[](#installation)

Use [composer](https://getcomposer.org/) to install:

```
composer require jhoff/phpeditor

```

Usage
-----

[](#usage)

There are a few static helpers to help you find the proper file to edit:

```
// Open an existing file using a relative or absolute path
File::open($filename)

// Create a new class with the provided filename, namespace and class
File::create($filename, $namespace, $class)

// Either open or create, based on if the file exists already
File::openOrCreate($filename, $namespace, $class)

// Use reflection to find the file that defines the provided class
File::fromClass($class)

```

Once you've opened or created the file, you can use fluent methods to make modifications and then write them to disk.

```
    $file = \Jhoff\PhpEditor\File::open('MyClass.php');

    $file->addUse('Awesome\Library\Tool')
        ->addPublicMethod(
            'newMethod',
            'return true;'
        )

    $file->write();

```

Additionally, you can use the `getNewFileContents` method if you don't want to write the changes to disk.

The underlying [nikic/PHP-Parser](https://github.com/nikic/PHP-Parser) library will attempt to preserve any existing formatting in the file, but you may need some additional processing to make small formatting tweaks.

Docblocks
---------

[](#docblocks)

The `addMethod` method ( or any of the variants ) accepts a final docblock argument in the form of an associative array. Optionally provide a `message` or `description` and any other properties will automatically be formatted into proper tags. Simple tags without any text can be added by setting their value to `true`.

```
    [
        'message' => 'This is the docblock message',
        'description' => 'Some information about the method',
        'param' => [
            'string $paramOne',
            'array $paramTwo',
        ],
        'return' => 'void',
        'internal' => true,
    ]

```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

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 ~0 days

Total

2

Last Release

2921d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/155e0e6f1ecdebf6c65ac73aa8645a94465341e1c8fe7d2e6d71571970aa4473?d=identicon)[jhoff](/maintainers/jhoff)

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/jhoff-phpeditor/health.svg)

```
[![Health](https://phpackages.com/badges/jhoff-phpeditor/health.svg)](https://phpackages.com/packages/jhoff-phpeditor)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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