https://github.com/tomkyle/boilerplate-php
PHP package boilerplate. Automatically runs PHPUnit, PHPStan, Rector, and PHP-CS-Fixer on file changes.
https://github.com/tomkyle/boilerplate-php
package-development php php-boilerplate php-cs-fixer phpstan phpunit rector
Last synced: 3 months ago
JSON representation
PHP package boilerplate. Automatically runs PHPUnit, PHPStan, Rector, and PHP-CS-Fixer on file changes.
- Host: GitHub
- URL: https://github.com/tomkyle/boilerplate-php
- Owner: tomkyle
- License: mit
- Created: 2021-01-22T12:38:37.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-06-28T17:24:21.000Z (7 months ago)
- Last Synced: 2025-08-01T16:25:08.329Z (6 months ago)
- Topics: package-development, php, php-boilerplate, php-cs-fixer, phpstan, phpunit, rector
- Language: PHP
- Homepage:
- Size: 202 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
PHP Package Boilerplate
[](https://packagist.org/packages/tomkyle/boilerplate-php )
[](https://packagist.org/packages/tomkyle/boilerplate-php )
[](https://github.com/tomkyle/boilerplate-php/actions/workflows/php.yml)
[](LICENSE)
**A template repository for PHP package.**
---
## Start new project
```bash
$ 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`:
- [PHPUnit](https://phpunit.de/documentation.html) tests
- [PHPStan](https://phpstan.org/) static analysis
- [Rector](https://getrector.com/) to fix code style issues
- [PHP CS Fixer](https://cs.symfony.com/) to format the code
#### 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](https://packagist.org/packages/psr/log) | [Monolog Logger](https://github.com/Seldaek/monolog) |
| PSR-6 Cache Implementation | [psr/cache](https://packagist.org/packages/psr/cache) | [Symfony Cache component](https://symfony.com/components/Cache) |
| PSR-17 HTTP factory* implementation | [psr/http-factory](https://packagist.org/packages/psr/http-factory) | [nyholm/psr7](nyholm/psr7) |
| PSR-18 HTTP client | [psr/http-client](https://packagist.org/packages/psr/http-client) | [Guzzle 7](https://packagist.org/packages/guzzlehttp/guzzle) |
```bash
$ 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](package.json) for a list of all test tasks:
```bash
$ npm run watch
```
Whenever a PHP file is changed, the following tasks are run:
- [PHPUnit](https://phpunit.de/documentation.html) test — only for [that very file](https://github.com/tomkyle/find-run-test)
- [PHPStan](https://phpstan.org/) static analysis
- [Rector](https://getrector.com/) to fix code style issues
[PHP CS Fixer](https://cs.symfony.com/) 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:
```bash
$ 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.