This package is abandoned and no longer maintained. No replacement package was suggested.

Generating and modifying source code

0.4.3 2021-12-28 20:24 UTC



This library can be used to generate or idempotently add classes, methods, properties, use statements, etc. to existing source code using prototypes.

A prototype is an object which defines structural code elements.


The library provides a source code prototype builder:

$builder = SourceBuilder::create()

$sourcePrototype = $builder->build();

the above prototype can either be used to generate a new class:

$renderer = new TwigRenderer();

Or it can be applied to an existing source code, given the following:


class Rabbits

When we do:

$updater = new TolerantUpdater();
$updater->apply($sourcePrototype, Code::fromString(file_get_contents('Rabbits.php')));

Then we get:


namespace Animals;

use Measurements\Height;

class Rabbits extends Leopridae
    private $force = 5;

    public function jump(Height $how = 'high')

About this project

This library is part of the phpactor project.


This package is open source and welcomes contributions! Feel free to open a pull request on this repository.


  • Create an issue on the main Phpactor repository.
  • Join the #phpactor channel on the Slack Symfony Devs channel.