representations[$rep->getName()])) { return false; } if (null === $pos) { $this->representations[$rep->getName()] = $rep; } else { $this->representations = \array_merge( \array_slice($this->representations, 0, $pos), [$rep->getName() => $rep], \array_slice($this->representations, $pos) ); } return true; } public function replaceRepresentation(Representation $rep, int $pos = null): void { if (null === $pos) { $this->representations[$rep->getName()] = $rep; } else { $this->removeRepresentation($rep); $this->addRepresentation($rep, $pos); } } /** * @param Representation|string $rep */ public function removeRepresentation($rep): void { if ($rep instanceof Representation) { unset($this->representations[$rep->getName()]); } else { // String unset($this->representations[$rep]); } } public function getRepresentation(string $name): ?Representation { return $this->representations[$name] ?? null; } public function getRepresentations(): array { return $this->representations; } public function clearRepresentations(): void { $this->representations = []; } public function getType(): ?string { return $this->type; } public function getModifiers(): ?string { $out = $this->getAccess(); if ($this->readonly) { $out .= ' readonly'; } if ($this->const) { $out .= ' const'; } if ($this->static) { $out .= ' static'; } if (null !== $out && \strlen($out)) { return \ltrim($out); } return null; } public function getAccess(): ?string { switch ($this->access) { case self::ACCESS_PRIVATE: return 'private'; case self::ACCESS_PROTECTED: return 'protected'; case self::ACCESS_PUBLIC: return 'public'; } return null; } public function getName(): ?string { if (isset($this->name)) { return (string) $this->name; } return null; } public function getOperator(): ?string { switch ($this->operator) { case self::OPERATOR_ARRAY: return '=>'; case self::OPERATOR_OBJECT: return '->'; case self::OPERATOR_STATIC: return '::'; } return null; } public function getSize(): ?string { if (isset($this->size)) { return (string) $this->size; } return null; } public function getValueShort(): ?string { if ($rep = $this->value) { if ('boolean' === $this->type) { return $rep->contents ? 'true' : 'false'; } if ('integer' === $this->type || 'double' === $this->type) { return (string) $rep->contents; } } return null; } public function getAccessPath(): ?string { return $this->access_path; } public function transplant(self $old): void { $this->name = $old->name; $this->size = $old->size; $this->access_path = $old->access_path; $this->access = $old->access; $this->readonly = $old->readonly; $this->static = $old->static; $this->const = $old->const; $this->type = $old->type; $this->depth = $old->depth; $this->owner_class = $old->owner_class; $this->operator = $old->operator; $this->reference = $old->reference; $this->value = $old->value; $this->representations += $old->representations; $this->hints = \array_merge($this->hints, $old->hints); } /** * Creates a new basic object with a name and access path. */ public static function blank(string $name = null, string $access_path = null): self { $o = new self(); $o->name = $name; $o->access_path = $access_path; return $o; } public static function sortByAccess(self $a, self $b): int { static $sorts = [ self::ACCESS_PUBLIC => 1, self::ACCESS_PROTECTED => 2, self::ACCESS_PRIVATE => 3, self::ACCESS_NONE => 4, ]; return $sorts[$a->access] - $sorts[$b->access]; } public static function sortByName(self $a, self $b): int { if ((string) $a->name === (string) $b->name) { return (int) \is_int($b->name) - (int) \is_int($a->name); } return \strnatcasecmp((string) $a->name, (string) $b->name); } }