Repository: laravel/framework
File: src/Illuminate/Database/Eloquent/Casts/AsBinary.php (PHP)

Code before:
<?php

namespace Illuminate\Database\Eloquent\Casts;

use Illuminate\Contracts\Database\Eloquent\Castable;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Support\BinaryCodec;
use InvalidArgumentException;
use RuntimeException;

class AsBinary implements Castable
{
    /**
     * Get the caster class to use when casting from / to this cast target.
     * @param array $arguments
     * @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<string|null, string|null>
     */
    public static function castUsing(array $arguments)
    {
        return new class($arguments) implements CastsAttributes {
            private string $format;

            private bool $isRequired;

            public function __construct(protected array $arguments)
            {
                [$format, $required] = array_pad(array_values($this->arguments), 2, null);
                $this->format = $format ?: throw new InvalidArgumentException('The binary codec format is required.');
                $this->isRequired = str($required ?? false)->toBoolean();
                $allowedFormats = array_keys(BinaryCodec::all());

                if (! in_array($this->format, $allowedFormats, true)) {
                    throw new InvalidArgumentException(sprintf(
                        'Unsupported binary codec format [%s]. Allowed formats are: %s.',
                        $this->format,
                        implode(', ', $allowedFormats),
                    ));
                }
            }


Review comment (suggestion):
You could narrow this further down:
```suggestion
     * @param array{string, '0'|'1'} $arguments
```
or
```suggestion
     * @param array{0: string, 1: '0'|'1'} $arguments
```

Code after:
<?php

namespace Illuminate\Database\Eloquent\Casts;

use Illuminate\Contracts\Database\Eloquent\Castable;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Support\BinaryCodec;
use InvalidArgumentException;

class AsBinary implements Castable
{
    /**
     * Get the caster class to use when casting from / to this cast target.
     *
     * @param  array{string}  $arguments
     * @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes
     */
    public static function castUsing(array $arguments)
    {
        return new class($arguments) implements CastsAttributes
        {
            protected string $format;

            public function __construct(protected array $arguments)
            {
                $this->format = $this->arguments[0]
                    ?? throw new InvalidArgumentException('The binary codec format is required.');

                if (! in_array($this->format, BinaryCodec::formats(), true)) {
                    throw new InvalidArgumentException(sprintf(
                        'Unsupported binary codec format [%s]. Allowed formats are: %s.',
                        $this->format,
                        implode(', ', BinaryCodec::formats()),
                    ));
                }
            }

            public function get($model, $key, $value, $attributes)
            {
                return BinaryCodec::decode($attributes[$key] ?? null, $this->format);