ergebnis/version

Provides an abstraction of a semantic version.

1.1.0 2024-03-10 12:44 UTC

This package is auto-updated.

Last update: 2024-11-06 20:45:36 UTC


README

Integrate Merge Release Renew

Code Coverage Type Coverage

Latest Stable Version Total Downloads Monthly Downloads

This project provides a composer package with an abstraction of a semantic version.

Installation

Run

composer require ergebnis/version

Usage

This project comes with the following components:

Version

Create a Version from a string

<?php

declare(strict_types=1);

use Ergebnis\Version;

$version = Version\Version::fromString('1.2.3-alpha+build.9001');

echo $version->toString(); // 1.2.3

echo $version->major()->toString(); // 1
echo $version->minor()->toString(); // 2
echo $version->patch()->toString(); // 3
echo $version->preRelease()->toString(); // alpha
echo $version->buildMetaData()->toString(); // build.9001

Bump a Version

<?php

declare(strict_types=1);

use Ergebnis\Version;

$version = Version\Version::fromString('1.2.3');

$one = $version->bumpMajor();

echo $one->toString(); // 2.0.0

$two = $version->bumpMinor();

echo $two->toString(); // 1.3.0

$three = $version->bumpPatch();

echo $three->toString(); // 1.2.4

Bump a Version with PreRelease

<?php

declare(strict_types=1);

use Ergebnis\Version;

$version = Version\Version::fromString('1.2.3-alpha');

$one = $version->bumpMajor();

echo $one->toString(); // 2.0.0

$two = $version->bumpMinor();

echo $two->toString(); // 1.3.0

$three = $version->bumpPatch();

echo $three->toString(); // 1.2.3

Bump a Version with BuildMetaData

<?php

declare(strict_types=1);

use Ergebnis\Version;

$version = Version\Version::fromString('1.2.3+build.9001');

$one = $version->bumpMajor();

echo $one->toString(); // 2.0.0

$two = $version->bumpMinor();

echo $two->toString(); // 1.3.0

$three = $version->bumpPatch();

echo $three->toString(); // 1.2.4

Compare a Version with another Version

<?php

declare(strict_types=1);

use Ergebnis\Version;

$one = Version\Version::fromString('1.2.3-alpha');
$two = Version\Version::fromString('1.2.3');
$three = Version\Version::fromString('1.2.4');
$four = Version\Version::fromString('1.2.4+build.9001');

$one->compare($two); // -1
$one->compare($one); // 0
$three->compare($one); // 1

$one->isSmallerThan($one); // false
$one->isSmallerThan($two); // true
$one->isSmallerThan($three); // true
$one->isSmallerThan($four); // true

$one->equals($two); // false
$one->equals($one); // true
$one->equals($three); // false
$three->equals($four); // true

$one->isGreaterThan($one); // false
$two->isGreaterThan($one); // true
$three->isGreaterThan($one); // true
$four->isGreaterThan($one); // true

Major

Create a Major from an int

<?php

declare(strict_types=1);

use Ergebnis\Version;

$major = Version\Major::fromInt(1);

echo $major->toString(); // 1

Create a Major from a string

<?php

declare(strict_types=1);

use Ergebnis\Version;

$major = Version\Major::fromString('1');

echo $major->toString(); // 1

Bump a Major

<?php

declare(strict_types=1);

use Ergebnis\Version;

$one = Version\Major::fromString('1');

$two = $one->bump();

echo $two->toString(); // 2

Compare a Major with another Major

<?php

declare(strict_types=1);

use Ergebnis\Version;

$one = Version\Major::fromString('1');
$two = Version\Major::fromString('2');

$one->compare($two); // -1
$one->compare($one); // 0
$two->compare($one); // 1

$one->isSmallerThan($one); // false
$one->isSmallerThan($two); // true

$one->equals($two); // false
$one->equals($one); // true

$one->isGreaterThan($one); // false
$two->isGreaterThan($one); // true

Minor

Create a Minor from an int

<?php

declare(strict_types=1);

use Ergebnis\Version;

$minor = Version\Minor::fromInt(1);

echo $minor->toString(); // 1

Create a Minor from a string

<?php

declare(strict_types=1);

