Skip to content

Commit

Permalink
Add validation for extra.replace structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jissereitsma committed Oct 2, 2023
1 parent 0b93a7c commit bbcaffe
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Composer/Service/ReplaceBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,30 @@ public function getErrors(): array
}
}

return array_merge($errors, $this->getErrorsFromBasicStructure());
}

private function getErrorsFromBasicStructure(): array
{
$errors = [];

$jsonData = $this->readJsonData();
if (!isset($jsonData['extra'])) {
return ['No section "extra" yet'];
}

if (!isset($jsonData['extra']['replace'])) {
return ['No section "extra.replace" yet'];
}

$elements = array_keys($jsonData['extra']['replace']);
$allowedElements = ['bulk', 'include', 'exclude'];
foreach ($elements as $element) {
if (!in_array($element, $allowedElements)) {
$errors[] = 'Unknown element "'.$element.'" in section "extra.replace"';
}
}

return $errors;
}

Expand Down

0 comments on commit bbcaffe

Please sign in to comment.