From a89d5a73fbd07f6ee40d841d9ed075c3cb1769f3 Mon Sep 17 00:00:00 2001 From: alsbury Date: Tue, 15 Nov 2022 16:44:32 -0600 Subject: [PATCH] Cleanup and fixing type bug --- src/Model/RpcStatus.php | 10 +++++----- src/Model/SubjectFilter.php | 15 ++++++++++++--- src/Model/SubjectFilterRelationFilter.php | 13 ++++++++++--- src/Model/SubjectReference.php | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/Model/RpcStatus.php b/src/Model/RpcStatus.php index 019d86a..20b7baa 100644 --- a/src/Model/RpcStatus.php +++ b/src/Model/RpcStatus.php @@ -4,16 +4,16 @@ class RpcStatus { - protected int $code; + protected ?int $code = null; - protected string $message; + protected ?string $message = null; /** * @var ProtobufAny[] */ - protected array $details; + protected array $details = []; - public function getCode(): int + public function getCode(): ?int { return $this->code; } @@ -24,7 +24,7 @@ public function setCode(int $code): self return $this; } - public function getMessage(): string + public function getMessage(): ?string { return $this->message; } diff --git a/src/Model/SubjectFilter.php b/src/Model/SubjectFilter.php index 6ec9926..abb0872 100644 --- a/src/Model/SubjectFilter.php +++ b/src/Model/SubjectFilter.php @@ -11,6 +11,15 @@ class SubjectFilter protected ?SubjectFilterRelationFilter $optionalRelation = null; + public static function createFromArray(array $subject) + { + $self = new self(); + $self->setSubjectType($subject[0]) + ->setOptionalSubjectId($subject[1] ?? null) + ->setOptionalRelation($subject[2] ?? null); + return $self; + } + public function getSubjectType(): ?string { return $this->subjectType; @@ -44,18 +53,18 @@ public function setOptionalRelation(?SubjectFilterRelationFilter $optionalRelati return $this; } - public static function fromSubject(\Lifestyle\Integration\SpiceDB\Service\Model\SubjectReference $subjectReference) : SubjectFilter + public static function fromSubject(SubjectReference $subjectReference) : SubjectFilter { $filter = new self(); $filter->setSubjectType($subjectReference->getObject()->getObjectType()); $filter->setOptionalSubjectId($subjectReference->getObject()->getObjectId()); - $filter->setOptionalRelation($subjectReference->getRelation()); + $filter->setOptionalRelation($subjectReference->getOptionalRelation()); return $filter; } public function __toString(): string { - return SubjectReference::create($this->subjectType, $this->optionalSubjectId, $this->optionalRelation); + return SubjectReference::create($this->subjectType, $this->optionalSubjectId, $this->optionalRelation?->getRelation()); } diff --git a/src/Model/SubjectFilterRelationFilter.php b/src/Model/SubjectFilterRelationFilter.php index 203e819..36407aa 100644 --- a/src/Model/SubjectFilterRelationFilter.php +++ b/src/Model/SubjectFilterRelationFilter.php @@ -5,14 +5,21 @@ class SubjectFilterRelationFilter { - protected string $relation; + public function __construct(protected ?string $relation) + { + } + + public static function create(string $relation): self + { + return new self($relation); + } - public function getRelation(): string + public function getRelation(): ?string { return $this->relation; } - public function setRelation(string $relation): self + public function setRelation(?string $relation): self { $this->relation = $relation; return $this; diff --git a/src/Model/SubjectReference.php b/src/Model/SubjectReference.php index 8885f69..2bf23a7 100644 --- a/src/Model/SubjectReference.php +++ b/src/Model/SubjectReference.php @@ -29,7 +29,7 @@ public static function create(string $objectType, string $objectId, string $opti return new self(new ObjectReference($objectType, $objectId), $optionalRelation); } - public static function createFromArray(array $data) + public static function createFromArray(array $data): self { return new self(new ObjectReference($data[0], $data[1]), $data[2] ?? null); }