Composer is a dependency management tool for projects running on PHP. PHP frameworks like Laravel, Symfony, and CodeIgniter use Composer to manage libraries and packages.

In this tutorial, you’ll learn the following:

  • Introduction to Composer.
  • Minimum stability in Composer.
  • Levels of stability, and the recommended version for production code.

One of the benefits of using a dependency tool is that it makes it easy to declare the key-value pair of packages you need for your project. This way, you can install dependencies via the composer install command or update them via the composer update command in the terminal.

Introduction to Composer

In Laravel, the composer.json is a JSON file located at the root of the project directory. It contains sample configurations used for dependency management, such as the project name, type (optional), description (optional), and the list of required packages.

These packages are represented using key-value pairs (name and version to be installed). Additionally, the composer.json file includes some required packages for the development environment which can be added as part of the configuration setup.

Here's what a composer.json file looks like:

{
    "name": "laravel/laravel",    
    "type": "project",    
    "description": "The Laravel Framework.",    
    "keywords": [        
        "framework",        
        "laravel"    
    ],    
    "license": "MIT",    
    "require": {        
       "php": "^8.1",        
       "laravel/framework": "^10.0",    
    },    
    "require-dev": {    
         .    
         .     
    },    
    "config": {    
         .    
         .    
    },    
    "minimum-stability": "dev"| "alpha"| "beta"| "RC"|"stable", //stable
}
composer.json file

What is Minimum Stability?

In Composer, the “minimum-stability” configuration specifies the minimum stability level for all installed packages.

Packages to be installed or updated will use the minimum-stability value to determine version limitations during dependency resolution.

Levels of Stability

The following are the different stability levels:

  • dev: This is the least stable version, and should never be used in production. It often includes packages under active development that may contain bugs or breaking changes and may still undergo significant modifications. It is only recommended for local development purposes.
  • alpha: It's a version also undergoing development but in a more stable state. It usually contains fewer breaking changes and features nearing final completion or awaiting a beta release. However, it is also not highly recommended for production environments.
  • beta: This version is currently being tested, and minor bugs, when noticed, will need to be fixed. However, it is more stable than the alpha and dev versions, but it's still not recommended for production purposes.
  • RC: The RC (Release Candidate) is a version pending official release. It's the closest to being stable, but the version requires community testing and feedback prior to the final release. Undiscovered bugs can also be identified during this phase, so it's best practice not to use it for production purposes.
  • stable: This is the required level for production purposes. It includes all packages that have gone through significant changes, bug fixes, community testing, feedback, and is now ready to use.

In your composer.json, you can specify the minimum stability by doing the following:

{
    "minimum-stability": "stable"
}
minimum-stability config

Conclusion

In this article, you have learned about Composer, the composer.json file, minimum stability, and, most importantly, the levels of stability offered by Composer.

For your application, you should carefully choose the stability level that satisfies your production needs, while keeping security and downtime issues in mind. Remember, your application should only depend on stable and reliable packages.

I hope you now have a better understanding of minimum stability.

Keep learning, and Happy Coding!

You can find me on LinkedIn and Twitter.