Checks prefer-lowest installation for actually defined min versions in composer.json

Overview

Composer Prefer Lowest Validator

CI Latest Stable Version Minimum PHP Version License Coding Standards Total Downloads

This validator will strictly compare the specified minimum versions of your composer.json with the ones actually used by the prefer-lowest composer update command option.

This is useful for all libraries that want to make sure

  • the defined minimum of each dependency is actually still being tested
  • no silent regressions (like using too new methods of depending libraries) sneaked in

For details, see Why and when is this useful?. This has been built after Composer didn't have the motivation for it.

A total must-have for

  • frameworks
  • framework plugins/addons (and testing against the framework minors)
  • custom libraries to be used by apps/projects which have at least one dependency to other libraries

It is somewhat important for the involved packages to follow semver here. Otherwise some of the comparison might be problematic.

This is not so useful for projects, as here there is no need to test against anything than latest versions already in use. Also, if your library has no dependencies, you can skip prefer-lowest checks as well as this validation.

Local Test-Run

You want to give it a quick test-spin for one of your libraries? See what results it yields?

composer update --prefer-lowest --prefer-dist --prefer-stable
composer require --dev --update-with-all-dependencies dereuromark/composer-prefer-lowest
vendor/bin/validate-prefer-lowest

If there is no output, that's good. echo $? should return 0 (success).

CI Installation

It is recommended to run only for CI and composer update --prefer-lowest. As such, it suffices to add it conditionally here.

E.g. for Travis CI:

php:
  - 7.3
  - 8.1

env:
  global:
    - DEFAULT=1

matrix:
  include:
    - php: 7.3
      env: PREFER_LOWEST=1

before_script:
  - if [[ $PREFER_LOWEST != 1 ]]; then composer install --prefer-source --no-interaction; fi
  - if [[ $PREFER_LOWEST == 1 ]]; then composer update --prefer-lowest --prefer-dist --prefer-stable --no-interaction; fi
  - if [[ $PREFER_LOWEST == 1 ]]; then composer require --dev dereuromark/composer-prefer-lowest; fi

script:
  - if [[ $DEFAULT == 1 ]]; then vendor/bin/phpunit; fi
  - if [[ $PREFER_LOWEST == 1 ]]; then vendor/bin/validate-prefer-lowest; fi

You can, of course, also directly include it into require-dev. After manually running composer update --prefer-lowest locally, you can also test this on your local computer then:

vendor/bin/validate-prefer-lowest

It returns the list of errors and exits with error code 1 if any violations are found. Otherwise it returns with success code 0.

Prefer stable

Usually composer update --prefer-lowest suffices. Make sure you have "prefer-stable": true in your composer.json for this to work. Otherwise you might have to use the longer version as outlined above.

In general it is best to just use all flags for your CI script:

composer update --prefer-lowest --prefer-dist --prefer-stable --no-interaction

Majors only

If you want to only error the CI build for major constraint issues, use --majors-only/-m option:

vendor/bin/validate-prefer-lowest -m

The patch and minor issues will then be warnings only.

Display only

If you want to just display the result in your CI report without failing the build, you could do:

vendor/bin/validate-prefer-lowest || true

PHP version

In general: Use the minimum PHP version for prefer-lowest as defined in your composer.json.

This tool requires minimum PHP 7.3, as such make sure your library to test also runs on this (or higher) for the prefer-lowest CI job. At this point, with it being EOL already, you can and should not use any PHP version below 7.3 anyway, or provide support for it.

