Skip to content

Commit 1930521

Browse files
committed
add some helpful comments
1 parent ea4ae74 commit 1930521

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/Health.php

+22-2
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,18 @@ private static function retrieveSchemaForCategory(string $category, ?string $dat
364364
*/
365365
private function executeValidation(object $validation, ConnectionInterface $to)
366366
{
367+
// First thing is try to determine the schema that we will be validating against,
368+
// and the path to the source file or folder that we will be validating against the schema.
369+
// Our purpose here is to set the $pathForSchema and $dataPath variables.
370+
$pathForSchema = null;
371+
$dataPath = null;
372+
373+
// Source data checks validate data directly in the filesystem, not through the API
367374
if ($validation->category === 'sourceDataCheck') {
368-
$pathForSchema = $validation->validate;
375+
$pathForSchema = $validation->validate;
376+
// Are we validating a single source file, or are we validating a folder of i18n files?
369377
if (property_exists($validation, 'sourceFolder')) {
378+
// If the 'sourceFolder' property is set, then we are validating a folder of i18n files
370379
$dataPath = rtrim($validation->sourceFolder, '/');
371380
$matches = null;
372381
if (preg_match("/^(wider\-region|national\-calendar|diocesan\-calendar)\-([A-Z][_a-z]+)\-i18n$/", $validation->validate, $matches)) {
@@ -399,6 +408,8 @@ private function executeValidation(object $validation, ConnectionInterface $to)
399408
$dataPath = RomanMissal::$i18nPath["{$region}_{$year}"];
400409
}
401410
} else {
411+
// If we are not validating a folder of i18n files, then we are validating a single source file,
412+
// and the 'sourceFile' property is required in this case
402413
if (property_exists($validation, 'sourceFile')) {
403414
$dataPath = $validation->sourceFile;
404415
$matches = null;
@@ -436,13 +447,18 @@ private function executeValidation(object $validation, ConnectionInterface $to)
436447
}
437448
}
438449
} else {
450+
// If it's not a sourceDataCheck, it's probably a resourceDataCheck
451+
// That is to say, an API path
439452
$pathForSchema = $validation->sourceFile;
440453
$dataPath = $validation->sourceFile;
441454
}
442455

443456
$schema = Health::retrieveSchemaForCategory($validation->category, $pathForSchema);
444457

458+
// Now that we have the correct schema to validate against,
459+
// we will perform the actual validation either for all files in a folder, or for a single file
445460
if (property_exists($validation, 'sourceFolder')) {
461+
// If the 'sourceFolder' property is set, then we are validating a folder of i18n files
446462
$files = glob($dataPath . '/*.json');
447463
if (false === $files || empty($files)) {
448464
$message = new \stdClass();
@@ -525,6 +541,7 @@ private function executeValidation(object $validation, ConnectionInterface $to)
525541
$this->sendMessage($to, $message);
526542
}
527543
} else {
544+
// If the 'sourceFolder' property is not set, then we are validating a single source file or API path
528545
$matches = null;
529546
if (preg_match("/^diocesan-calendar-([a-z]{6}_[a-z]{2})$/", $pathForSchema, $matches)) {
530547
$dioceseId = $matches[1];
@@ -543,6 +560,8 @@ private function executeValidation(object $validation, ConnectionInterface $to)
543560
]);
544561
}
545562

563+
// If we are validating an API path, we check for a 200 OK HTTP response from the API
564+
// rather than checking for existence of the file in the filesystem
546565
if ($validation->category === 'resourceDataCheck') {
547566
$headers = get_headers($dataPath);
548567
if (!$headers || strpos($headers[0], '200') === false) {
@@ -563,11 +582,12 @@ private function executeValidation(object $validation, ConnectionInterface $to)
563582
$message->text = "Unable to verify schema for dataPath {$dataPath} and category {$validation->category} since Data file $dataPath does not exist or is not readable";
564583
$message->classes = ".$validation->validate.schema-valid";
565584
$this->sendMessage($to, $message);
566-
585+
// early exit
567586
return;
568587
}
569588
}
570589

590+
// $dataPath could be either a source file or an API path, file_get_contents can handle both
571591
$data = file_get_contents($dataPath);
572592
if (false === $data) {
573593
$message = new \stdClass();

0 commit comments

Comments
 (0)