scheb/comparator

This package is abandoned and no longer maintained. No replacement package was suggested.

Compares to values for equality

v1.0.0 2018-09-02 12:38 UTC

This package is auto-updated.

Last update: 2022-01-11 13:25:31 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version License

This library compares two values for equality.

If you need to add your own rules for comparing specific values, you can extend the library with your own comparison strategies.

Features

  • Simple equality comparison (== or ===)
  • Strategy interface for your own comparison rules

Installation

composer require scheb/comparator

How to use

$comparator = new \Scheb\Comparator\Comparator(true); // Type-sensive equal (===)
$comparator->isEqual(0, "0"); // Returns false
$comparator->isEqual(0, ""); // Returns false
$comparator->isEqual(0, 0); // Returns true
$comparator->isEqual(0, "foo"); // Returns false

$comparator = new \Scheb\Comparator\Comparator(false); // Type-insensive equal (==)
$comparator->isEqual(0, "0"); // Returns true
$comparator->isEqual(0, ""); // Returns true
$comparator->isEqual(0, 0); // Returns true
$comparator->isEqual(0, "foo"); // Returns false

How to extend

To add your own comparison strategy, implement Scheb\Comparator\ValueComparisonStrategyInterface.

Then, add an instance of that class via the constructor argument $customComparisonStrategies of Scheb\Comparator\Comparator.

Custom comparison strategies take preference over default ones.

Contribute

You're welcome to contribute to this library by creating a pull requests or feature request in the issues section. For pull requests, please follow these guidelines:

  • Symfony code style
  • PHP7.1 type hints for everything (including: return types, void, nullable types)
  • Please add/update test cases
  • Test methods should be named [method]_[scenario]_[expected result]

To run the test suite install the dependencies with composer install and then execute bin/phpunit.

License

This bundle is available under the MIT license.