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.3. If using as base for CLI command,symfony/consoleis provided as a dependency as well. -
Development Dependencies: Tools like PHP Code Sniffer, 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, 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:
-
Dependency Policy (Composer 2.10+): The
policysection sets how Composer treats packages with security advisories and abandoned packages. The template ships these values:Setting Value Effect advisories.blockfalseComposer installs packages that have known advisories. Set it to trueto block them.advisories.audit"fail"composer auditfails when an installed package has a known advisory.abandoned.audit"report"composer auditlists abandoned packages and still passes.
Composer older than 2.10 ignores the
policysection without a warning. To prevent that,require-devdeclares"composer": ">=2.10.2", so an older Composer refuses to install the project. The floor is 2.10.2 because earlier 2.10 releases have a known advisory. The constraint sits inrequire-devbecauseconfigapplies only to the root project, so packages that depend on yours keep their own Composer version.composer install --no-devskips the check, so it applies tocomposer updateand to installs that include development dependencies.To allow a specific advisory after you review it, add its ID and your reason to
ignore-id:"policy": {"advisories": {"ignore-id": {"CVE-2024-1234": "Waiting for upstream fix, mitigated by input validation","GHSA-xxxx-yyyy-zzzz": "False positive - feature not used in our code"}}}Remove each exception after a fix is available.
-
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.
-