Skip to content

feat/phpdoc-for-ecloud #545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

namespace UKFast\SDK;

use Closure;
use GuzzleHttp\Psr7\Request;
use UKFast\SDK\Client;
use UKFast\SDK\Exception\InvalidJsonException;

/**
* @template T of Entity
*/
class Page
{
/**
* @var array
* @var array<int, T>
*/
protected $items;

Expand All @@ -24,7 +28,7 @@ class Page
protected $request;

/**
* @var \Closure|null
* @var Closure|null
*/
protected $serializer;

Expand All @@ -41,7 +45,7 @@ public function __construct($items, $meta, $request)
}

/**
* @return array
* @return array<int, T>
*/
public function getItems()
{
Expand All @@ -51,8 +55,8 @@ public function getItems()
/**
* Setter for page items
*
* @param array $items
* @return \UKFast\SDK\Page
* @param array<int, T> $items
* @return array<int, T>
*/
public function setItems($items)
{
Expand All @@ -64,8 +68,8 @@ public function setItems($items)
* Sets a mapping function to serialize each
* item in a new page with
*
* @param \Closure $callback
* @return \UKFast\SDK\Page
* @param Closure $callback
* @return Page<T>
*/
public function serializeWith($callback)
{
Expand All @@ -78,7 +82,7 @@ public function serializeWith($callback)
* Applies a callback to each item in the page
* and returns the resulting array
*
* @param \Closure $callback
* @param Closure $callback
* @return array
*/
public function map($callback)
Expand All @@ -95,8 +99,8 @@ public function map($callback)
* Sets client to use when making requests
* to other pages
*
* @param \UKFast\SDK\Client $client
* @return \UKFast\SDK\Page
* @param Client $client
* @return Page<T>
*/
public function setClient(Client $client)
{
Expand Down Expand Up @@ -176,7 +180,7 @@ public function pageNumber()
* Gets a page by number
*
* @param int $number
* @return \UKFast\SDK\Page
* @return Page<T>
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \UKFast\SDK\Exception\InvalidJsonException
*/
Expand All @@ -192,7 +196,7 @@ public function getPage($number)
}

/**
* @return \UKFast\SDK\Page|false
* @return Page<T>|false
*/
public function getNextPage()
{
Expand All @@ -205,7 +209,7 @@ public function getNextPage()
}

/**
* @return \UKFast\SDK\Page|false
* @return Page<T>|false
*/
public function getPreviousPage()
{
Expand All @@ -218,7 +222,7 @@ public function getPreviousPage()
}

/**
* @return \UKFast\SDK\Page
* @return Page<T>
*/
public function getFirstPage()
{
Expand All @@ -227,7 +231,7 @@ public function getFirstPage()
}

/**
* @return \UKFast\SDK\Page
* @return Page<T>
*/
public function getLastPage()
{
Expand All @@ -241,7 +245,7 @@ public function getLastPage()
*
* @param Response $response
* @param string|\Psr\Http\Message\UriInterface $uri
* @return \UKFast\SDK\Page
* @return Page<T>
* @throws \UKFast\SDK\Exception\InvalidJsonException
*/
private function constructNewPage($response, $uri)
Expand Down
15 changes: 10 additions & 5 deletions src/Traits/PageItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace UKFast\SDK\Traits;

use UKFast\SDK\Entity;
use UKFast\SDK\Page;
use UKFast\SDK\SelfResponse;

/**
* @template T of Entity
*/
trait PageItems
{
/**
Expand All @@ -19,6 +23,7 @@ public function getEntityMap()
/**
* Return an entity model
* @param $data
* @return T
*/
abstract public function loadEntity($data);

Expand All @@ -28,7 +33,7 @@ abstract public function loadEntity($data);
* @param int $page
* @param int $perPage
* @param array $filters
* @return Page
* @return Page<T>
*/
public function getPage($page = 1, $perPage = 15, $filters = [])
{
Expand All @@ -49,7 +54,7 @@ public function getPage($page = 1, $perPage = 15, $filters = [])
* Get an array of all items from all pages
*
* @param array $filters
* @return array
* @return array<int, T>
*/
public function getAll($filters = [])
{
Expand Down Expand Up @@ -79,7 +84,7 @@ public function getAll($filters = [])
/**
* Get a single item from the collection
* @param $id
* @return mixed
* @return T
*/
public function getById($id)
{
Expand All @@ -101,7 +106,7 @@ public function deleteById($id)

/**
* Create a new item for the collection
* @param $entity
* @param T $entity
* @return SelfResponse
*/
public function createEntity($entity)
Expand All @@ -121,7 +126,7 @@ public function createEntity($entity)

/**
* Update an existing item in the collection
* @param $entity
* @param T $entity
* @return SelfResponse
*/
public function updateEntity($entity)
Expand Down
1 change: 1 addition & 0 deletions src/eCloud/AffinityRuleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class AffinityRuleClient extends Client implements ClientEntityInterface
{
/** @use PageItems<AffinityRule> */
use PageItems;

protected $collectionPath = 'v2/affinity-rules';
Expand Down
1 change: 1 addition & 0 deletions src/eCloud/AffinityRuleMemberClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class AffinityRuleMemberClient extends Client implements ClientEntityInterface
{
/** @use PageItems<AffinityRuleMember> */
use PageItems;

protected $collectionPath = 'v2/affinity-rule-members';
Expand Down
2 changes: 1 addition & 1 deletion src/eCloud/ApplianceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ApplianceClient extends Client
* @param int $page
* @param int $perPage
* @param array $filters
* @return Page
* @return Page<Appliance>
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function getPage($page = 1, $perPage = 15, $filters = [])
Expand Down
1 change: 1 addition & 0 deletions src/eCloud/AvailabilityZoneClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

class AvailabilityZoneClient extends Client implements ClientEntityInterface
{
/** @use PageItems<AvailabilityZone> */
use PageItems;

protected $collectionPath = 'v2/availability-zones';
Expand Down
1 change: 1 addition & 0 deletions src/eCloud/BillingHistoryClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class BillingHistoryClient extends Client implements ClientEntityInterface
{
/** @use PageItems<BillingHistory> */
use PageItems;

protected $collectionPath = 'v2/billing-history';
Expand Down
1 change: 1 addition & 0 deletions src/eCloud/BillingMetricClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class BillingMetricClient extends Client implements ClientEntityInterface
{
/** @use PageItems<BillingMetric> */
use PageItems;

protected $collectionPath = 'v2/billing-metrics';
Expand Down
Loading