refactor(meta): own the platforms.*.meta parent rule in PostPlatformMetaRules

The shared rules() returned only meta sub-keys, so every caller still repeated
its own 'platforms.*.meta' => array parent (with slightly different sometimes/
nullable combos). Fold the parent into rules() with a single safe contract so
callers just spread one source for the whole meta block.
This commit is contained in:
Paulo Castellano 2026-06-16 17:50:40 -03:00
parent 3aa4b2a2f0
commit ba20534a6d
6 changed files with 4 additions and 7 deletions

View file

@ -50,7 +50,6 @@ public function rules(): array
Rule::in(array_column(ContentType::cases(), 'value')),
new ContentTypeMatchesPlatform,
],
'platforms.*.meta' => ['sometimes', 'nullable', 'array'],
...PostPlatformMetaRules::rules(),
'scheduled_at' => ['nullable', 'date', 'after:now'],
'label_ids' => ['sometimes', 'array'],

View file

@ -52,7 +52,6 @@ public function rules(): array
Rule::in(array_column(ContentType::cases(), 'value')),
new ContentTypeMatchesPostPlatform,
],
'platforms.*.meta' => ['nullable', 'array'],
...PostPlatformMetaRules::rules(),
'scheduled_at' => [
'nullable',

View file

@ -70,7 +70,6 @@ public function rules(): array
Rule::in(array_column(ContentType::cases(), 'value')),
Rule::when($enforcesMediaCompatibility, [new ContentTypeCompatibleWithMedia]),
],
'platforms.*.meta' => ['nullable', 'array'],
...PostPlatformMetaRules::rules(),
'label_ids' => ['sometimes', 'array'],
'label_ids.*' => ['uuid', Rule::exists('workspace_labels', 'id')->where('workspace_id', $this->user()->currentWorkspace->id)],

View file

@ -38,7 +38,6 @@ public function handle(Request $request): ResponseFactory
->where('is_active', true),
],
'platforms.*.content_type' => ['required', 'string', Rule::in(array_column(ContentType::cases(), 'value')), new ContentTypeMatchesPlatform],
'platforms.*.meta' => ['sometimes', 'array'],
...PostPlatformMetaRules::rules(),
]);

View file

@ -49,7 +49,6 @@ public function handle(Request $request): Response|ResponseFactory
Rule::exists('post_platforms', 'id')->where('post_id', $post->id),
],
'platforms.*.content_type' => ['sometimes', 'string', Rule::in(array_column(ContentType::cases(), 'value')), new ContentTypeMatchesPostPlatform],
'platforms.*.meta' => ['sometimes', 'array'],
...PostPlatformMetaRules::rules(),
]);

View file

@ -32,14 +32,16 @@ class PostPlatformMetaRules
];
/**
* Validation rules for the `platforms.*.meta.*` keys. The caller keeps its own
* `platforms.*.meta` (array) parent rule; these are the per-platform sub-keys.
* Validation rules for `platforms.*.meta` and all its per-platform sub-keys.
* Spread into a FormRequest/MCP tool rule set as the complete meta contract.
*
* @return array<string, mixed>
*/
public static function rules(): array
{
return [
'platforms.*.meta' => ['sometimes', 'nullable', 'array'],
// Instagram / Facebook
'platforms.*.meta.aspect_ratio' => ['sometimes', 'nullable', 'string', Rule::enum(AspectRatio::class)],