trypost/app/Enums/PostPlatform/AspectRatio.php
Paulo Castellano efe49c34de Make AspectRatio the single source for crop math; fill test gaps
Review follow-ups:
- AspectRatio::toFloat() now owns the crop ratio math; CropsImageForAspectRatio
  delegates to it so the enum is the single source of truth for both validation
  and cropping (no more parallel literal map).
- API update controller now reloads postPlatforms before returning, so the
  update response reflects the persisted platform meta/content_type (was stale).
- Tests: AspectRatio enum unit test; API valid-update read-back + 'original'
  on create; MCP response read-back + valid update.
2026-06-10 15:52:41 -03:00

27 lines
661 B
PHP

<?php
declare(strict_types=1);
namespace App\Enums\PostPlatform;
enum AspectRatio: string
{
case Square = '1:1';
case Portrait = '4:5';
case Landscape = '16:9';
case Original = 'original';
/**
* Width-to-height ratio used to center-crop an image. `Original` means "no
* crop", so it resolves to a square (1.0) only as a safe fallback — callers
* should bypass cropping entirely for `Original`.
*/
public function toFloat(): float
{
return match ($this) {
self::Portrait => 4 / 5,
self::Landscape => 16 / 9,
self::Square, self::Original => 1.0,
};
}
}