Skip to content

Commit

Permalink
Refactored main interface methods
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Wright <[email protected]>
  • Loading branch information
betterthanclay committed Oct 18, 2023
1 parent a6f6e5d commit 3d92ffb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Refactored main interface methods
* Refactored package file structure

## v0.3.9 (2023-09-26)
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]);
Expand All @@ -53,7 +53,7 @@ $myDate = Lucid::make('tomorrow', 'date', [
If you need more fine grained control of the responses to constraints, use <code>validate()</code>:

```php
$result = Lucid::validate('potato', 'int', [
$result = Lucid::validate('int', 'potato', [
'min' => 4
]);

Expand All @@ -69,7 +69,7 @@ if(!$result->isValid()) {
Or conversely if you just need a yes or no answer, use <code>is()</code>:

```php
if(!Lucid::is('not a number', 'float')) {
if(!Lucid::is('float', 'not a number')) {
// do something
}
```
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -39,7 +39,7 @@
},
"extra": {
"branch-alias": {
"dev-develop": "0.3.x-dev"
"dev-develop": "0.4.x-dev"
}
}
}
8 changes: 4 additions & 4 deletions stubs/DecodeLabs/Lucid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3d92ffb

Please sign in to comment.