From 3e72b013e03e50ba6230e843a493210a593900ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Willi=20E=C3=9Fer?= Date: Mon, 23 Oct 2017 12:57:35 +0200 Subject: [PATCH 1/3] (docs) added init docs --- README.md | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2bb1b61..1c3e4fe 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,81 @@ # predict -## currently in development \ No newline at end of file +> Fluent interface, small and simple predictions + +## Install + +```bash +$ compose require try/predict +``` + +## Usage + +```php +predict([1, 2, 3])->isArray()->withKey(1); +} catch(PredictionFailException $ex) { + // catch if the prediction failes +} +``` + +## API + +### Trait + +#### `TryPhp\PredictionTrait` + +##### Methods + +| Method | Arguments | Description | +|---|---|---| +| predict($value) | * `$value` (**string**)(required) | Entrypoint to setup predictions based on the given `$value`, will return a fluid interface for prediction setups (See `Prediction Entrypoint`). See `Prediction Classes` for more information about the several prediction chaining possibilities. | + + +### Prediction Entrypoint + +#### `TryPhp\Predictions` + +Class wich will be returned by `TryPhp\PredictionTrait::predict($value)`. Provides setup functions for prediction chains. + +##### Methods + +| Method | Arguments | Description | +|---|---|---| +| isTrue() | **none** | Will add a failed prediction if the set value is not true. | +| isFalse() | **none** | Will add a failed prediction if the set value is true. | +| isArray() | **none** | Will return a fluid interface to `TryPhp\Predictions\ArrayPrediction` and add a failed prediction if value is no array. | + +### Prediction Classes + +#### `TryPhp\Predictions\ArrayPrediction` + +Prediction class for array predictions and comparisons. + +##### Methods + +| Method | Arguments | Description | +|---|---|---| +| withKey($key) | * `$key` (**mixed**)(required) | Will add a failed prediction if set value does not contain provided key. | +| withKeys($keys) | * `$keys` (**array**)(required) | Will add a failed prediction if set value does not contain provided keys. | +| withoutKey($key) | * `$key` (**mixed**)(required) | Inverted case of `withKey`. | +| withoutKeys($keys) | * `$keys` (**array**)(required) | Inverted case of `withKeys`. | +| countIs($expected) | * `$expected` (**int**)(required) | Will add a prediction fail if the length of the set value doesmatch the expected one. | +| countIsHigherThan($expected) | * `$expected` (**int**)(required) | Will add a prediction fail if the length of the set value is lower than the expected value. | +| countIsLowerThan($expected) | * `$expected` (**int**)(required) | Will add a prediction fail if the length of the set value is higher than the expected value. | +| hasItem($expected, $strict = false) | * `$expected` (**mixed**)(required) * `$strict` (**bool**) | Will add a prediction fail if the set values does not contain expected item. | +| hasItems($expected) | * `$expected` (**array**)(required) | Will add a prediction fail if the set values does not contain expected items. | +| hasSubset($supset) | * `$supset` (**array**)(required) | Will add a prediction fail if the set values does not contain expected subset. | + +## License + +GPL-2.0 © Felix Buchheim \ No newline at end of file From 7e7acfdaefb309675a8168d3124c6672b096232b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Willi=20E=C3=9Fer?= Date: Mon, 23 Oct 2017 12:57:50 +0200 Subject: [PATCH 2/3] (pkg) change package description --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index eda2a92..1b822d2 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "try/predict", - "description": "Fluent, small and simple predictions", + "description": "Fluent interface, small and simple predictions", "type": "library", "license": "GPL-2.0", "authors": [ From a4e5c82bf8c8b9d5a108fe93714c4ba0a042af76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Willi=20E=C3=9Fer?= Date: Mon, 23 Oct 2017 12:58:11 +0200 Subject: [PATCH 3/3] (API)(lib) fixed typos --- src/Predictions/ArrayPrediction.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Predictions/ArrayPrediction.php b/src/Predictions/ArrayPrediction.php index 84c67ca..65df100 100644 --- a/src/Predictions/ArrayPrediction.php +++ b/src/Predictions/ArrayPrediction.php @@ -135,7 +135,7 @@ public function countIs(int $expectedCount) * * @return $this */ - public function countIsHigherThen(int $expected) + public function countIsHigherThan(int $expected) { $count = count($this->value); if (count($this->value) <= $expected) { @@ -152,7 +152,7 @@ public function countIsHigherThen(int $expected) * * @return $this */ - public function countIsSmallerThen(int $expected) + public function countIsLowerThan(int $expected) { $count = count($this->value); if (count($this->value) >= $expected) {