Skip to content

Commit

Permalink
πŸ“ (Schedule.php): Add Webmozart Assert library for input validation
Browse files Browse the repository at this point in the history
πŸ”§ (Schedule.php): Add input validation for functionString and value['name'] in Schedule class
  • Loading branch information
marco76tv committed Sep 17, 2024
1 parent b2db9f3 commit 35e7a2b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Models/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Support\Collection;
use Modules\Job\Enums\Status;
use Modules\Xot\Contracts\ProfileContract;
use Webmozart\Assert\Assert;

/**
* Modules\Job\Models\Schedule.
Expand Down Expand Up @@ -47,6 +48,43 @@
* @property ProfileContract|null $creator
* @property ProfileContract|null $updater
*
* @method static Builder|Schedule active()
* @method static \Modules\Job\Database\Factories\ScheduleFactory factory($count = null, $state = [])
* @method static Builder|Schedule inactive()
* @method static Builder|Schedule newModelQuery()
* @method static Builder|Schedule newQuery()
* @method static Builder|Schedule onlyTrashed()
* @method static Builder|Schedule query()
* @method static Builder|Schedule whereCommand($value)
* @method static Builder|Schedule whereCommandCustom($value)
* @method static Builder|Schedule whereCreatedAt($value)
* @method static Builder|Schedule whereCreatedBy($value)
* @method static Builder|Schedule whereDeletedAt($value)
* @method static Builder|Schedule whereDeletedBy($value)
* @method static Builder|Schedule whereEmailOutput($value)
* @method static Builder|Schedule whereEnvironments($value)
* @method static Builder|Schedule whereEvenInMaintenanceMode($value)
* @method static Builder|Schedule whereExpression($value)
* @method static Builder|Schedule whereId($value)
* @method static Builder|Schedule whereLogError($value)
* @method static Builder|Schedule whereLogFilename($value)
* @method static Builder|Schedule whereLogSuccess($value)
* @method static Builder|Schedule whereOnOneServer($value)
* @method static Builder|Schedule whereOptions($value)
* @method static Builder|Schedule whereOptionsWithValue($value)
* @method static Builder|Schedule whereParams($value)
* @method static Builder|Schedule whereRunInBackground($value)
* @method static Builder|Schedule whereSendmailError($value)
* @method static Builder|Schedule whereSendmailSuccess($value)
* @method static Builder|Schedule whereStatus($value)
* @method static Builder|Schedule whereUpdatedAt($value)
* @method static Builder|Schedule whereUpdatedBy($value)
* @method static Builder|Schedule whereWebhookAfter($value)
* @method static Builder|Schedule whereWebhookBefore($value)
* @method static Builder|Schedule whereWithoutOverlapping($value)
* @method static Builder|Schedule withTrashed()
* @method static Builder|Schedule withoutTrashed()
*
* @mixin \Eloquent
*/
class Schedule extends BaseModel
Expand Down Expand Up @@ -169,6 +207,10 @@ private function evaluateFunction(string $functionString): mixed
$allowedFunctions = ['strtolower', 'strtoupper']; // Example allowed functions

if (in_array($functionString, $allowedFunctions)) {
if (! is_callable($functionString)) {
throw new \Exception('['.__LINE__.']['.__CLASS__.']');
}

return call_user_func($functionString);
}

Expand All @@ -189,6 +231,8 @@ public function getOptions(): array

return $options->map(function ($value, $key) {
if (is_array($value)) {
Assert::nullOrString($value['name']);

return '--'.((string) ($value['name'] ?? $key)).'='.((string) $value['value']);
}

Expand Down

0 comments on commit 35e7a2b

Please sign in to comment.