/valuewrapper

This simple library allows you to wrap any kind of PHP variable in a strict typed PHP object.

Primary LanguagePHPMIT LicenseMIT

Latest Stable Version Total Downloads Build Status Build status Scrutinizer Code Quality Code Coverage Codacy Badge Mutation testing badge License

ValueWrapper

Description

This simple library allows you to wrap any kind of PHP variable in a strict typed PHP object.

Requirements

  • PHP >= 7.1

Installation

composer require drupol/valuewrapper

Usage

$string = 'Hello world!';
$value = ValueWrapper::create($string); // This creates a StringType object.

$integer = 123;
$value = ValueWrapper::create($string); // This creates an IntegerType object.

$closure = function (string $who) {return 'Hello ' . $who;};
$value = ValueWrapper::create($closure); // This creates a ClosureObject object.

$value('world'); // Return 'Hello world'.
$value->hash(); // Return '513c4a7d0c1e07fa75e40c842880c82cffa69c5d'.

$anotherClosure = function () {return 'Hello world';};
$anotherValue = ValueWrapper::create($anotherClosure);
$value->equals($anotherValue); // Return false.

$sameClosure = function (string $who) {return 'Hello ' . $who;};
$sameValue = ValueWrapper::create($sameClosure);
$value->equals($sameValue); // Return true.

Code quality and tests

Every time changes are introduced into the library, Travis CI run the tests and the benchmarks.

The library has tests written with PHPSpec. Feel free to check them out in the spec directory. Run composer phpspec to trigger the tests.

PHPInfection is used to ensure that your code is properly tested, run composer infection to test your code.

Contributing

Feel free to contribute to this library by sending Github pull requests. I'm quite reactive :-)