Bored of manually setting up your PHP projects ?
This is the solution !
This is a skeleton for PHP projects that focus on code quality.
It contains pretty much everything you need to start a new project :
- Code quality
- A working unit test (using PHPUnit) to bootstrap your coding experience
- Static analyis tools (phpcs, phpstan, psalm, phpmd and phan) to enforce the quality of your code
- A mutation testing framework (Infection) to enforce the quality of your tests
- An automated refactoring tool (Rector) to help you keep your code up to date
- Composer scripts to easily use all the above
- Infra
- Docker support
- A Makefile to manage docker commands with ease
- GitHub workflows to automatically run the tests and quality tools on every push and pull request
- It also uploads a code coverage report to CodeCov
- Docker support
To create a new project based on this skeleton, run the following command:
composer create-project ingenioz-it/php-skeleton {PROJECT_NAME}
- docker
- make (optional)
OR
- PHP 8.2 or higher
- composer
- xdebug
I suggest you run the full set of tests to make sure everything is working correctly:
cd {PROJECT_NAME}
make build && make start && make cli
This will build the Docker image and start a shell inside the container (use exit
to go back to your local terminal).
composer install
composer fulltest
The last line should be:
OK
You are now ready to start coding !
The project comes with a few useful composer scripts to help you work with it.
You can view their description inside the composer.json
file (look for scripts-descriptions
), but here is a quick overview of the main ones:
composer serve
: Runs a local web server on port 8000. Run this command and go to http://localhost:8000 to see the magic happen.composer testdox
: Runs the unit tests using thetestdox
format (it's better looking than the default one).composer coverage-html
: Generates a code coverage report in HTML format inside thedoc/
directory.composer quality:infection
: Generates a mutation testing report in HTML format attmp/infection.html
.composer quality:clean
: Runs phpcbf to automatically fix code formatting issues.composer quality:refactor
: Runs Rector to automatically refactor your code. Warning: This is a very powerful tool that can break your code. Usecomposer quality:refactor-dry
to preview the changes before applying them.composer fulltest
: Runs the full set of tests (unit tests, static analysis tools and mutation testing).
The project comes with a Makefile
to help you manage your Docker container:
make build
: Builds the Docker imagemake start
: Starts the Docker container (go to http://localhost:8080 to see your app live)make stop
: Stops the Docker containermake restart
: Restarts the Docker containermake rebuild
: Rebuilds the Docker image and restarts the containermake remove
: Removes the Docker containermake cli
: Access a command line the container (useful to run the various composer scripts)make logs
: Displays the logs of the Docker containermake clean
: Cleans the docker environment
Make the project truly yours by doing the following:
- Update the
composer.json
with your project's information - Update the
README.md
file to describe your project - Update the
LICENSE
file with your favorite license