Skip to content

Commit

Permalink
Cleanup and fixing type bug
Browse files Browse the repository at this point in the history
  • Loading branch information
alsbury committed Nov 15, 2022
1 parent 1e879fd commit a89d5a7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/Model/RpcStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -24,7 +24,7 @@ public function setCode(int $code): self
return $this;
}

public function getMessage(): string
public function getMessage(): ?string
{
return $this->message;
}
Expand Down
15 changes: 12 additions & 3 deletions src/Model/SubjectFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}


Expand Down
13 changes: 10 additions & 3 deletions src/Model/SubjectFilterRelationFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Model/SubjectReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit a89d5a7

Please sign in to comment.