mirror of
https://github.com/anikeen-com/id.git
synced 2026-03-13 13:46:13 +00:00
fix some issues
Signed-off-by: Maurice Preuß (envoyr) <hello@envoyr.com>
This commit is contained in:
@@ -2,21 +2,18 @@
|
|||||||
|
|
||||||
namespace Anikeen\Id\Concerns;
|
namespace Anikeen\Id\Concerns;
|
||||||
|
|
||||||
use Anikeen\Id\Contracts\Billable;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
trait HasBillable
|
trait HasBillable
|
||||||
{
|
{
|
||||||
protected Billable|Model $billable;
|
public mixed $billable;
|
||||||
|
|
||||||
public function setBillable(Billable|Model $billable): self
|
public function setBillable(mixed $billable): self
|
||||||
{
|
{
|
||||||
$this->billable = $billable;
|
$this->billable = $billable;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBillable(): Billable|Model
|
public function getBillable(): mixed
|
||||||
{
|
{
|
||||||
return $this->billable;
|
return $this->billable;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ trait HasParent
|
|||||||
{
|
{
|
||||||
protected mixed $parent;
|
protected mixed $parent;
|
||||||
|
|
||||||
public function setParent($parent): self
|
public function setParent(mixed $parent): self
|
||||||
{
|
{
|
||||||
$this->parent = $parent;
|
$this->parent = $parent;
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ trait MagicProperties
|
|||||||
protected function setMagicProperties(stdClass $data): void
|
protected function setMagicProperties(stdClass $data): void
|
||||||
{
|
{
|
||||||
foreach ($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
if (property_exists($this, $key)) {
|
if (!property_exists($this, $key)) {
|
||||||
$this->{$key} = $value;
|
$this->{$key} = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Anikeen\Id\Contracts;
|
|
||||||
|
|
||||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
|
||||||
use Anikeen\Id\Helpers\Paginator;
|
|
||||||
use Anikeen\Id\Result;
|
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
|
||||||
use stdClass;
|
|
||||||
|
|
||||||
interface Billable
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get the user data of the billable.
|
|
||||||
*
|
|
||||||
* @throws RequestRequiresClientIdException
|
|
||||||
* @throws GuzzleException
|
|
||||||
*/
|
|
||||||
public function getUserData(): ?stdClass;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a request to the API.
|
|
||||||
*
|
|
||||||
* @throws RequestRequiresClientIdException
|
|
||||||
* @throws GuzzleException
|
|
||||||
*/
|
|
||||||
public function request(string $method, string $path, null|array $payload = null, array $parameters = [], ?Paginator $paginator = null): Result;
|
|
||||||
}
|
|
||||||
@@ -4,6 +4,7 @@ namespace Anikeen\Id\Resources;
|
|||||||
|
|
||||||
use Anikeen\Id\Concerns\HasBillable;
|
use Anikeen\Id\Concerns\HasBillable;
|
||||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
||||||
|
use Anikeen\Id\Result;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
namespace Anikeen\Id\Resources;
|
namespace Anikeen\Id\Resources;
|
||||||
|
|
||||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
|
||||||
use Anikeen\Id\Result;
|
use Anikeen\Id\Result;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
|
|
||||||
abstract class BaseCollection implements JsonSerializable
|
abstract class BaseCollection implements JsonSerializable
|
||||||
@@ -19,7 +17,7 @@ abstract class BaseCollection implements JsonSerializable
|
|||||||
*/
|
*/
|
||||||
public function toArray(): array
|
public function toArray(): array
|
||||||
{
|
{
|
||||||
return (array) $this->result;
|
return (array)$this->result->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,20 +30,14 @@ abstract class BaseCollection implements JsonSerializable
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the collection of resources.
|
* Returns the collection of resources.
|
||||||
*
|
|
||||||
* @throws RequestRequiresClientIdException
|
|
||||||
* @throws GuzzleException
|
|
||||||
*/
|
*/
|
||||||
public function get(): Result
|
public function paginate(): Result
|
||||||
{
|
{
|
||||||
return $this->result;
|
return $this->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Resource based on the ID.
|
* Returns the Resource based on the ID.
|
||||||
*
|
|
||||||
* @throws RequestRequiresClientIdException
|
|
||||||
* @throws GuzzleException
|
|
||||||
*/
|
*/
|
||||||
abstract public function find(string $id): ?BaseResource;
|
abstract public function find(string $id): ?BaseResource;
|
||||||
}
|
}
|
||||||
@@ -4,9 +4,8 @@ namespace Anikeen\Id\Resources;
|
|||||||
|
|
||||||
use Anikeen\Id\Concerns\MagicProperties;
|
use Anikeen\Id\Concerns\MagicProperties;
|
||||||
use Anikeen\Id\Result;
|
use Anikeen\Id\Result;
|
||||||
use JsonSerializable;
|
|
||||||
|
|
||||||
abstract class BaseResource implements JsonSerializable
|
abstract class BaseResource
|
||||||
{
|
{
|
||||||
use MagicProperties;
|
use MagicProperties;
|
||||||
|
|
||||||
@@ -14,20 +13,4 @@ abstract class BaseResource implements JsonSerializable
|
|||||||
{
|
{
|
||||||
$this->setMagicProperties($this->result->data);
|
$this->setMagicProperties($this->result->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the collection of resources as an array.
|
|
||||||
*/
|
|
||||||
public function toArray(): array
|
|
||||||
{
|
|
||||||
return (array) $this->result->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the collection of resources as a JSON string.
|
|
||||||
*/
|
|
||||||
public function jsonSerialize(): array
|
|
||||||
{
|
|
||||||
return $this->toArray();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user