tomkyle / boilerplate-php
PHP Package boilerplate
Requires
- php: ^7.4|^8.0
- ext-json: *
- psr/cache: ^1.0|^2.0|^3.0
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/log: ^1.1|^2.0|^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- guzzlehttp/guzzle: ^7.0
- laminas/laminas-log: ^2.15
- nyholm/psr7: ^1.3
- php-coveralls/php-coveralls: ^2.0
- phpspec/prophecy-phpunit: ^2.0
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^9.0
- spatie/phpunit-watcher: ^1.0
- symfony/cache: ^5.0|^6.0
Suggests
- guzzlehttp/guzzle: PSR-18 client (as of v7)
- monolog/monolog: PSR-3 Logger of choice
- nyholm/psr7: PSR-17 factories
- symfony/cache: PSR-6 and PSR-16 Cache engines
README
A template repository for PHP package.
Start new project
$ composer create-project tomkyle/boilerplate-php new-project
$ cd new-project
$ composer install
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
Run all tests
This packages has predefined test setups for code quality, code readability and unit tests. Check them out at the scripts
section of composer.json.
$ composer test # ... which includes $ composer phpstan $ composer phpcs $ composer phpunit
Unit tests
Default configuration is phpunit.xml.dist. Create a custom phpunit.xml to apply your own settings. Also visit phpunit.readthedocs.io · Packagist
$ composer phpunit
# ... or
$ vendor/bin/phpunit
PhpStan
Default configuration is phpstan.neon.dist. Create a custom phpstan.neon to apply your own settings. Also visit phpstan.org · GitHub · Packagist
$ composer phpstan
# ... which includes
$ vendor/bin/phpstan analyse
PhpCS
Default configuration is .php-cs-fixer.dist.php. Create a custom .php-cs-fixer.php to apply your own settings. Also visit cs.symfony.com · GitHub · Packagist
$ composer phpcs
# ... which aliases
$ vendor/bin/php-cs-fixer fix --verbose --diff --dry-run
Apply all CS fixes:
$ composer phpcs:apply
# ... which aliases
$ vendor/bin/php-cs-fixer fix --verbose --diff
On PHP 8.2, setting environment variable PHP_CS_FIXER_IGNORE_ENV
is needed:
$ PHP_CS_FIXER_IGNORE_ENV=1 composer phpcs