Clean up API code and fix test code.

This commit is contained in:
James Cole
2019-09-04 17:39:39 +02:00
parent f52584d46b
commit f9f1fa0fcb
60 changed files with 812 additions and 1191 deletions

View File

@@ -133,21 +133,6 @@ class RuleStoreRequest extends Request
);
}
/**
* Adds an error to the validator when there are no repetitions in the array of data.
*
* @param Validator $validator
*/
protected function atLeastOneTrigger(Validator $validator): void
{
$data = $validator->getData();
$triggers = $data['triggers'] ?? [];
// need at least one trigger
if (0 === count($triggers)) {
$validator->errors()->add('title', (string)trans('validation.at_least_one_trigger'));
}
}
/**
* Adds an error to the validator when there are no repetitions in the array of data.
*
@@ -164,24 +149,18 @@ class RuleStoreRequest extends Request
}
/**
* @return array
* Adds an error to the validator when there are no repetitions in the array of data.
*
* @param Validator $validator
*/
private function getRuleTriggers(): array
protected function atLeastOneTrigger(Validator $validator): void
{
$triggers = $this->get('triggers');
$return = [];
if (is_array($triggers)) {
foreach ($triggers as $trigger) {
$return[] = [
'type' => $trigger['type'],
'value' => $trigger['value'],
'active' => $this->convertBoolean((string)($trigger['active'] ?? 'false')),
'stop_processing' => $this->convertBoolean((string)($trigger['stop_processing'] ?? 'false')),
];
}
$data = $validator->getData();
$triggers = $data['triggers'] ?? [];
// need at least one trigger
if (0 === count($triggers)) {
$validator->errors()->add('title', (string)trans('validation.at_least_one_trigger'));
}
return $return;
}
/**
@@ -204,4 +183,25 @@ class RuleStoreRequest extends Request
return $return;
}
/**
* @return array
*/
private function getRuleTriggers(): array
{
$triggers = $this->get('triggers');
$return = [];
if (is_array($triggers)) {
foreach ($triggers as $trigger) {
$return[] = [
'type' => $trigger['type'],
'value' => $trigger['value'],
'active' => $this->convertBoolean((string)($trigger['active'] ?? 'false')),
'stop_processing' => $this->convertBoolean((string)($trigger['stop_processing'] ?? 'false')),
];
}
}
return $return;
}
}