width < 1 || $this->height < 1) { throw new InvalidArgumentException('Preview variant dimensions must be positive'); } if ($this->quality < 1 || $this->quality > 100) { throw new InvalidArgumentException('Preview variant quality must be between 1 and 100'); } $this->format = MimeType::normalize($format); } public static function fromArray(array $data, ?self $defaults = null): self { $width = $data['width'] ?? $defaults?->width; $height = $data['height'] ?? $defaults?->height; $format = $data['format'] ?? $defaults?->format; $quality = $data['quality'] ?? $defaults?->quality; if (!is_int($width) || !is_int($height) || !is_string($format) || !is_int($quality)) { throw new InvalidArgumentException('Preview variants require integer dimensions and quality plus a MIME format'); } return new self($width, $height, $format, $quality); } /** @return array{width:int,height:int,format:string,quality:int} */ public function toArray(): array { return [ 'width' => $this->width, 'height' => $this->height, 'format' => $this->format, 'quality' => $this->quality, ]; } }