PHPackages                             rayne/semantic-versioning - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. rayne/semantic-versioning

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rayne/semantic-versioning
=========================

A tiny independent library for parsing and comparing semantic versions.

1.1.0(9y ago)4214MITPHPPHP &gt;=5.6

Since Dec 22Pushed 8y ago2 watchersCompare

[ Source](https://github.com/Rayne/semantic-versioning.php)[ Packagist](https://packagist.org/packages/rayne/semantic-versioning)[ RSS](/packages/rayne-semantic-versioning/feed)WikiDiscussions master Synced today

READMEChangelog (5)Dependencies (1)Versions (8)Used By (0)

Rayne\\SemanticVersioning
=========================

[](#raynesemanticversioning)

A tiny independent library for parsing and comparing semantic versions which is compatible with [Semantic Versioning 2.0](http://semver.org).

[![Latest Stable Version](https://camo.githubusercontent.com/b43ef4d173880f1d295cb47125fe7300de5080d753441bed4714b6f6609066b6/68747470733a2f2f706f7365722e707567782e6f72672f7261796e652f73656d616e7469632d76657273696f6e696e672f762f737461626c65)](https://packagist.org/packages/rayne/semantic-versioning)[![Latest Unstable Version](https://camo.githubusercontent.com/c7806d7194a8d442b610445cfddc37c3b113ddd49966f18865355326fdfd86fb/68747470733a2f2f706f7365722e707567782e6f72672f7261796e652f73656d616e7469632d76657273696f6e696e672f762f756e737461626c65)](https://packagist.org/packages/rayne/semantic-versioning)[![Build Status](https://camo.githubusercontent.com/1fc4a24d968c1abd0e4ec4c0fe9e1111d891edf00103957e27a98b600bd9773a/68747470733a2f2f7472617669732d63692e6f72672f5261796e652f73656d616e7469632d76657273696f6e696e672e7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Rayne/semantic-versioning.php)[![Code Coverage](https://camo.githubusercontent.com/2f5c867c996eeaf345abea6b526854bb8efa897c672a7bbeea40d9fabf95007c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5261796e652f73656d616e7469632d76657273696f6e696e672e7068702f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Rayne/semantic-versioning.php/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/00964dffcc7f85e015a6f9808c94d23b88c70a2c2d5f9788d08d244b2c1b58d3/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5261796e652f73656d616e7469632d76657273696f6e696e672e7068702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Rayne/semantic-versioning.php/?branch=master)[![License](https://camo.githubusercontent.com/8a5d5cb2295d92bc54bc83c828af11c52bb8a7fd0c2813d1797c72e3abf5c436/68747470733a2f2f706f7365722e707567782e6f72672f7261796e652f73656d616e7469632d76657273696f6e696e672f6c6963656e7365)](https://packagist.org/packages/rayne/semantic-versioning)

Dependencies
------------

[](#dependencies)

### Production

[](#production)

- PHP 5.6 or better

### Development

[](#development)

- Composer
- Git
- PHPUnit

Setup
-----

[](#setup)

[Download Composer](https://getcomposer.org/download) and install `rayne/semantic-versioning`.

```
composer require rayne/semantic-versioning

```

Tests
-----

[](#tests)

1. Clone the repository

    ```
    git clone https://github.com/rayne/semantic-versioning.php.git

    ```
2. Install the development dependencies

    ```
    composer install --dev

    ```
3. Run the tests

    ```
    ./vendor/bin/phpunit

    ```

Examples
--------

[](#examples)

The library contains the following classes:

- `InvalidVersionException`: Thrown by `SemanticVersion` on invalid input
- `SemanticComparator`: The semantic versioning comparator for comparing `SemanticVersion` objects
- `SemanticVersion`: The semantic versioning parser which throws a `RuntimeException` on invalid versions

The examples are part of the test suite. Have a look at the `tests` directory for more information.

### Interpret semantic versions

[](#interpret-semantic-versions)

```
use Rayne\SemanticVersioning\SemanticVersion;

$version = new SemanticVersion('1.0.0-beta+exp.sha.5114f85');

assert('1.0.0-beta+exp.sha.5114f85' === (string) $version);
assert( 1                           === $version->getMajor());
assert(   0                         === $version->getMinor());
assert(     0                       === $version->getPatch());
assert(      'beta'                 === $version->getPre());
assert(           'exp.sha.5114f85' === $version->getMeta());
assert('1.0.0-beta+exp.sha.5114f85' === $version->getVersion());

assert(true  === $version->isMajorRelease());
assert(false === $version->isMinorRelease());
assert(false === $version->isPatchRelease());
assert(true  === $version->isPreRelease());
```

### Compare semantic versions

[](#compare-semantic-versions)

```
use Rayne\SemanticVersioning\SemanticComparator;
use Rayne\SemanticVersioning\SemanticVersion;

$comparator     = new SemanticComparator;

$alpha          = new SemanticVersion('1.0.0-alpha');
$candidate      = new SemanticVersion('1.0.0-rc.1');
$candidate_meta = new SemanticVersion('1.0.0-rc.1+ci');
$release        = new SemanticVersion('1.0.0');

// $alpha < $candidate
assert($comparator($alpha, $candidate) < 0);
assert($comparator->compare($alpha, $candidate) < 0);

// $candidate == $candidate_meta
assert($comparator($candidate, $candidate_meta) == 0);
assert($comparator->compare($candidate, $candidate_meta) == 0);

// $release > $candidate
assert($comparator($release, $candidate) > 0);
assert($comparator->compare($release, $candidate) > 0);
```

### Sort semantic versions

[](#sort-semantic-versions)

```
use Rayne\SemanticVersioning\SemanticComparator;
use Rayne\SemanticVersioning\SemanticVersion;

$versions = [
	$candidate = new SemanticVersion('1.0.0-rc.1'),
	$release   = new SemanticVersion('1.0.0'),
	$alpha     = new SemanticVersion('1.0.0-alpha'),
];

// Sort by semantic precedence.
usort($versions, new SemanticComparator);

assert($versions[0] === $alpha);
assert($versions[1] === $candidate);
assert($versions[2] === $release);
```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 97.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~104 days

Total

5

Last Release

3426d ago

PHP version history (2 changes)1.0.0-rc.1PHP &gt;=5.4

1.0.0-rc.3PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/3c8280f00784624f044fa15aa869fd0a3958b0ade356a01297eff1f6240332e2?d=identicon)[Rayne](/maintainers/Rayne)

---

Top Contributors

[![Rayne](https://avatars.githubusercontent.com/u/1098733?v=4)](https://github.com/Rayne "Rayne (36 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

composercomposer-packagesphpphp-librarysemantic-versioningsemverversioningsemantic

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rayne-semantic-versioning/health.svg)

```
[![Health](https://phpackages.com/badges/rayne-semantic-versioning/health.svg)](https://phpackages.com/packages/rayne-semantic-versioning)
```

###  Alternatives

[composer/semver

Version comparison library that offers utilities, version constraint parsing and validation.

3.3k522.3M990](/packages/composer-semver)[nikolaposa/version

Value Object that represents a SemVer-compliant version number.

1407.3M23](/packages/nikolaposa-version)[shivas/versioning-bundle

Symfony application versioning, simple console command to manage version (with providers e.g. git tag) of your application using Semantic Versioning 2.0.0 recommendations

1111.3M1](/packages/shivas-versioning-bundle)[wenzhixin/bootstrap-table

An extended table to integration with some of the most widely used CSS frameworks. (Supports Bootstrap, Semantic UI, Bulma, Material Design, Foundation)

11.8k287.3k1](/packages/wenzhixin-bootstrap-table)[naneau/semver

A decent, standards-compliant, Semantic Versioning (SemVer) parser and library

73522.7k18](/packages/naneau-semver)[pragmarx/version

Take control over your Laravel app version

5931.2M2](/packages/pragmarx-version)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
