Skip to content

Commit

Permalink
check $schema for null value
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRDOrazio committed Nov 19, 2024
1 parent 50e6225 commit 3204c83
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/Health.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,6 @@ private function executeValidation(object $validation, ConnectionInterface $to)
{
$dataPath = $validation->sourceFile;
$schema = Health::retrieveSchemaForCategory($validation->category, $dataPath);
if (null === $schema) {
$message = new \stdClass();
$message->type = "error";
$message->text = "Unable to detect schema for dataPath {$dataPath} and category {$validation->category}";
$message->classes = ".$validation->validate.schema-valid";
$this->sendMessage($to, $message);
}
$data = file_get_contents($dataPath);
if ($data !== false) {
$message = new \stdClass();
Expand All @@ -319,16 +312,24 @@ private function executeValidation(object $validation, ConnectionInterface $to)
$message->classes = ".$validation->validate.json-valid";
$this->sendMessage($to, $message);

$validationResult = $this->validateDataAgainstSchema($jsonData, $schema);
if (gettype($validationResult) === 'boolean' && $validationResult === true) {
if (null !== $schema) {
$validationResult = $this->validateDataAgainstSchema($jsonData, $schema);
if (gettype($validationResult) === 'boolean' && $validationResult === true) {
$message = new \stdClass();
$message->type = "success";
$message->text = "The Data file $dataPath was successfully validated against the Schema $schema";
$message->classes = ".$validation->validate.schema-valid";
$this->sendMessage($to, $message);
} elseif (gettype($validationResult === 'object')) {
$validationResult->classes = ".$validation->validate.schema-valid";
$this->sendMessage($to, $validationResult);
}
} else {
$message = new \stdClass();
$message->type = "success";
$message->text = "The Data file $dataPath was successfully validated against the Schema $schema";
$message->type = "error";
$message->text = "Unable to detect schema for dataPath {$dataPath} and category {$validation->category}";
$message->classes = ".$validation->validate.schema-valid";
$this->sendMessage($to, $message);
} elseif (gettype($validationResult === 'object')) {
$validationResult->classes = ".$validation->validate.schema-valid";
$this->sendMessage($to, $validationResult);
}
} else {
$message = new \stdClass();
Expand Down

0 comments on commit 3204c83

Please sign in to comment.