Skip to content
A wrapper for ocramius/package-versions to get pretty versions strings
PHP
Branch: master
Clone or download
Latest commit 8f65807 Nov 18, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Add getShortCommitHash method Jun 13, 2018
tests Add getShortCommitHash method Jun 13, 2018
.gitattributes
.gitignore Add composer.json Jul 5, 2017
.scrutinizer.yml Create first class and first test; complete the readme and add CI Jul 5, 2017
.travis.yml Add PHP 7.4 to the build Nov 18, 2019
CHANGELOG.md Release 1.2 Jun 13, 2018
LICENSE Initial commit Jul 5, 2017
README.md
composer.json Fix description in composer.json Jun 13, 2018
composer.lock Update composer.lock to PHP 7.2 Jan 21, 2018
phpunit.xml.dist Create first class and first test; complete the readme and add CI Jul 5, 2017

README.md

jean85/pretty-package-versions

PHP Version Stable release Unstable release composer.lock available

Build status Coverage Status Scrutinizer SL Insight

A wrapper for ocramius/package-versions to get pretty versions strings.

Installation

To use this package, use Composer:

  • from CLI: composer require jean85/pretty-package-versions
  • or, directly in your composer.json:
{
    "require-dev": {
        "jean85/pretty-package-versions": "~1.0"
    }
}

Usage

This package should be used with a single class, Jean85\PrettyVersions, which wraps PackageVersions\Versions; it provides a single method that returns a Jean85\Version object for the requested package, like in this example:

use Jean85\PrettyVersions;

$version = PrettyVersions::getVersion('phpunit/phpunit');
$version->getPrettyVersion(); // '6.0.0'
$version->getShortVersion(); // '6.0.0'
$version->getVersionWithShortCommit(); // '6.0.0@fa5711'

$version = PrettyVersions::getVersion('roave/security-advisories');
$version->getPrettyVersion(); // 'dev-master@7cd88c8'
$version->getShortVersion(); // 'dev-master'
$version->getVersionWithShortCommit(); // 'dev-master@7cd88c8'

The Version class has also a __toString() method implemented, so it can be easily cast to a string; the result would be the same as calling the getPrettyVersion() method.

Available methods

The Jean85\Version class has these public methods available:

  • getPrettyVersion(): string: if the requested package is a tagged version, it will return just the short version; if not, it will output the same result as getVersionWithShortCommit()

  • getShortVersion(): string: it will return just the version of the package (i.e. 6.0.0, v.1.7.0, 99999-dev etc...)

  • getVersionWithShortCommit(): string: it will return the version of the package, followed by the short version of the commit hash (i.e. 6.0.0@fa5711)

  • getPackageName(): string will return the original package name

  • getFullVersion(): string will return the same value as PackageVersions\Versions::getVersion()

  • getCommitHash(): string will return the full commit hash

  • getShortCommitHash(): string will return the short commit hash (i.e. fa5711)

  • __toString(): string will return the same as getPrettyVersion()

You can’t perform that action at this time.