data = $data ?? (object) []; } /** * Create an instance. * * @param stdClass|array|null $data Raw data. * @return self */ public static function create($data = null): self { if ($data !== null && !is_object($data) && !is_array($data)) { throw new TypeError(); } if (is_array($data)) { $data = (object) $data; } return new self($data); } public function getRaw(): stdClass { return ObjectUtil::clone($this->data); } /** * @return mixed */ public function get(string $name) { return $this->getRaw()->$name ?? null; } public function has(string $name): bool { return property_exists($this->data, $name); } public function getTargetId(): ?string { return $this->targetId; } public function getTargetType(): ?string { return $this->targetType; } public function withTargetId(?string $targetId): self { $obj = clone $this; $obj->targetId = $targetId; return $obj; } public function withTargetType(?string $targetType): self { $obj = clone $this; $obj->targetType = $targetType; return $obj; } }