Skip to content

Commit

Permalink
Merge branch 'release/v0.2.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
betterthanclay committed Sep 8, 2022
2 parents 49be764 + af7671e commit 0cb441f
Show file tree
Hide file tree
Showing 42 changed files with 257 additions and 721 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
dependency-versions: "highest"

- name: "Check source code for syntax errors"
run: "composer exec -- parallel-lint src/ ecs.php"
run: "composer exec -- parallel-lint src/ stubs/ ecs.php"
# @TODO Check template files for syntax errors

unit_tests:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v0.1.0 (2022-09-08)
* Moved Sanitizer Provider interfaces to lucid-support
* Removed force* methods
* Added Processor level validation hook
* Added Email & URL Processors

## v0.1.0 (2022-09-07)
* Built initial Sanitizer structure
* Added core Processor and Constraint types
16 changes: 9 additions & 7 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.4",
"decodelabs/exceptional": "^0.4",
"decodelabs/tightrope": "^0.1.1",
"decodelabs/lucid-support": "^0.1.1",
"decodelabs/veneer": "^0.9.2",

"nesbot/carbon": "^2.25"
Expand All @@ -27,7 +27,9 @@
"php-parallel-lint/php-parallel-lint": "^1.3",
"symplify/easy-coding-standard": "^11",

"decodelabs/phpstan-decodelabs": "^0.6"
"decodelabs/phpstan-decodelabs": "^0.6",
"decodelabs/atlas": "^0.10.1",
"decodelabs/terminus": "^0.8.3"
},
"suggest": {},
"autoload": {
Expand All @@ -41,7 +43,7 @@
},
"extra": {
"branch-alias": {
"dev-develop": "0.1.x-dev"
"dev-develop": "0.2.x-dev"
}
},
"config": {
Expand All @@ -53,10 +55,10 @@
"analyze": "phpstan analyze --no-progress",
"ecs": "ecs check --no-progress-bar",
"ecs-fix": "ecs check --no-progress-bar --fix",
"lint": "parallel-lint src/ tests/ ecs.php",
"eclint": "eclint check src/ tests/ ecs.php",
"eclint-fix": "eclint fix src/ tests/ ecs.php",
"non-ascii": "! LC_ALL=C.UTF-8 find src/ -type f -name \"*.php\" -print0 | xargs -0 -- grep -PHn \"[^ -~]\" | grep -v '// @ignore-non-ascii$'",
"lint": "parallel-lint src/ stubs/ ecs.php",
"eclint": "eclint check src/ stubs/ ecs.php",
"eclint-fix": "eclint fix src/ stubs/ ecs.php",
"non-ascii": "! LC_ALL=C.UTF-8 find src/ stubs/ -type f -name \"*.php\" -print0 | xargs -0 -- grep -PHn \"[^ -~]\" | grep -v '// @ignore-non-ascii$'",
"check": [
"@composer update",
"@analyze",
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
parameters:
paths:
- src/
- tests/
level: max
7 changes: 1 addition & 6 deletions src/Lucid/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function __construct(Processor $processor);
*/
public static function getProcessorOutputTypes(): ?array;

public function getName(): string;
public function getWeight(): int;

/**
Expand Down Expand Up @@ -54,10 +55,4 @@ public function alterValue(mixed $value): mixed;
* @phpstan-return Generator<int, Error|null, mixed, bool>
*/
public function validate(mixed $value): Generator;

/**
* @phpstan-param TValue $value
* @phpstan-return TValue
*/
public function constrain(mixed $value): mixed;
}
9 changes: 0 additions & 9 deletions src/Lucid/Constraint/DateTime/Max.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,4 @@ public function validate(mixed $value): Generator

return true;
}

public function constrain(mixed $value): mixed
{
if ($value->greaterThan($this->max)) {
$value = new Carbon('now');
}

return $value;
}
}
9 changes: 0 additions & 9 deletions src/Lucid/Constraint/DateTime/Min.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,4 @@ public function validate(mixed $value): Generator

return true;
}

public function constrain(mixed $value): mixed
{
if ($value->lessThan($this->min)) {
$value = new Carbon('now');
}

return $value;
}
}
9 changes: 0 additions & 9 deletions src/Lucid/Constraint/Interval/Max.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,4 @@ public function validate(mixed $value): Generator

return true;
}

