Skip to content

Commit

Permalink
Declare typed properties
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Aug 15, 2023
1 parent b8b12bc commit 9474619
Show file tree
Hide file tree
Showing 25 changed files with 117 additions and 313 deletions.
5 changes: 1 addition & 4 deletions src/JsonApi/Client/JsonApiAsyncClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

class JsonApiAsyncClient
{
/**
* @var HttpAsyncClient
*/
private $client;
private HttpAsyncClient $client;

public function __construct(HttpAsyncClient $client)
{
Expand Down
6 changes: 1 addition & 5 deletions src/JsonApi/Client/JsonApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ class JsonApiClient
* @var ClientInterface
*/
private $client;

/**
* @var DeserializerInterface
*/
private $deserializer;
private DeserializerInterface $deserializer;

public function __construct(ClientInterface $client, ?DeserializerInterface $deserializer = null)
{
Expand Down
5 changes: 1 addition & 4 deletions src/JsonApi/Hydrator/AbstractClassDocumentHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ public function hydrateCollection(Document $document): iterable
return $this->hydratePrimaryResources($document);
}

/**
* @return object
*/
public function hydrateSingleResource(Document $document)
public function hydrateSingleResource(Document $document): object
{
if ($document->isSingleResourceDocument() === false) {
throw new DocumentException(
Expand Down
5 changes: 1 addition & 4 deletions src/JsonApi/Hydrator/ClassDocumentHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

class ClassDocumentHydrator extends AbstractClassDocumentHydrator
{
/**
* @var AttributeHydratorInterface
*/
private $attributeHydrator;
private AttributeHydratorInterface $attributeHydrator;

public function __construct(?AttributeHydratorInterface $attributeHydrator = null)
{
Expand Down
65 changes: 20 additions & 45 deletions src/JsonApi/Request/JsonApiRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,20 @@

class JsonApiRequestBuilder
{
/** @var RequestInterface */
private $request;

/** @var SerializerInterface */
private $serializer;

/** @var string */
private $method;

/** @var string */
private $protocolVersion;

/** @var string */
private $scheme;

/** @var string */
private $host;

/** @var int */
private $port;

/** @var string */
private $path;

/** @var array */
private $queryString;

/** @var array */
private $headers;

private RequestInterface $request;
private SerializerInterface $serializer;
private string $method;
private string $protocolVersion;
private string $scheme;
private string $host;
private ?int $port;
private string $path;
private array $queryString;
private array $headers;
/** @var string[] */
private $appliedProfiles;

private array $appliedProfiles;
/** @var string[] */
private $requestedProfiles;

/** @var string[] */
private $requiredProfiles;

private array $requestedProfiles;
/** @var mixed */
private $body;

Expand All @@ -73,12 +48,12 @@ public function initialize(): void
$this->protocolVersion = "";
$this->scheme = "http";
$this->host = "";
$this->port = null;
$this->path = "";
$this->queryString = [];
$this->headers = [];
$this->appliedProfiles = [];
$this->requestedProfiles = [];
$this->requiredProfiles = [];
}

public function fetch(): JsonApiRequestBuilder
Expand Down Expand Up @@ -134,23 +109,23 @@ public function setUri(string $uri): JsonApiRequestBuilder
}

if ($this->isBlankKey($parsedUri, "scheme") === false) {
$this->scheme = $parsedUri["scheme"];
$this->scheme = $parsedUri["scheme"] ?? "";
}

if ($this->isBlankKey($parsedUri, "port") === false) {
$this->port = $parsedUri["port"];
$this->port = $parsedUri["port"] ?? null;
}

if ($this->isBlankKey($parsedUri, "host") === false) {
$this->host = $parsedUri["host"];
$this->host = $parsedUri["host"] ?? "";
}

if ($this->isBlankKey($parsedUri, "path") === false) {
$this->path = $parsedUri["path"];
$this->path = $parsedUri["path"] ?? "";
}

if ($this->isBlankKey($parsedUri, "query") === false) {
parse_str($parsedUri["query"], $this->queryString);
parse_str($parsedUri["query"] ?? "", $this->queryString);
}

return $this;
Expand All @@ -170,7 +145,7 @@ public function setUriHost(string $host): JsonApiRequestBuilder
return $this;
}

public function setUriPort(int $port): JsonApiRequestBuilder
public function setUriPort(?int $port): JsonApiRequestBuilder
{
$this->port = $port;

Expand All @@ -185,7 +160,7 @@ public function setUriPath(string $path): JsonApiRequestBuilder
}

/**
* @param string|array $value
* @param string|array<int|string, mixed> $value
*/
public function setUriQueryParam(string $name, $value): JsonApiRequestBuilder
{
Expand Down
25 changes: 6 additions & 19 deletions src/JsonApi/Request/ResourceObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,12 @@

class ResourceObject
{
/**
* @var string
*/
private $type;

/**
* @var string
*/
private $id;

/**
* @var array
*/
private $attributes;

/**
* @var RelationshipInterface[]
*/
private $relationships;
private string $type;
private string $id;
/** @var array<string, mixed> */
private array $attributes;
/** @var array<string, RelationshipInterface> */
private array $relationships;

public static function create(string $type, string $id = ""): ResourceObject
{
Expand Down
5 changes: 1 addition & 4 deletions src/JsonApi/Request/ToManyRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

final class ToManyRelationship implements RelationshipInterface
{
/**
* @var array
*/
private $resourceIdentifiers = [];
private array $resourceIdentifiers = [];

public static function create(): ToManyRelationship
{
Expand Down
18 changes: 4 additions & 14 deletions src/JsonApi/Request/ToOneRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,10 @@

final class ToOneRelationship implements RelationshipInterface
{
/**
* @var string
*/
private $type;

/**
* @var string
*/
private $id;

/**
* @var array
*/
private $meta;
private string $type;
private string $id;
/** @var array<int|string, mixed> */
private array $meta;

public static function create(string $type, string $id, array $meta = []): ToOneRelationship
{
Expand Down
17 changes: 7 additions & 10 deletions src/JsonApi/Response/AbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@

abstract class AbstractResponse implements ResponseInterface
{
/**
* @var ResponseInterface
*/
protected $response;
protected ResponseInterface $response;

public function __construct(ResponseInterface $response)
{
Expand All @@ -28,7 +25,7 @@ public function getProtocolVersion(): string
* @param string $version
* @return $this
*/
public function withProtocolVersion($version)
public function withProtocolVersion($version): ResponseInterface
{
$response = clone $this;
$response->response = $this->response->withProtocolVersion($version);
Expand Down Expand Up @@ -74,7 +71,7 @@ public function getHeaderLine($name): string
* @param string|string[] $value
* @return $this
*/
public function withHeader($name, $value)
public function withHeader($name, $value): ResponseInterface
{
$response = clone $this;
$response->response = $this->response->withHeader($name, $value);
Expand All @@ -87,7 +84,7 @@ public function withHeader($name, $value)
* @param string|string[] $value
* @return $this
*/
public function withAddedHeader($name, $value)
public function withAddedHeader($name, $value): ResponseInterface
{
$response = clone $this;
$response->response = $this->response->withAddedHeader($name, $value);
Expand All @@ -99,7 +96,7 @@ public function withAddedHeader($name, $value)
* @param string $name
* @return $this
*/
public function withoutHeader($name)
public function withoutHeader($name): ResponseInterface
{
$response = clone $this;
$response->response = $this->response->withoutHeader($name);
Expand All @@ -115,7 +112,7 @@ public function getBody(): StreamInterface
/**
* @return $this
*/
public function withBody(StreamInterface $body)
public function withBody(StreamInterface $body): ResponseInterface
{
$response = clone $this;
$response->response = $this->response->withBody($body);
Expand All @@ -133,7 +130,7 @@ public function getStatusCode(): int
* @param string $reasonPhrase
* @return $this
*/
public function withStatus($code, $reasonPhrase = "")
public function withStatus($code, $reasonPhrase = ""): ResponseInterface
{
$response = clone $this;
$response->response = $this->response->withStatus($code, $reasonPhrase);
Expand Down
9 changes: 2 additions & 7 deletions src/JsonApi/Response/JsonApiResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@

class JsonApiResponse extends AbstractResponse
{
/**
* @var DeserializerInterface
*/
private $deserializer;
private DeserializerInterface $deserializer;

/**
* @var Document|false|null
*/
/** @var Document|false|null */
private $document = false;

public function __construct(ResponseInterface $response, ?DeserializerInterface $deserializer = null)
Expand Down
37 changes: 9 additions & 28 deletions src/JsonApi/Schema/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,15 @@

final class Document
{
/**
* @var JsonApiObject
*/
private $jsonApi;

/**
* @var array
*/
private $meta;

/**
* @var DocumentLinks
*/
private $links;

/**
* @var ResourceObjects
*/
private $resources;

/**
* @var Error[]
*/
private $errors;

/**
* @param Error[] $errors
*/
private JsonApiObject $jsonApi;
/** @var array<int|string, mixed> */
private array $meta;
private DocumentLinks $links;
private ResourceObjects $resources;
/** @var array<int, Error> */
private array $errors;

/** @param array<int, Error> $errors */
public function __construct(JsonApiObject $jsonApi, array $meta, DocumentLinks $links, ResourceObjects $resources, array $errors)
{
$this->jsonApi = $jsonApi;
Expand Down
Loading

0 comments on commit 9474619

Please sign in to comment.