$dependencies */ public function __construct( public readonly array $dependencies, public readonly string $version ) { } public static function from_description( mixed $description ): self { if ( ! is_array( $description ) ) { throw new UnexpectedValueException( 'The screen build description is not a list of fields.' ); } $version = $description['version'] ?? null; if ( ! is_string( $version ) ) { throw new UnexpectedValueException( 'The screen build description has no version.' ); } return new self( self::dependency_names( $description['dependencies'] ?? null ), $version ); } /** @return list */ private static function dependency_names( mixed $dependencies ): array { if ( ! is_array( $dependencies ) ) { throw new UnexpectedValueException( 'The screen build description has no dependency list.' ); } $names = array(); foreach ( $dependencies as $dependency ) { if ( ! is_string( $dependency ) || '' === $dependency ) { throw new UnexpectedValueException( 'The screen build description has a nameless dependency.' ); } $names[] = $dependency; } return $names; } }