<commit_before>Templates
=========

**phpspec** can generate code snippets that will save you time when speccing classes.
The default templates will be suitable for many use cases.

However in some cases, it'll be useful to customize those templates by providing
ones that suit your project requirements. For example, you may need to add
information in a docblock to every class file. Instead of doing this manually you
can modify the template so it is already in the generated file.

Overriding templates
--------------------

**phpspec** uses three templates:
  - *specification* - used when a spec is generated using the `describe` command
  - *class* - used to generate a class that is specced but which does not exist
  - *method* - used to add a method that is specced to a class

You can override these on a per project basis by creating a template file in
`.phpspec` in the root directory of the project. For example, to add author
information to the docblock for a class, you can create a file ``{project_directory}/.phpspec/class.tpl``.
You can copy the contents of the default template found in **phpspec** at
``src/PhpSpec/CodeGenerator/Generator/templates/class.template`` and add the docblock to it:

.. code-block:: php

    <?php%namespace_block%

    /**
     * @author user <<EMAIL>>
     */
    class %name%
    {
    }

So now, for example, you want to describe a class ``Acme\Model\Foo`` which does not exist. You can run
the spec``spec/Acme/Model/FooSpec.php``` and let **phpspec** generate the missing class.
**phpspec** will use your overridden template and the generated file will look like:

.. code-block:: php

    <?php

    /**
     * @author user <<EMAIL>>
     */

    namespace Acme\Model;

    class Foo
    {
    }

You can also override the templates for all projects by creating a template
in `.phpspec` in your home directory.

**phpspec** uses the first template it finds by looking in this order:<commit_msg>Change template example to use licence<commit_after>Templates
=========

**phpspec** can generate code snippets that will save you time when speccing classes.
The default templates will be suitable for many use cases.

However in some cases, it'll be useful to customize those templates by providing
ones that suit your project requirements. For example, you may need to add licence
information in a docblock to every class file. Instead of doing this manually you
can modify the template so it is already in the generated file.

Overriding templates
--------------------

**phpspec** uses three templates:
  - *specification* - used when a spec is generated using the `describe` command
  - *class* - used to generate a class that is specced but which does not exist
  - *method* - used to add a method that is specced to a class

You can override these on a per project basis by creating a template file in
`.phpspec` in the root directory of the project. For example, to add licence
information to the docblock for a class, you can create a file ``{project_directory}/.phpspec/class.tpl``.
You can copy the contents of the default template found in **phpspec** at
``src/PhpSpec/CodeGenerator/Generator/templates/class.template`` and add the docblock to it:

.. code-block:: php

    <?php

    /*
     * This file is part of Acme.
     *
     * For the full copyright and license information, please view the LICENSE
     * file that was distributed with this source code.
     */%namespace_block%

    class %name%
    {
    }

So now, for example, you want to describe a class ``Acme\Model\Foo`` which does not exist. You can run
the spec``spec/Acme/Model/FooSpec.php``` and let **phpspec** generate the missing class.
**phpspec** will use your overridden template and the generated file will look like:

.. code-block:: php

    <?php

    /*
     * This file is part of Acme.
     *
     * For the full copyright and license information, please view the LICENSE
     * file that was distributed with this source code.
     */

    namespace Acme\Model;

    class Foo
    {
    }

You can also override the templates for all your projects by creating a
template in `.phpspec` in your home directory.

**phpspec** uses the first template it finds by looking in this order:
{'fraction_non_alphanumeric': 0.08424041646947468, 'fraction_numerical': 0.0, 'mean_word_length': 3.353244078269825, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2855349', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1113, 'n_words': 589}