drupol/valuewrapper

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

1.2.0 2019-07-09 07:29 UTC

This package is auto-updated.

Last update: 2020-07-28 11:58:59 UTC


README

Latest Stable Version GitHub stars Total Downloads GitHub Workflow Status Scrutinizer code quality Code Coverage Mutation testing badge License Say Thanks! Donate!

ValueWrapper

Description

This library allows you to wrap PHP variable in a strict typed PHP object.

Documentation

TODO.

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($integer); // 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, Github run the tests.

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 :-)