Composer Constraints Parser is a PHP Experts, Inc., Project that is a clean-room implementation of Packagist's composer's version constraint system.
It is meant as a zero-dependency option to faithfully interpret whether any particular version number is satisfiable by a composer verison constraint.
This project contains 100% of all of the in-the-world composer version constraints of every dependency of every package in the entire packagist.org database. These can be found in [tests/constraints.json].
There are 155,623 test assertions testing all 48,209 in-the-wild composer version constraints and has 100% fidelity. It is current as of 2025-04-01.
This is possible because of the Bettergist Collector API, which archives every PHP packagist package weekly and does deep analysis of them quarterly.
This is primarily a scientific research project and the code will be part of a scientific study.
You are allowed only two documents and one website to solve this problem:
- The official Composer Versions and Constraints documentation
- How Composer Version Constraints Work
- The PHP.net manual
Absolutely no LLMs should be consulted for this project. No ChatGPT, nothing. This needs to be a 100% human endeavor.
Requirements:
- Clean-room implementation: Absolutely do not look at any other source code or projects. Use your own knowledge and the existing documentation.
- 100% passing every single one of the 155,319 PHP unit test assertions.
- You almost certainly must have Xdebug configured for command line debugging or this project will not be feasible.
- The Unit tests contain Composer's version matching code itself, which you can use to test your own code.
It is in
isValidVersionConstraint
. - Absolutely under no circumstance may you look at or analyze Composer source code. This would be a breach of ethics in this case. If it is done accidentally, please report to your manager immediately do not code further.
- All of your work and research should be screen-recorded and stored as H264 with no audio and uploaded to a mega.nz account.
- Please attempt to do
git commits
at every possible stopping point, with descriptive commit messages. While not essential, this will aid in the scientific research.
Via Composer
composer install
use PHPExperts\ComposerVersionConstraints\ComposerConstraintsHelper;
$satisfies = ComposerConstraintsHelper::versionSatisfies('7.4', '^7.4|^8.0');
// true
✔ Can determine if a constraint is valid
✔ Complex composer constraints
✔ All composer constraints
✔ Known constraint
phpunit
Theodore R. Smith [email protected]
GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690
CEO: PHP Experts, Inc.
MIT license. Please see the license file for more information.