use Ergebnis\Version;

$minor = Version\Minor::fromString('1');

echo $minor->toString(); // 1

Bump a Minor

<?php

declare(strict_types=1);

use Ergebnis\Version;

$one = Version\Minor::fromString('1');

$two = $one->bump();

echo $two->toString(); // 2

Compare a Minor with another Minor

<?php

declare(strict_types=1);

use Ergebnis\Version;

$one = Version\Minor::fromString('1');
$two = Version\Minor::fromString('2');

$one->compare($two); // -1
$one->compare($one); // 0
$two->compare($one); // 1

$one->isSmallerThan($one); // false
$one->isSmallerThan($two); // true

$one->equals($two); // false
$one->equals($one); // true

$one->isGreaterThan($one); // false
$two->isGreaterThan($one); // true

Patch

Create a Patch from an int

<?php

declare(strict_types=1);

use Ergebnis\Version;

$patch = Version\Patch::fromInt(1);

echo $patch->toString(); // 1

Create a Patch from a string

<?php

declare(strict_types=1);

use Ergebnis\Version;

$patch = Version\Patch::fromString('1');

echo $patch->toString(); // 1

Bump a Patch

<?php

declare(strict_types=1);

use Ergebnis\Version;

$one = Version\Patch::fromString('1');

$two = $one->bump();

echo $two->toString(); // 2

Compare a Patch with another Patch

<?php

declare(strict_types=1);

use Ergebnis\Version;

$one = Version\Patch::fromString('1');
$two = Version\Patch::fromString('2');

$one->compare($two); // -1
$one->compare($one); // 0
$two->compare($one); // 1

$one->isSmallerThan($one); // false
$one->isSmallerThan($two); // true

$one->equals($two); // false
$one->equals($one); // true

$one->isGreaterThan($one); // false
$two->isGreaterThan($one); // true

PreRelease

Create a PreRelease from a string

<?php

declare(strict_types=1);

use Ergebnis\Version;

$preRelease = Version\PreRelease::fromString('alpha');

echo $preRelease->toString(); // alpha

Create an empty PreRelease

<?php

declare(strict_types=1);

use Ergebnis\Version;

$preRelease = Version\PreRelease::empty();

echo $preRelease->toString(); // empty

Compare a PreRelease with another PreRelease

<?php

declare(strict_types=1);

use Ergebnis\Version;

$one = Version\PreRelease::fromString('alpha');
$two = Version\PreRelease::fromString('rc.1');

$one->compare($two); // -1
$one->compare($one); // 0
$two->compare($one); // 1

$one->isSmallerThan($one); // false
$one->isSmallerThan($two); // true

$one->equals($two); // false
$one->equals($one); // true

$one->isGreaterThan($one); // false
$two->isGreaterThan($one); // true

BuildMetaData

Create a BuildMetaData from a string

<?php

declare(strict_types=1);

use Ergebnis\Version;

$buildMetaData = Version\BuildMetaData::fromString('build.9001');

echo $buildMetaData->toString(); // build.9001

Create an empty BuildMetaData

<?php

declare(strict_types=1);

use Ergebnis\Version;

$buildMetaData = Version\BuildMetaData::empty();

echo $buildMetaData->toString(); // empty

Compare a BuildMetaData with another BuildMetaData

<?php

declare(strict_types=1);

use Ergebnis\Version;

$one = Version\BuildMetaData::fromString('build.9001');
$two = Version\BuildMetaData::fromString('build.9000');

$one->equals($two); // false
$one->equals($one); // true

Changelog

The maintainers of this project record notable changes to this project in a changelog.

Contributing

The maintainers of this project suggest following the contribution guide.

Code of Conduct

The maintainers of this project ask contributors to follow the code of conduct.

General Support Policy

The maintainers of this project provide limited support.

You can support the maintenance of this project by sponsoring @localheinz or requesting an invoice for services related to this project.

PHP Version Support Policy

This project supports PHP versions with active and security support.

The maintainers of this project add support for a PHP version following its initial release and drop support for a PHP version when it has reached the end of security support.

Security Policy

This project has a security policy.

License

This project uses the MIT license.

Social

Follow @localheinz and @ergebnis on Twitter.