PHPackages                             memio/spec-gen - 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. memio/spec-gen

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

memio/spec-gen
==============

phpspec extension for better code generation

0.10.1(3mo ago)66204.3k10[1 PRs](https://github.com/memio/spec-gen/pulls)20MITPHPPHP ^7.2 || 8.0.\*CI failing

Since May 11Pushed 3mo ago4 watchersCompare

[ Source](https://github.com/memio/spec-gen)[ Packagist](https://packagist.org/packages/memio/spec-gen)[ Docs](http://memio.github.io/spec-gen)[ RSS](/packages/memio-spec-gen/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (14)Versions (23)Used By (20)

Memio's SpecGen
===============

[](#memios-specgen)

This extension for [phpspec](http://phpspec.net/) provides a powerful code generator:

- method generation:
    - it inserts method at the end of the class
    - it typehints arguments (uses interface when possible)
    - it names object arguments after their type (strips `Interface` suffix from names)
    - it names scalar arguments after a generic name (`argument`)
    - it adds number on names that could collide (e.g. `$argument1, $argument2`)
- constructor generation, same as method except:
    - it inserts constructor at the begining of the class
    - it inserts properties with initialization for each constructor arguments

> **Note**: Currently it is not possible to provide custom templates to SpecGen (it is not compatible with phpspec templates).

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

[](#installation)

First install it using [Composer](https://getcomposer.org/download):

```
composer require --dev memio/spec-gen:^0.10.1
```

Then enable it in `phpspec.yml`:

```
extensions:
    Memio\SpecGen\MemioSpecGenExtension: ~
```

> **Version guide**:
>
> - using phpspec 6? Then use spec-gen v0.10
> - using phpspec 5? Then use spec-gen v0.9
> - using phpspec 4? Then use spec-gen v0.8
> - using phpspec 3 and PHP 7? Then use spec-gen v0.7
> - using phpspec 3 and PHP 5.6? Then use spec-gen v0.6
> - using phpspec 2? Then use spec-gen v0.4

Full example
------------

[](#full-example)

Let's write the following specification:

```