It is advised to also raise your composer.json entry for the min PHP version here. Use 7.3 or higher:

    "require": {
        "php": ">=7.3",

Local Composer Script Installation

For local testing, when you do not want to modify your composer.json file, you can simple add this composer script:

"scripts": {
    ...
    "lowest": " validate-prefer-lowest",
    "lowest-setup": "composer update --prefer-lowest --prefer-stable --prefer-dist --no-interaction && cp composer.json composer.backup && composer require --dev --update-with-all-dependencies dereuromark/composer-prefer-lowest && mv composer.backup composer.json",

Then run composer lowest-setup to set up the script and finally composer lowest to execute.

TODOs

  • Better version handling, especially around special cases like suffixes.

Help is greatly appreciated.

You might also like...
Analyzer of PHP code to search issues with deprecated functionality in newer interpreter versions.

PhpDeprecationDetector PhpDeprecationDetector - analyzer of PHP code to search usages of deprecated functionality in newer interpreter versions - depr

Automatically delete old SiteTree page versions from Silverstripe

Version truncator for Silverstripe An extension for Silverstripe to automatically delete old versioned DataObject records from your database when a re

Algolia Search integration for Magento 1 - compatible with versions from 1.6.x to 1.9.x

Algolia Search for Magento 1.6+ End of Support 🚨 The Algolia Magento 1 extension has reached End of Life regarding support and maintenance. We do not

Algolia Search integration for Magento 2 - compatible with versions from 2.3.x to 2.4.x

Algolia Search for Magento 2 🔎 Need help? Check out our Technical Troubleshooting Guide. For feedback, bug reporting, or unresolved issues with the e

A tool that can be used to verify BC breaks between two versions of a PHP library.

Roave Backward Compatibility Check A tool that can be used to verify BC breaks between two versions of a PHP library. Pre-requisites/assumptions Your

This project backports features found in the latest PHP versions and provides compatibility layers for some extensions and functions

This project backports features found in the latest PHP versions and provides compatibility layers for some extensions and functions. It is intended to be used when portability across PHP versions and extensions is desired.

Analyzer of PHP code to search issues with deprecated functionality in newer interpreter versions.

PhpDeprecationDetector PhpDeprecationDetector - analyzer of PHP code to search usages of deprecated functionality in newer interpreter versions - depr

A MCPE server software that backporting new Minecraft: Bedrock Edition to older PocketMine versions with better stability and performance.
A MCPE server software that backporting new Minecraft: Bedrock Edition to older PocketMine versions with better stability and performance.

CoarseMC is a server software that backports new Minecraft: Bedrock Edition versions to older PocketMine versions with better stability and performance, while retaining as many features from the new PocketMine-MP versions as possible.

A high-performance license server system service for creating and managing products, major versions, and software licenses for the purpose of selling installable software products.
A high-performance license server system service for creating and managing products, major versions, and software licenses for the purpose of selling installable software products.

A high-performance license server system service for creating and managing products, major versions, and software licenses for the purpose of selling installable software products. Comes with a SDK and command-line tool. Works anywhere that PHP runs.

Comments
  • Cannot use version ranges

    Cannot use version ranges

    We are hitting this error in cakephp-codesniffer with this version constraint:

    "slevomat/coding-standard": ">=6.0 <6.2"

    https://travis-ci.com/github/cakephp/cakephp-codesniffer/jobs/319510577

    Fatal error: Uncaught UnexpectedValueException: Invalid version string "6.0 <6.2" in /home/travis/build/cakephp/cakephp-codesniffer/vendor/composer/semver/src/VersionParser.php:176
    Stack trace:
    #0 /home/travis/build/cakephp/cakephp-codesniffer/vendor/dereuromark/composer-prefer-lowest/src/Validator.php(205): Composer\Semver\VersionParser->normalize('6.0 <6.2')
    #1 /home/travis/build/cakephp/cakephp-codesniffer/vendor/dereuromark/composer-prefer-lowest/src/Validator.php(111): ComposerPreferLowest\Validator->normalizeVersion('6.0 <6.2')
    #2 /home/travis/build/cakephp/cakephp-codesniffer/vendor/dereuromark/composer-prefer-lowest/src/Validator.php(62): ComposerPreferLowest\Validator->definedMinimum(Array, 'slevomat/coding...')
    #3 /home/travis/build/cakephp/cakephp-codesniffer/vendor/dereuromark/composer-prefer-lowest/src/Validator.php(42): ComposerPreferLowest\Validator->compare('/home/travis/bu...', '/home/travis/bu...', Array)
    #4 /home/travis/build/cakephp/cakephp-codesniffer/vendor/dereuromark/composer-prefer-lowest/bin/vali in /home/travis/build/cakephp/cakephp-codesniffer/vendor/composer/semver/src/VersionParser.php on line 176
    
    opened by othercorey 4
  • Allow x.y.* syntax

    Allow x.y.* syntax

    Fatal error: Uncaught UnexpectedValueException: Invalid version string "3.5.*" in /home/travis/build/cakephp/cakephp-codesniffer/vendor/composer/semver/src/VersionParser.php:172
    Stack trace:
    #0 /home/travis/build/cakephp/cakephp-codesniffer/vendor/dereuromark/composer-prefer-lowest/src/Validator.php(182): Composer\Semver\VersionParser->normalize('3.5.*')
    #1 /home/travis/build/cakephp/cakephp-codesniffer/vendor/dereuromark/composer-prefer-lowest/src/Validator.php(57): ComposerPreferLowest\Validator->normalizeVersion('3.5.*')
    
    bug 
    opened by dereuromark 1
  • Whitelist certain warnings

    Whitelist certain warnings

    Add a way to whitelist certain "version" errors as version warnings (="acceptable") Could be a composer config key=>value pair or some metafile to read from.

    Thoughts welcome.

    For now, you can do it by declaring them in require-dev in a higher version that works for the prefer-lowest build.

    enhancement help wanted 
    opened by dereuromark 0
Releases(0.1.10)
  • 0.1.10(Nov 2, 2021)

  • 0.1.9(Oct 12, 2021)

    Improvements

    Support a min/max range of e.g. "^4.2.12 < 4.3.0 || ^4.3.8 || ^5.0.0". The first is internally translated to "[== 4.2.12.0 < 4.3.0.0-dev]" and therefore needs special treatment.

    Source code(tar.gz)
    Source code(zip)
  • 0.1.8(Sep 8, 2021)

    Improvements

    PHP 7.2+ with types added and PHP 8 checking in CI. From using side nothing should change or be an issue if you use a high enough PHP version to run this tool.

    Source code(tar.gz)
    Source code(zip)
  • 0.1.7(Apr 29, 2021)

  • 0.1.6(Apr 15, 2020)

  • 0.1.5(Mar 29, 2020)

  • 0.1.4(Dec 4, 2019)

  • 0.1.3(Feb 4, 2019)

  • 0.1.2(Jan 5, 2019)

    Improvements

    When declared both in require and require-dev, this issues just a warning, not an error. The build will not fail, as this seems to be intentional (to make prefer-lowest pass here). Still a valid warning, as this way it is impossible to test the promised minimum. Consider injecting the require-dev dependency in Travis more dynamically where needed.

    Source code(tar.gz)
    Source code(zip)
  • 0.1.1(Jan 3, 2019)

  • 0.1.0(Jan 3, 2019)

    Initial Release

    Try it out :)

    E.g. for Travis CI:

    php:
      - ...
      - 7.3
    
    env:
      global:
        - DEFAULT=1
    
    matrix:
      include:
        - php: 5.6
          env: PREFER_LOWEST=1
    
    before_script:
      - if [[ $PREFER_LOWEST != 1 ]]; then composer install --prefer-source --no-interaction; fi
      - if [[ $PREFER_LOWEST == 1 ]]; then composer update --prefer-lowest --prefer-dist --prefer-stable --no-interaction; fi
      - if [[ $PREFER_LOWEST == 1 ]]; then composer require --dev dereuromark/composer-prefer-lowest; fi
    
    script:
      - if [[ $DEFAULT == 1 ]]; then vendor/bin/phpunit; fi
      - if [[ $PREFER_LOWEST == 1 ]]; then vendor/bin/validate-prefer-lowest; fi
    
    Source code(tar.gz)
    Source code(zip)
Owner
Mark Scherer
Senior Software Developer, Tooling Architect & Master of Automation
Mark Scherer
YCOM Impersonate. Login as selected YCOM user 🧙‍♂️in frontend.

YCOM Impersonate Login as selected YCOM user in frontend. Features: Backend users with admin rights or YCOM[] rights, can be automatically logged in v

Friends Of REDAXO 17 Sep 12, 2022
Composer Repository Manager for selling Magento 2 extension and offering composer installation for ordered packages.

Magento 2 Composer Repository Credits We got inspired by https://github.com/Genmato. Composer Repository for Magento 2 This extension works as a Magen

EAdesign 18 Dec 16, 2021
JSONFinder - a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

JSONFinder - a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

Eboubaker Eboubaker 2 Jul 31, 2022
RedeemeRadio is the radio station of Alexander Schliker, our Redeemer and Super Hero (he actually flies).

RedeemeRadio - README Welcome to the RedeemeRadio project -- an open source project for allowing broadcasting the radio of Alexander Schliker, our Sup

RedeemeRadio 1 Nov 21, 2021
This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards

PHP_CodeSniffer Standards Composer Installer Plugin This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards (r

PHPCSStandards 393 Feb 25, 2022
PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.

PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.

Squiz Labs 9.9k Jan 5, 2023
Dependency graph visualization for composer.json (PHP + Composer)

clue/graph-composer Graph visualization for your project's composer.json and its dependencies: Table of contents Usage graph-composer show graph-compo

Christian Lück 797 Jan 5, 2023
The Phar Installation and Verification Environment (PHIVE)

The Phar Installation and Verification Environment (PHIVE) Installation and verification of phar distributed PHP applications has never been this easy

null 509 Dec 29, 2022
Secure package for WP CLI, built to provide an easier way of securing your WordPress installation

wp-cli/secure-command Official website: Hackthewp.com Manages common security aspects of WordPress. Supports nginx and Apache. Basic Usage This packag

Igor Hrcek 68 Dec 27, 2022
A WordPress package to nudge users to upgrade their software versions (starting with PHP)

whip A WordPress package to nudge users to upgrade their software versions (starting with PHP) Requirements The following versions of PHP are supporte

Yoast 71 Oct 18, 2022