PHPackages                             florianwolters/component-core-comparable - 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. florianwolters/component-core-comparable

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

florianwolters/component-core-comparable
========================================

Imposes a total ordering on objects as a PHP component.

v0.2.0(13y ago)018312LGPL-3.0+PHPPHP &gt;=5.4

Since Mar 1Pushed 12y ago1 watchersCompare

[ Source](https://github.com/FlorianWolters/PHP-Component-Core-Comparable)[ Packagist](https://packagist.org/packages/florianwolters/component-core-comparable)[ Docs](http://github.com/FlorianWolters/PHP-Component-Core-Comparable)[ RSS](/packages/florianwolters-component-core-comparable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (2)

FlorianWolters\\Component\\Core\\Comparable
===========================================

[](#florianwolterscomponentcorecomparable)

[![Build Status](https://camo.githubusercontent.com/af18b3dfea19873fa0bd085c014e4bc588733a796796a1050daa6cd24323988f/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f466c6f7269616e576f6c746572732f5048502d436f6d706f6e656e742d436f72652d436f6d70617261626c652e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/FlorianWolters/PHP-Component-Core-Comparable)[![Dependency Status](https://camo.githubusercontent.com/684e2af298ada720f35e299c6fc5b222fa472883a155b4f3fd608beb313e6767/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3531633333306631353836326334303030323030303533632f62616467652e706e67)](http://www.versioneye.com/user/projects/51c330f15862c4000200053c)[![Scrutinizer](https://camo.githubusercontent.com/2823122473871c8933511e32c863a9f1903e3b17e9aed5fda8d6601b65589f6a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f696d616765732f6272616e642d6e61766261722e706e67)](https://scrutinizer-ci.com/g/FlorianWolters/PHP-Component-Core-Comparable/inspections)

**FlorianWolters\\Component\\Core\\Comparable** is a simple-to-use [PHP](http://php.net "PHP: Hypertext Preprocessor") component that imposes a total ordering on objects.

Introduction
------------

[](#introduction)

This component is inspired by the following three artifacts of the [Java](http://java.com "java.com: Java + You") programming language.

- The interface [`java.lang.Comparable`](http://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html "Comparable (Java Platform SE 7)") of the [Java](http://java.com "java.com: Java + You") Platform Standard Edition (SE).
- The interface [`java.util.Comparator`](http://docs.oracle.com/javase/7/docs/api/java/util/Comparator.html "Comparator (Java Platform SE 7)") of the [Java](http://java.com "java.com: Java + You") Platform SE.
- The method [`org.apache.commons.lang3.ObjectUtils.compare`](http://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/ObjectUtils.html#compare%28T,%20T,%20boolean%29 "ObjectUtils (Commons Lang 3.1 API)") of the [Apache Commons Lang API](http://commons.apache.org/lang "Commons Lang"):

**FlorianWolters\\Component\\Core\\Comparable** consists of two artifacts:

1. The interface [`FlorianWolters\Component\Core\ComparableInterface`](src/php/FlorianWolters/Component/Core/ComparableInterface.php "FlorianWolters\Component\Core\ComparableInterface"): Imposes a *total ordering* on the objects of each class that implements it.
2. The static class [`FlorianWolters\Component\Core\ComparableUtils`](src/php/FlorianWolters/Component/Core/ComparableUtils.php "FlorianWolters\Component\Core\ComparableUtils"): Offers comparison operations that impose a *total ordering* on objects.

Features
--------

[](#features)

- The static method `FlorianWolters\Component\Core\ComparableUtils::compare` is `null`-safe. A client can determine if `null` is considered greater than a non-`null` value or if `null` is considered less than a non-`null` value.
- Artifacts tested with both static and dynamic test procedures:

    - Dynamic component tests (unit tests) implemented using [PHPUnit](http://phpunit.de "sebastianbergmann/phpunit · GitHub").
    - Static code analysis performed using the following tools:
        - [PHP\_CodeSniffer](http://pear.php.net/package/PHP_CodeSniffer "PHP_CodeSniffer"): Style Checker
        - [PHP Mess Detector (PHPMD)](http://phpmd.org "PHPMD - PHP Mess Detector"): Code Analyzer
        - [phpcpd](https://github.com/sebastianbergmann/phpcpd "sebastianbergmann/phpcpd · GitHub"): Copy/Paste Detector (CPD)
        - [phpdcd](https://github.com/sebastianbergmann/phpdcd "sebastianbergmann/phpdcd · GitHub"): Dead Code Detector (DCD)
- Installable via [Composer](http://getcomposer.org "Composer") or the [PEAR command line installer](http://pear.php.net/manual/en/guide.users.commandline.cli.php "Manual :: Command line installer (PEAR)"):

    - Provides a [Packagist](http://packagist.org "Packagist") package which can be installed using the dependency manager [Composer](http://getcomposer.org "Composer").

        Click [here](http://packagist.org/packages/florianwolters/component-core-comparable "florianwolters/component-core-comparable - Packagist") for the package on [Packagist](http://packagist.org "Packagist").
    - Provides a [PEAR package](http://pear.php.net/manual/en/guide.users.concepts.package.php "Manual :: PEAR Packages") which can be installed using the package manager [PEAR installer](http://pear.php.net/manual/en/guide.users.commandline.cli.php "Manual :: Command line installer (PEAR)").

        Click [here](http://pear.florianwolters.de "PEAR channel of Florian Wolters") for the [PEAR channel](http://pear.php.net/manual/en/guide.users.concepts.channel.php "Manual :: PEAR Channels").
- Provides a complete Application Programming Interface (API) documentation generated with the documentation generator [ApiGen](http://apigen.org "ApiGen | API documentation generator for PHP 5.3.+").

    Click [here](http://blog.florianwolters.de/PHP-Component-Core-Comparable "FlorianWolters\Component\Core | Application Programming Interface (API) documentation") for the current API documentation.
- Follows the [PSR-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md "PSR-0 requirements for autoloader interoperability") requirements for autoloader interoperability.
- Follows the [PSR-1](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md "PSR-1 basic coding style guide") basic coding style guide.
- Follows the [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md "PSR-2 coding style guide") coding style guide.
- Follows the [Semantic Versioning](http://semver.org "Semantic Versioning") Specification (SemVer) 2.0.0-rc.1.

Requirements
------------

[](#requirements)

- [PHP](http://php.net "PHP: Hypertext Preprocessor") &gt;= 5.4

Usage
-----

[](#usage)

The best documentation for **FlorianWolters\\Component\\Core\\Comparable** are the unit tests, which are shipped in the package. You will find them installed into your [PEAR](http://pear.php.net "PEAR - PHP Extension and Application Repository") repository, which on Linux systems is normally `/usr/share/php/test`.

Installation
------------

[](#installation)

### Local Installation

[](#local-installation)

**FlorianWolters\\Component\\Core\\Comparable** should be installed using the dependency manager [Composer](http://getcomposer.org "Composer"). [Composer](http://getcomposer.org "Composer") can be installed with [PHP](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md "PSR-0 requirements for autoloader interoperability").

```
php -r "eval('?>'.file_get_contents('http://getcomposer.org/installer'));"

```

> This will just check a few [PHP](http://php.net "PHP: Hypertext Preprocessor") settings and then download `composer.phar` to your working directory. This file is the [Composer](http://getcomposer.org "Composer") binary. It is a PHAR ([PHP](http://php.net "PHP: Hypertext Preprocessor") archive), which is an archive format for [PHP](http://php.net "PHP: Hypertext Preprocessor") which can be run on the command line, amongst other things.
>
> Next, run the `install` command to resolve and download dependencies:

```
php composer.phar install

```

### System-Wide Installation

[](#system-wide-installation)

**FlorianWolters\\Component\\Core\\Comparable** should be installed using the [PEAR installer](http://pear.php.net/manual/en/guide.users.commandline.cli.php "Manual :: Command line installer (PEAR)"). This installer is the [PHP](http://php.net "PHP: Hypertext Preprocessor") community's de-facto standard for installing [PHP](http://php.net "PHP: Hypertext Preprocessor") components.

```
pear channel-discover pear.florianwolters.de
pear install --alldeps fw/Comparable

```

As A Dependency On Your Component
---------------------------------

[](#as-a-dependency-on-your-component)

### Composer

[](#composer)

If you are creating a component that relies on **FlorianWolters\\Component\\Core\\Comparable**, please make sure that you add **FlorianWolters\\Component\\Core\\Comparable** to your component's `composer.json` file:

```
{
    "require": {
        "florianwolters/component-core-comparable": "0.2.*"
    }
}
```

### PEAR

[](#pear)

If you are creating a component that relies on **FlorianWolters\\Component\\Core\\Comparable**, please make sure that you add **FlorianWolters\\Component\\Core\\Comparable** to your component's `package.xml` file:

```

      Comparable
      pear.florianwolters.de
      0.2.0
      0.2.99

```

Development Environment
-----------------------

[](#development-environment)

If you want to patch or enhance this component, you will need to create a suitable development environment. The easiest way to do that is to install [phix4componentdev](https://github.com/stuartherbert/phix4componentdev "stuartherbert/phix4componentdev · GitHub"):

```
# phix4componentdev
pear channel-discover pear.phix-project.org
pear install phix/phix4componentdev

```

You can then clone the Git repository:

```
# PHP-Component-Core-Comparable
git clone http://github.com/FlorianWolters/PHP-Component-Core-Comparable

```

Then, install a local copy of this component's dependencies to complete the development environment:

```
# build vendor/ folder
phing build-vendor

```

To make life easier for you, common tasks (such as running unit tests, generating code review analytics, and creating the [PEAR package](http://pear.php.net/manual/en/guide.users.concepts.package.php "Manual :: PEAR Packages")) have been automated using [phing](http://phing.info "Phing"). You'll find the automated steps inside the `build.xml` file that ships with the component.

Run the command `phing` in the component's top-level folder to see the full list of available automated tasks.

License
-------

[](#license)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see .

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~9 days

Total

3

Last Release

4808d ago

PHP version history (2 changes)v0.1.0PHP &gt;=5.3

v0.1.1PHP &gt;=5.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/75dd7e42d69a87c4a0c68b4f29f5d223eb1f9a3f647abafa72da80d2a06d2442?d=identicon)[FlorianWolters](/maintainers/FlorianWolters)

---

Top Contributors

[![FlorianWolters](https://avatars.githubusercontent.com/u/1318837?v=4)](https://github.com/FlorianWolters "FlorianWolters (20 commits)")

---

Tags

corecomparisoncompareTocomparable

### Embed Badge

![Health badge](/badges/florianwolters-component-core-comparable/health.svg)

```
[![Health](https://phpackages.com/badges/florianwolters-component-core-comparable/health.svg)](https://phpackages.com/packages/florianwolters-component-core-comparable)
```

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[fidry/cpu-core-counter

Tiny utility to get the number of CPU cores.

238148.2M23](/packages/fidry-cpu-core-counter)[typo3/cms-composer-installers

TYPO3 CMS Installers

6113.7M52](/packages/typo3-cms-composer-installers)[icecave/parity

A customizable deep comparison library.

516.8M10](/packages/icecave-parity)[phootwork/lang

Missing PHP language constructs

1224.8M8](/packages/phootwork-lang)[atomescrochus/laravel-string-similarities

Compare two string and get a similarity percentage

70160.1k2](/packages/atomescrochus-laravel-string-similarities)

PHPackages © 2026

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