PHPackages                             code-stencil/code-stencil - 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. code-stencil/code-stencil

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

code-stencil/code-stencil
=========================

A beautiful way to create dynamic code

v1.2.0(1y ago)01.7k[5 PRs](https://github.com/Riley19280/code-stencil/pulls)MITPHPCI passing

Since Oct 16Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/Riley19280/code-stencil)[ Packagist](https://packagist.org/packages/code-stencil/code-stencil)[ RSS](/packages/code-stencil-code-stencil/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (12)Versions (10)Used By (0)

 [![Code Stencil](https://raw.githubusercontent.com/Riley19280/code-stencil/main/docs/static/img/splash.png)](https://raw.githubusercontent.com/Riley19280/code-stencil/main/docs/static/img/splash.png)

 [![GitHub Workflow Status (master)](https://camo.githubusercontent.com/92bdc0e77c91b47190bd478625d9359d6db591ac27352959bf7971fb5ccbab88/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72696c657931393238302f636f64652d7374656e63696c2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d5465737473)](https://github.com/riley19280/code-stencil/actions) [![Total Downloads](https://camo.githubusercontent.com/6c3496237a1d696e2878132b3b4a2e4c2ef6d13867a4475a891b8ba5cb2a2a88/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f64652d7374656e63696c2f636f64652d7374656e63696c)](https://packagist.org/packages/code-stencil/code-stencil) [![Latest Version](https://camo.githubusercontent.com/6d38437885be61eb877f366e3b1d8b45be6925ab5a8792ecf48fd7c8b99e8833/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64652d7374656e63696c2f636f64652d7374656e63696c)](https://packagist.org/packages/code-stencil/code-stencil) [![License](https://camo.githubusercontent.com/7e28c1a03f4d893b3957a2e538c9927aa01e2dbcb7e69467821bd1d95a9515db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636f64652d7374656e63696c2f636f64652d7374656e63696c)](https://packagist.org/packages/code-stencil/code-stencil)

Introduction
============

[](#introduction)

Code Stencil provides an elegant, easy to read pattern that is great for generating stub files, and will streamline your code generation tasks. A common occurrence with code generation is that readability and maintenance suffer, but with Code Stencil, it's a piece of cake!

Create a class
--------------

[](#create-a-class)

```
Stencil::make()
    ->php()
    ->strictTypes()
    ->namespace('App/Models')
    ->curlyStatement('class MyClass', fn(Stencil $s) => $s
        ->line('private OtherClass $otherClass;')
        ->use(OtherClass::class) // This will add a use statement to the file
        ->line()
        ->phpdoc(
            summary: 'Create a new instance of MyClass',
            tags: ['param' => ['OtherClass $class', 'bool $options']]
        )
        ->curlyStatement('function __construct(OtherClass $class, bool $options = false)', fn(Stencil $s) => $s
            ->line('$this->otherClass = $class;')
        )
    )
    ->save('MyClass.php')
```

Show Result```
