Skip to content

Commit

Permalink
ACMS-1925: Update starterkit validation and cover all sections.
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeshreeputra committed Aug 14, 2023
1 parent 93393db commit 6edc5f9
Showing 1 changed file with 71 additions and 10 deletions.
81 changes: 71 additions & 10 deletions src/Validation/StarterKitValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,92 @@ public function __construct(
* Validates each key value for starter-kit.
*/
public function validateStarterKit(array &$starterkits): array {
foreach ($starterkits as $starterkit) {
foreach ($starterkits as $key => $starterkit) {
// Validate starterkit name.
if (empty($starterkit['name']) || !is_string($starterkit['name'])) {
$this->output->writeln(sprintf(
'<error>[error] Name field is mandatory and should be in string format.</error>'
'<error>[error] Name field is mandatory and should be in string format, in %s starterkit.</error>', $key
));
exit;
}

// Validate starterkit description.
if (empty($starterkit['description']) || !is_string($starterkit['description'])) {
$this->output->writeln(sprintf(
'<error>[error] Description field is mandatory and should be in string format.</error>'
'<error>[error] Description field is mandatory and should be in string format, in %s starterkit.</error>', $key
));
exit;
}
if (isset($starterkit['modules']) && (!is_array($starterkit['modules']['require']) || !is_array($starterkit['modules']['install']))) {

// Validate modules section.
if (array_key_exists('modules', $starterkit) && !isset($starterkit['modules'])) {
$this->output->writeln(sprintf(
'<error>[error] Modules field/section is not in array format, in %s starterkit.</error>', $key
));
exit;
}

// Validate modules require section.
if (isset($starterkit['modules']) &&
(array_key_exists('require', $starterkit['modules']) &&
(!isset($starterkit['modules']['require']) || !is_array($starterkit['modules']['require'])))) {
$this->output->writeln(sprintf(
'<error>[error] Modules require field/section is not in array format, in %s starterkit.</error>', $key
));
exit;
}

// Validate modules install section.
if (isset($starterkit['modules']) &&
(array_key_exists('install', $starterkit['modules']) &&
(!isset($starterkit['modules']['install']) || !is_array($starterkit['modules']['install'])))) {
$this->output->writeln(sprintf(
'<error>[error] Modules install field/section is not in array format, in %s starterkit.</error>', $key
));
exit;
}

// Validate themes section.
if (array_key_exists('themes', $starterkit) && !isset($starterkit['themes'])) {
$this->output->writeln(sprintf(
'<error>[error] Modules field is not in array format.</error>'
'<error>[error] Themes field/section is not in array format, in %s starterkit.</error>', $key
));
exit;
}
if (!is_array($starterkit['themes']['require']) ||
!is_array($starterkit['themes']['install']) ||
!is_string($starterkit['themes']['admin']) ||
!is_string($starterkit['themes']['default'])) {

// Validate themes require section.
if (isset($starterkit['themes']) &&
(array_key_exists('require', $starterkit['themes']) &&
(!isset($starterkit['themes']['require']) || !is_array($starterkit['themes']['require'])))) {
$this->output->writeln(sprintf(
'<error>[error] Themes require field/section is not in array format, in %s starterkit.</error>', $key
));
exit;
}

// Validate themes install section.
if (isset($starterkit['themes']) &&
(array_key_exists('install', $starterkit['themes']) &&
(!isset($starterkit['themes']['install']) || !is_array($starterkit['themes']['install'])))) {
$this->output->writeln(sprintf(
'<error>[error] Themes install field/section is not in array format, in %s starterkit.</error>', $key
));
exit;
}

// Validate themes admin section.
if (isset($starterkit['themes']) &&
(array_key_exists('admin', $starterkit['themes']) && !is_string($starterkit['themes']['admin']))) {
$this->output->writeln(sprintf(
'<error>[error] Themes admin field/section is not set or doesnt contain string value, in %s starterkit.</error>', $key
));
exit;
}

// Validate themes default section.
if (!is_string($starterkit['themes']['default'])) {
$this->output->writeln(sprintf(
'<error>[error] Themes field is not in array format or doesnt contain string format.</error>'
'<error>[error] Themes default field/section is not set or doesnt contain string value, in %s starterkit.</error>', $key
));
exit;
}
Expand Down

0 comments on commit 6edc5f9

Please sign in to comment.