Skip to content

Latest commit

 

History

History
96 lines (71 loc) · 3.78 KB

README.md

File metadata and controls

96 lines (71 loc) · 3.78 KB

php-skeleton

A skeleton to start new high-quality PHP projects without worrying about bootstrapping everything from scratch.

Features

The skeleton includes a PHP project properly configured with:

  • 🛠 Docker and docker-compose - because nobody wants (or should) to install project dependencies directly into their machines.
  • 🎉 PHP 7.4
  • 🕵 Xdebug - to stop wasting time printing values and start debugging PHP applications like a boss‍️.
  • 🚦PHPUnit - to write and run unit tests and also generate code coverage.
  • 🏎 PHP Parallel Lint - to check syntax of PHP files.
  • 📋 phpcs - to ensure good coding standards.
  • 👻 phpstan - to find errors in the code before running it.
  • 🚀 Continuous Integration - to ensure the previous tools runs for every contribution to your repository.

Stop wasting time! 🏝🍹

Requirements

Install

  1. Make sure you have the requirements described above.
  2. Clone this repository: git clone git@github.com:xthiago/php-skeleton.git
  3. Run docker-compose run php composer install to install the PHP dependencies.
  4. If you are using Linux, go to the next step. If you are using Docker for Mac or Windows, create a .env file (I suggest you copy from distribution version with cp .env.dist .env) and add XDEBUG_REMOTE_HOST=host.docker.internal). It is needed in order to allow Xdebug to connect back to the IDE in these OS.
  5. (optional) You can configure the Xdebug in your editor/IDE in order to debug this application using it. See the guide.
  6. That's all 😜.

Usage

Web application

In order to start the web application, you must create and start the PHP service:

docker-compose up -d

Then you can open https://localhost:8000 in your browser. It will open web/index.php file.

For troubleshooting, you can watch the logs to see what's going on:

docker-compose logs -f

See docker-compose --help to get more instructions.

Command line

You can access the terminal of PHP container with:

docker-compose exec php ash

You can also execute any command in PHP container from outside it typing and running:

docker-compose run php [command-name]
# Example: docker-compose run php

--help

Available commands

You can run any available commands inside the PHP container:

  • parallel-lint --exclude vendor . to check the PHP syntax.
  • phpcs - to check the codebase against code standards
    • the configuration is automatically inherited from phpcs.xml.
  • phpstan analyse to run a static analyse in the codebase
    • the configuration is automatically inherited from phpstan.neon.
  • phpunit to run the unit tests
    • the configuration is automatically inherited from phpunit.xml
  • composer test to run all commands above.
  • phpunit --coverage-html reports/ to generate code coverage of tests
    • the configuration is automatically inherited from phpunit.xml