diff --git a/src/schema/_scalar/ScalarResult.php b/src/schema/_scalar/ScalarResult.php index 6e50a29..44f07b9 100644 --- a/src/schema/_scalar/ScalarResult.php +++ b/src/schema/_scalar/ScalarResult.php @@ -51,7 +51,12 @@ class ScalarResult extends Result { $this->result[$name] = $value; } - function setMissing(ScalarSchema $schema, ?string $key=null): int { + protected static function replace_key(string &$message, ?string $key): void { + if ($key) $message = str_replace("{key}", $key, $message); + else $message = str_replace("{key}: ", "", $message); + } + + function setMissing(ScalarSchema $schema): int { $this->missing = true; if (!$schema->required) { $this->null = true; @@ -60,13 +65,13 @@ class ScalarResult extends Result { return ref_analyze::NORMALIZED; } else { $message = cl::get($schema->messages, "missing"); - $message = str_replace("{key}", $key, $message); + self::replace_key($message, $schema->name); $this->message = $message; return ref_analyze::MISSING; } } - function setNull(ScalarSchema $schema, ?string $key=null): int { + function setNull(ScalarSchema $schema): int { $this->missing = true; if ($schema->nullable) { $this->valid = true; @@ -74,7 +79,7 @@ class ScalarResult extends Result { return ref_analyze::NORMALIZED; } else { $message = cl::get($schema->messages, "null"); - $message = str_replace("{key}", $key, $message); + self::replace_key($message, $schema->name); $this->message = $message; return ref_analyze::NULL; } diff --git a/src/schema/_scalar/ScalarValue.php b/src/schema/_scalar/ScalarValue.php index b69b64e..c35d746 100644 --- a/src/schema/_scalar/ScalarValue.php +++ b/src/schema/_scalar/ScalarValue.php @@ -60,10 +60,10 @@ class ScalarValue extends Value { $destKey = $this->destKey; $result = $this->result; $result->reset(); - if (!$input->available()) return $result->setMissing($schema, $destKey); - $value = $input->get($destKey); - if ($value === null) return $result->setNull($schema, $destKey); #XXX résoudre le type + if (!$input->available()) return $result->setMissing($schema); + $value = $input->get($destKey); + if ($value === null) return $result->setNull($schema); } function exists(): bool {