From 3d92ffbaec0983f03527bad68b57fe020a96b733 Mon Sep 17 00:00:00 2001 From: Tom Wright Date: Wed, 18 Oct 2023 11:17:47 +0000 Subject: [PATCH] Refactored main interface methods Signed-off-by: Tom Wright --- CHANGELOG.md | 1 + README.md | 12 ++++++------ composer.json | 4 ++-- stubs/DecodeLabs/Lucid.php | 8 ++++---- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b75aaae..ded8b04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +* Refactored main interface methods * Refactored package file structure ## v0.3.9 (2023-09-26) diff --git a/README.md b/README.md index 694c57f..56233bd 100644 --- a/README.md +++ b/README.md @@ -32,19 +32,19 @@ Direct value sanitisation can be achieved quickly and painlessly: use DecodeLabs\Lucid; // This ensures the value is a string -$myString = Lucid::make('This is a string', 'string'); +$myString = Lucid::cast('string', 'This is a string'); // This is nullable -$notAString = Lucid::make(null, '?string'); +$notAString = Lucid::cast('?string', null); // These are constraints - throws an exception -$myString = Lucid::make('My very long piece of text', 'string', [ +$myString = Lucid::cast('string', 'My very long piece of text', [ 'maxLength' => 10, 'maxWords' => 4 ]); // Creates an instance of Carbon (DateTime) -$myDate = Lucid::make('tomorrow', 'date', [ +$myDate = Lucid::cast('date','tomorrow', [ 'min' => 'yesterday', 'max' => '+3 days' ]); @@ -53,7 +53,7 @@ $myDate = Lucid::make('tomorrow', 'date', [ If you need more fine grained control of the responses to constraints, use validate(): ```php -$result = Lucid::validate('potato', 'int', [ +$result = Lucid::validate('int', 'potato', [ 'min' => 4 ]); @@ -69,7 +69,7 @@ if(!$result->isValid()) { Or conversely if you just need a yes or no answer, use is(): ```php -if(!Lucid::is('not a number', 'float')) { +if(!Lucid::is('float', 'not a number')) { // do something } ``` diff --git a/composer.json b/composer.json index e2b8e32..d2c5c2f 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "decodelabs/coercion": "^0.2.2", "decodelabs/dictum": "^0.5", "decodelabs/exceptional": "^0.4", - "decodelabs/lucid-support": "^0.2.1", + "decodelabs/lucid-support": "^0.3", "decodelabs/veneer": "^0.10.10", "nesbot/carbon": "^2.25" @@ -39,7 +39,7 @@ }, "extra": { "branch-alias": { - "dev-develop": "0.3.x-dev" + "dev-develop": "0.4.x-dev" } } } diff --git a/stubs/DecodeLabs/Lucid.php b/stubs/DecodeLabs/Lucid.php index f8889f5..abb713e 100644 --- a/stubs/DecodeLabs/Lucid.php +++ b/stubs/DecodeLabs/Lucid.php @@ -24,13 +24,13 @@ class Lucid implements Proxy public static function newSanitizer(mixed $value): Ref0 { return static::$instance->newSanitizer(...func_get_args()); } - public static function make(mixed $value, string $type, Ref1|array|null $setup = NULL): mixed { - return static::$instance->make(...func_get_args()); + public static function cast(string $type, mixed $value, Ref1|array|null $setup = NULL): mixed { + return static::$instance->cast(...func_get_args()); } - public static function validate(mixed $value, string $type, Ref1|array|null $setup = NULL): Ref2 { + public static function validate(string $type, mixed $value, Ref1|array|null $setup = NULL): Ref2 { return static::$instance->validate(...func_get_args()); } - public static function is(mixed $value, string $type, Ref1|array|null $setup = NULL): bool { + public static function is(string $type, mixed $value, Ref1|array|null $setup = NULL): bool { return static::$instance->is(...func_get_args()); } public static function sanitize(mixed $value): Ref0 {