public function constrain(mixed $value): mixed
{
if ($value->greaterThan($this->max)) {
$value = new CarbonInterval();
}

return $value;
}
}
9 changes: 0 additions & 9 deletions src/Lucid/Constraint/Interval/Min.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,4 @@ public function validate(mixed $value): Generator

return true;
}

public function constrain(mixed $value): mixed
{
if ($value->lessThan($this->min)) {
$value = new CarbonInterval();
}

return $value;
}
}
12 changes: 0 additions & 12 deletions src/Lucid/Constraint/Number/Max.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,4 @@ public function validate(mixed $value): Generator

return true;
}

public function constrain(mixed $value): mixed
{
if (
$this->max !== null &&
$value > $this->max
) {
$value = $this->max;
}

return $value;
}
}
12 changes: 0 additions & 12 deletions src/Lucid/Constraint/Number/Min.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,4 @@ public function validate(mixed $value): Generator

return true;
}

public function constrain(mixed $value): mixed
{
if (
$this->min !== null &&
$value < $this->min
) {
$value = $this->min;
}

return $value;
}
}
40 changes: 40 additions & 0 deletions src/Lucid/Constraint/Processor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* @package Lucid
* @license http://opensource.org/licenses/MIT
*/

declare(strict_types=1);

namespace DecodeLabs\Lucid\Constraint;

use DecodeLabs\Lucid\Constraint;
use DecodeLabs\Lucid\ConstraintTrait;

/**
* This constraint is used to wrap the main Processor
* to be passed to Error objects
*
* @template TValue
* @implements Constraint<TValue, TValue>
*/
class Processor implements Constraint
{
/**
* @phpstan-use ConstraintTrait<TValue, TValue>
*/
use ConstraintTrait;

public const OUTPUT_TYPES = [];

public function getName(): string
{
return $this->processor->getName();
}

public function getWeight(): int
{
return 1;
}
}
9 changes: 0 additions & 9 deletions src/Lucid/Constraint/String/Emojis.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,4 @@ public function validate(mixed $value): Generator

return true;
}

public function constrain(mixed $value): mixed
{
if (!$this->emojis) {
$value = preg_replace(self::REGEX, '', $value) ?? $value;
}

return $value;
}
}
11 changes: 0 additions & 11 deletions src/Lucid/Constraint/String/MaxLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,4 @@ public function validate(mixed $value): Generator

return true;
}

public function constrain(mixed $value): mixed
{
$length = mb_strlen($value);

if ($length > $this->length) {
$value = substr($value, 0, $this->length);
}

return $value;
}
}
13 changes: 0 additions & 13 deletions src/Lucid/Constraint/String/MaxWords.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,4 @@ public function validate(mixed $value): Generator

return true;
}

public function constrain(mixed $value): mixed
{
$words = Dictum::countWords($value);

if ($words > $this->words) {
$parts = explode(' ', $value);
$parts = array_slice($parts, 0, $this->words);
$value = implode(' ', $parts);
}

return $value;
}
}
5 changes: 0 additions & 5 deletions src/Lucid/Constraint/String/MinLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,4 @@ public function validate(mixed $value): Generator

return true;
}

public function constrain(mixed $value): mixed
{
return str_pad($value, (int)$this->length, ' ');
}
}
16 changes: 0 additions & 16 deletions src/Lucid/Constraint/String/Pattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,4 @@ public function validate(mixed $value): Generator

return true;
}

public function constrain(mixed $value): mixed
{
if (
$this->pattern !== null &&
!filter_var(
$value,
\FILTER_VALIDATE_REGEXP,
['options' => ['regexp' => $this->pattern]]
)
) {
$value = '';
}

return $value;
}
}
16 changes: 7 additions & 9 deletions src/Lucid/ConstraintTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace DecodeLabs\Lucid;

use Generator;
use ReflectionClass;

/**
* @template TParam
Expand Down Expand Up @@ -44,6 +45,12 @@ public static function getProcessorOutputTypes(): ?array
return null;
}

public function getName(): string
{
return (new ReflectionClass($this))
->getShortName();
}

public function getWeight(): int
{
return 10;
Expand Down Expand Up @@ -86,13 +93,4 @@ public function validate(mixed $value): Generator
yield null;
return true;
}

/**
* @phpstan-param TValue $value
* @phpstan-return TValue
*/
public function constrain(mixed $value): mixed
{
return $value;
}
}
Loading

0 comments on commit 0cb441f

Please sign in to comment.