mirror of
https://codeberg.org/reflect/reflect-rules-plugin.git
synced 2025-09-13 16:33:42 +02:00
fix: pass scope for all eval methods (#4)
This commit is contained in:
parent
7fc27ff89c
commit
6583f87866
2 changed files with 10 additions and 10 deletions
|
@ -141,22 +141,22 @@
|
|||
};
|
||||
}
|
||||
|
||||
public function eval_min(mixed $value): bool {
|
||||
public function eval_min(mixed $value, Scope $scope): bool {
|
||||
return match($this->type) {
|
||||
Type::NUMBER => $this->eval_type($value) && $value >= $this->min,
|
||||
Type::STRING => $this->eval_type($value) && strlen($value) >= $this->min,
|
||||
Type::NUMBER => $this->eval_type($value, $scope) && $value >= $this->min,
|
||||
Type::STRING => $this->eval_type($value, $scope) && strlen($value) >= $this->min,
|
||||
Type::ARRAY,
|
||||
Type::OBJECT => $this->eval_type($value) && count($value) >= $this->min,
|
||||
Type::OBJECT => $this->eval_type($value, $scope) && count($value) >= $this->min,
|
||||
default => true
|
||||
};
|
||||
}
|
||||
|
||||
public function eval_max(mixed $value): bool {
|
||||
public function eval_max(mixed $value, Scope $scope): bool {
|
||||
return match($this->type) {
|
||||
Type::NUMBER => $this->eval_type($value) && $value <= $this->max,
|
||||
Type::STRING => $this->eval_type($value) && strlen($value) <= $this->max,
|
||||
Type::NUMBER => $this->eval_type($value, $scope) && $value <= $this->max,
|
||||
Type::STRING => $this->eval_type($value, $scope) && strlen($value) <= $this->max,
|
||||
Type::ARRAY,
|
||||
Type::OBJECT => $this->eval_type($value) && count($value) <= $this->max,
|
||||
Type::OBJECT => $this->eval_type($value, $scope) && count($value) <= $this->max,
|
||||
default => true
|
||||
};
|
||||
}
|
||||
|
|
|
@ -84,11 +84,11 @@
|
|||
$this->add_error($name, "Value must be of type '{$rules->type->name}'");
|
||||
}
|
||||
|
||||
if ($rules->min && !$rules->eval_min($value)) {
|
||||
if ($rules->min && !$rules->eval_min($value, $scope)) {
|
||||
$this->add_error($name, "Value must be larger or equal to {$rules->min}");
|
||||
}
|
||||
|
||||
if ($rules->max && !$rules->eval_max($value)) {
|
||||
if ($rules->max && !$rules->eval_max($value, $scope)) {
|
||||
$this->add_error($name, "Value must be smaller or equal to {$rules->max}");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue