<?php
namespace nur\data\types;

class md_utils {
  static function ensure_md(?Metadata &$md, array $schema, ?array $params=null): Metadata {
    if ($md === null) $md = new Metadata($schema, $params);
    return $md;
  }

  static function ensure_md_func(?Metadata &$md, callable $get_md): Metadata {
    if ($md === null) $md = $get_md();
    return $md;
  }

  static function ensure_schema(&$item, ?Metadata &$md, array $schema, ?array $params=null): void {
    self::ensure_md($md, $schema, $params)->ensureSchema($item);
  }
}
