A template repository for PHP package.
$ composer create-project tomkyle/boilerplate-php new-project
$ cd new-project
$ composer install
$ npm install
On first install, the composer install
command will create two things:
The pre-commit hook runs the following checks before allowing any git commit
:
- PHPUnit tests
- PHPStan static analysis
- Rector to fix code style issues
- PHP CS Fixer to format the code
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.
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
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:
- PHPUnit test — only for that very file
- PHPStan static analysis
- Rector to fix code style issues
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
.
$ npm run
Overview:
- watch watches
src/
andtests/
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.