> $defs * @param array $raw */ public function __construct( public string $id, public array $defs, public array $raw, public ?string $description = NULL, public ?int $revision = NULL, ) { $nsidParser = new NsidParser(); if (!$nsidParser->isValid($id) || $nsidParser->normalize($id) !== $id) { throw new \InvalidArgumentException('Lexicon document id must be a normalized NSID.'); } if ($defs === []) { throw new \InvalidArgumentException('Lexicon document must contain at least one definition.'); } foreach ($defs as $name => $definition) { // Numeric JSON object keys become integer array keys in PHP. // @mago-expect analysis:redundant-cast $name = (string) $name; if ( $name === '' || \preg_match('//u', $name) !== 1 || !\is_string($definition['type'] ?? NULL) ) { throw new \InvalidArgumentException('Lexicon document definitions must have valid names and string types.'); } } } /** * Returns a named definition from the document. * * @return array|null */ public function def(string $name): ?array { return $this->defs[$name] ?? NULL; } }