tomkyle/boilerplate-php

PHP package boilerplate. Automatically runs PHPUnit, PHPStan, Rector, and PHP-CS-Fixer on file changes.

1.3.0 2025-06-26 15:25 UTC

This package is auto-updated.

Last update: 2025-06-26 15:42:48 UTC


README

Packagist PHP version PHP Composer Software License

A template repository for PHP package.

Start new project

$ composer create-project tomkyle/boilerplate-php new-project  
$ cd new-project
$ composer install
$ npm install

Initial setup

On first install, the composer install command will create two things:

1. Pre-commit hook

The pre-commit hook runs the following checks before allowing any git commit:

2. Local PHP-CS-Fixer configuration

While the .php-cs-fixer.dist.php in the repo basically sets @PER-CS as coding standard, the local .php-cs-fixer.php override sets the sophisticated @PhpCsFixer coding standard. Its opinionated rules are compatible with PER-CS. This setup matches my taste but leaves room for customization.

Requirements and suggestions

PSR standard require suggest
PSR-3 Logger implementation psr/log Monolog Logger
PSR-6 Cache Implementation psr/cache Symfony Cache component
PSR-17 HTTP factory* implementation psr/http-factory nyholm/psr7
PSR-18 HTTP client psr/http-client Guzzle 7
$ composer require monolog/monolog
$ composer require symfony/cache
$ composer require nyholm/psr7
$ composer require guzzlehttp/guzzle

Development

Watch PHP source code

Watch the file system for PHP code changes. Unit and code quality tests are automatically triggered. To manually trigger a test run, see package.json for a list of all test tasks:

$ npm run watch

Whenever a PHP file is changed, the following tasks are run:

PHP CS Fixer is not automatically applied, but you can invoke it manually with npm run phpcs or npm run phpcs:apply to apply the changes. It will, however, automatically be executed on git commit.

Available npm scripts:

$ npm run

Overview:

  • watch watches src/ and tests/ directory
  • phpstan runs PHPStan static analysis
  • phpcs runs PHP CS Fixer as a dry run, use phpcs:apply to actually apply changes.
  • rector runs Rector as a dry run, use rector:apply to actually apply changes.
  • phpunit runs PHPUnit tests with textdox and coverage report if available.