PHP libraries and tools
Tags: php, tooling, symfony, cicd
Published: 2023-10-18 07:14:16

PHP possesses a rich ecosystem, with plenty of libraries and tools. Here is a list of them that I consider interesting, beyond any framework.

At the end, I included some useful checks for Composer and Symfony to execute on a CI pipeline.

## Libraries

- [brick/math](https://github.com/brick/math): Arbitrary-precision arithmetic library for PHP
- [openspout/openspout](https://github.com/openspout/openspout): Read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way
- [thecodingmachine/safe](https://github.com/thecodingmachine/safe): All PHP functions, rewritten to throw exceptions instead of returning false
- [azjezz/psl](https://github.com/azjezz/psl): PHP Standard Library - a modern, consistent, centralized, well-typed, non-blocking set of APIs for PHP programmers
- [particle/validator](https://github.com/particle-php/Validator): Particle\Validator is a validation library with an extremely clean API which makes validation fun! 
- [league/tactician](https://github.com/thephpleague/tactician): A small, flexible command bus.
- [league/flysystem](https://flysystem.thephpleague.com/docs/): Abstraction for local and remote filesystems
- [golem-ai/messenger-kit](https://github.com/golem-ai/messenger-kit): This command simulates consumer failures and prints a timeline of the events. It lets you check whether your retry strategy configuration does what you expect it to.
- [swarrot/swarrot](https://github.com/swarrot/swarrot): A lib to consume message from any Broker
- [ronanguilloux/isocodes](https://github.com/ronanguilloux/IsoCodes): PHP library - Validators for standards from ISO, International Finance, Public Administrations, GS1, Manufacturing Industry, Phone numbers & Zipcodes for many countries
- [php-units-of-measure/php-units-of-measure](https://github.com/PhpUnitsOfMeasure/php-units-of-measure): A library for handling physical quantities and the units of measure in which they're represented.
- [rawr/t-regx](https://github.com/T-Regx/T-Regx): PHP regular expression brought up to modern standards.
- [mpratt/embera](https://github.com/mpratt/Embera): A Oembed consumer library, that gives you information about urls. It helps you replace urls to youtube or vimeo for example, with their html embed code. It has advanced features like offline support, responsive embeds and caching support.
- [spatie/geocoder](https://github.com/spatie/geocoder): Geocode addresses to coordinates
- [php-soap/wsdl-reader](https://github.com/php-soap/wsdl-reader): A pure PHP wsdl metadata provider
- [phpro/soap-client](https://github.com/phpro/soap-client): A general purpose SOAP client for PHP
- [eventsauce/backoff](https://github.com/EventSaucePHP/BackOff): Sophisticated back-off strategies for retrying operations.
- [pontedilana/php-weasyprint](https://github.com/pontedilana/php-weasyprint): PHP library allowing PDF generation or snapshot from an URL or an HTML page. Wrapper for Kozea/WeasyPrint
- Parsers:
    - [cuyz/valinor](https://github.com/CuyZ/Valinor/): PHP library that helps to map any input into a strongly-typed value object structure.
    - [cerbero/json-parser](https://github.com/cerbero90/json-parser): 🧩 Zero-dependencies lazy parser to read JSON of any dimension and from any source in a memory-efficient way.
    - [yzen.dev/plain-to-class](https://github.com/yzen-dev/plain-to-class): Class-transformer to transform your data into a typed object
    - [JanePHP](https://jane.readthedocs.io/en/latest/): 🌱 Jane is a set of libraries to generate Models & API Clients based on JSON Schema / OpenAPI specs
- Time:
    - [brick/date-time](https://github.com/brick/date-time): Date and time library for PHP
    - [fredbradley/easytime](https://github.com/fredbradley/easytime): A small class based package to help with human readable calculations of time
    - [flack/ranger](https://github.com/flack/ranger): Formatter for date and time ranges with i18n support
- Money:
    - [brick/money](https://github.com/brick/money): A money and currency library for PHP
    - [moneyphp](https://github.com/moneyphp/money): PHP implementation of Fowler's Money pattern
- Search:
    - [schranz-search/seal](https://schranz-search.github.io): Search abstraction over different search engines written in PHP. Currently implemented Elasticsearch, Opensearch, Algolia, Meilisearch, RediSearch, Solr, Typesense.
    - [loupe/loupe](https://github.com/loupe-php/loupe): A full text search engine with tokenization, stemming, typo tolerance, filters and geo support based on only PHP and SQLite.

## Test libraries

- [Infection](https://infection.github.io/): PHP Mutation Testing library. Plugins:
  - [roave/infection-static-analysis-plugin](https://github.com/Roave/infection-static-analysis-plugin): Static analysis on top of mutation testing - prevents escaped mutants from being invalid according to static analysis
  - [bitexpert/captainhook-infection](https://github.com/bitExpert/captainhook-infection): Captain Hook Plugin to run InfectionPHP only against the changed files of a commit
- [lulco/populator](https://github.com/lulco/populator): Allows populate fake data to your database.
- [league/openapi-psr7-validator](https://github.com/thephpleague/openapi-psr7-validator): It validates PSR-7 messages (HTTP request/response) against OpenAPI specifications.
- [PHPUnit](https://phpunit.de/): PHPUnit is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks. Extensions/tools:
    - [brianium/paratest](https://github.com/paratestphp/paratest): Parallel testing for PHPUnit
    - [johnkary/phpunit-speedtrap](https://github.com/johnkary/phpunit-speedtrap): Reports on slow-running tests in your PHPUnit test suite.
    - [robiningelbrecht/phpunit-pretty-print](https://github.com/robiningelbrecht/phpunit-pretty-print): Better PHPUnit CLI output with Collision
    - [roave/no-leaks](https://github.com/Roave/no-leaks): PHPUnit Plugin for detecting Memory Leaks in code and tests

## Tools

- [Deptrac](https://github.com/qossmic/deptrac): Keep your architecture clean.
- [PHP Architecture Tester](https://github.com/carlosas/phpat): Easy to use architectural testing tool for PHP
- [PHPArkitect](https://github.com/phparkitect/arkitect): Put your architectural rules under test!
- [PHP Insights](https://phpinsights.com/): Instant PHP quality checks from your console
- [GrumPHP](https://github.com/phpro/grumphp): A PHP code-quality tool.
- [churn-php](https://github.com/bmitch/churn-php): Discover files in need of refactoring.
- [scheb/tombstone](https://github.com/scheb/tombstone): Dead code detection with tombstones for PHP
- [PHP Magic Number Detector](https://github.com/povils/phpmnd): a tool that aims to help you to detect magic numbers in your PHP code.
- [shipmonk/name-collision-detector](https://github.com/shipmonk-rnd/name-collision-detector): Fast & simple tool to find classname collisions within your project.
- [Robo](https://robo.li/): Modern Task Runner for PHP
- [CaptainHook](https://github.com/captainhookphp/captainhook): Very flexible git hook manager for php developers
- [Whisky](https://github.com/ProjektGopher/whisky): Whisky is the simplest, framework agnostic, CLI tool for managing and enforcing a php project's git hooks across an entire team.
- [PHP_Depend](https://pdepend.org/): PHP_Depend is an adaptation of the established Java development tool JDepend. This tool shows you the quality of your design in terms of extensibility, reusability and maintainability.
- [PHPMD - PHP Mess Detector](https://phpmd.org/): PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD. PHPMD can be seen as an user friendly frontend application for the raw metrics stream measured by PHP Depend.
- [vcian/php-db-auditor](https://github.com/vcian/php-db-auditor): Audit your mysql database -Database DB Auditor provide leverage to audit your MySql database standards and also provide options to add constraints in table
- [Psalm](https://psalm.dev/): A static analysis tool for finding errors in PHP applications. Plugins:
    - [boesing/psalm-plugin-stringf](https://github.com/boesing/psalm-plugin-stringf): Psalm plugin to provide more details for sprintf, printf, sscanf and fscanf functions.
    - [hectorj/safe-php-psalm-plugin](https://github.com/hectorj/safe-php-psalm-plugin): vimeo/psalm plugin for thecodingmachine/safe.
    - [marartner/psalm-no-empty](https://github.com/marartner/psalm-no-empty): Psalm plugin to detect usage of empty().
    - [marartner/psalm-strict-equality](https://github.com/marartner/psalm-strict-equality): Psalm plugin to enforce strict equality.
    - [psalm/plugin-phpunit](https://github.com/psalm/psalm-plugin-phpunit): A PHPUnit plugin for Psalm.
    - [psalm/plugin-symfony](https://github.com/psalm/psalm-plugin-symfony): Psalm Plugin for Symfony.
    - [weirdan/doctrine-psalm-plugin](https://github.com/psalm/psalm-plugin-doctrine): Stubs to let Psalm understand Doctrine better.
    - [ghostwriter/psalm-plugin](https://github.com/ghostwriter/psalm-plugin): Provides an `ALL-IN-ONE` plugin for Psalm
- [PHPStan](https://phpstan.org/): PHP Static Analysis Tool - discover bugs in your code without running it! Plugins:
    - [ergebnis/phpstan-rules](https://github.com/ergebnis/phpstan-rules): Provides additional rules for phpstan/phpstan.
    - [spaze/phpstan-disallowed-calls](https://github.com/spaze/phpstan-disallowed-calls): PHPStan rules to detect disallowed calls and constant & namespace usages
    - [roave/no-floaters](https://github.com/Roave/no-floaters): static analysis rules to prevent IEEE-754 floating point errors.
    - [dave-liddament/php-language-extensions](https://github.com/DaveLiddament/php-language-extensions): Attributes to define PHP language extensions (to be enforced by static analysis)
    - [sidz/phpstan-rules](https://github.com/sidz/phpstan-rules): Additional rules for phpstan/phpstan.
    - [staabm/phpstan-baseline-analysis](https://github.com/staabm/phpstan-baseline-analysis): Analyzes PHPStan baseline files and creates aggregated error trend-reports
    - [More extensions](https://phpstan.org/user-guide/extension-library)

## Performance frameworks

- [Hyperf](www.hyperf.io): 🚀 A coroutine framework that focuses on hyperspeed and flexibility. Building microservice or middleware with ease.
- [Flow PHP](https://github.com/flow-php/flow): Flow PHP - strongly typed data processing framework
- [PHPTokio](https://github.com/danog/php-tokio): Use any async Rust library from PHP!

## Composer tools

- [ComposerRequireChecker](https://github.com/maglnet/ComposerRequireChecker): A CLI tool to check whether a specific composer package uses imported symbols that aren't part of its direct composer dependencies
- [composer-unused](https://github.com/composer-unused/composer-unused): Show unused composer dependencies by scanning your code
- [composer-normalize](https://github.com/ergebnis/composer-normalize): Provides a composer plugin for normalizing composer.json.

## Security

- [roave/security-advisories](https://github.com/Roave/SecurityAdvisories): Security advisories as a simple composer exclusion list, updated daily
- [roave/backward-compatibility-check](https://github.com/Roave/BackwardCompatibilityCheck): Tool to compare two revisions of a class API to check for BC breaks
- [Local PHP Security Checker](https://github.com/fabpot/local-php-security-checker): PHP security vulnerabilities checker

## CI checks

- Lints (for Symfony):
    - PHP: `find src public bin -name "*.php" -print0 | xargs -0 -n1 php -l`
    - Container: `bin/console lint:container`
    - YAML: `bin/console lint:yaml config src`
    - Twig: `bin/console lint:twig src`
- Symfony + Doctrine:
    - Deprecations: `bin/console debug:container --deprecations` (even if it fails, it returns `0` as exit code)
    - Doctrine schema: `bin/console doctrine:schema:validate --skip-sync`
- Composer
    - Audit (The audit command checks for security vulnerability advisories for installed packages.): `composer audit`
    - Outdated (The `outdated` command shows a list of installed packages that have updates available, including their current and latest versions): `composer outdated --minor-only --direct --strict`
    - Validate (It will check if your `composer.json` is valid): `composer validate --strict`

## Sources

This list is inspired (and based to some extent) by:

- [https://twitter.com/ramsey/status/1396592906102722561](https://twitter.com/ramsey/status/1396592906102722561)
- [https://twitter.com/lulco/status/1397813303037079553](https://twitter.com/lulco/status/1397813303037079553)
- [https://twitter.com/ArkadiuszKondas/status/1338485275002068993](https://twitter.com/ArkadiuszKondas/status/1338485275002068993)
- [https://twitter.com/ArkadiuszKondas/status/1596232242627366912](https://twitter.com/ArkadiuszKondas/status/1596232242627366912)
- [Aggressive PHP Quality Assurance in 2019 \| Marco Pivetta](https://youtu.be/8rdTSYljts4)