Composer
Composer is a dependency manager for PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
This template uses Composer to manage dependencies and provide scripts for linting and testing code.
The provided composer.json file contains the following sections:
-
Project Information: Metadata like name, description, and license.
-
Author and Support: Includes maintainer details and URLs for issues and source code.
-
Dependencies: Requires PHP version
>= 8.2. If using as base for CLI command,symfony/consoleis provided as a dependency as well. -
Development Dependencies: Tools like PHP Code Sniffer, PHP Mess Detector, PHPStan, and PHPUnit for development are listed.
-
Auto-loading: PSR-4 standard is used for auto-loading classes from the
srcdirectory. -
Dev Auto-loading: Auto-loads classes for development from
tests/phpunitdirectory. -
Custom Scripts: Defines CLI scripts for tasks:
lintandlint-fix- to lint and fix code using PHP Code Sniffer, PHP Mess Detector, PHPStan, and Rector.test- to run PHPUnit tests without generating coverage report.test-coverage- to run PHPUnit tests and generate coverage report.build- to build a PHAR file (if using as base for CLI command).
-
Executable Binaries: Executable binaries are defined as executable scripts in
bindirectory, which makes them easily accessible without cluttering the global scope. -
Configuration: Composer is configured with the following settings:
-
Discard Changes: Automatically discards any changes to the
composer.lockfile that are not committed. This ensures a clean state for the dependency versions defined incomposer.json. -
Sort Packages: Ensures that the packages in
composer.jsonare sorted, which helps in maintaining a consistent and organized structure. Runcomposer normalizeto sort the packages. -
Minimum Stability: Sets the minimum stability to
stable, meaning that only stable versions of packages will be considered when resolving dependencies. You can change this todevoralphaif you want to include unstable versions in your project. -
Prefer Stable: Prefers stable versions of packages over unstable ones, providing more reliable and tested packages unless a specific unstable version is required.
-