Skip to content

Commit

Permalink
Correcting params to the method. Updated php docs
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-mykhailenko committed Jul 30, 2024
1 parent 4891e53 commit c8a5976
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/Api/HttpApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract class HttpApi
* @param RequestBuilder $requestBuilder
* @param Hydrator $hydrator
*/
public function __construct($httpClient, RequestBuilder $requestBuilder, Hydrator $hydrator)
public function __construct(ClientInterface $httpClient, RequestBuilder $requestBuilder, Hydrator $hydrator)
{
$this->httpClient = $httpClient;
$this->requestBuilder = $requestBuilder;
Expand Down
8 changes: 4 additions & 4 deletions src/Api/MailingList/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ public function create(
* @param array $members Array of members, each item should be either a single string address or an array of member properties
* @param bool $upsert `true` to update existing members, `false` (default) to ignore duplicates
* @param array $requestHeaders
* @return UpdateResponse
* @return MailingListUpdateResponse
* @throws ClientExceptionInterface
*/
public function createMultiple(string $list, array $members, bool $upsert = false, array $requestHeaders = [])
public function createMultiple(string $list, array $members, bool $upsert = false, array $requestHeaders = []): MailingListUpdateResponse
{
Assert::stringNotEmpty($list);
Assert::isArray($members);
Expand Down Expand Up @@ -156,11 +156,11 @@ public function createMultiple(string $list, array $members, bool $upsert = fals
if (is_array($value)) {
$value = json_encode($value);
}
// We should assert that "vars"'s $value is a string.
break;
// We should assert that "vars"'s $value is a string.
// no break
case 'name':
Assert::string($value);

break;
case 'subscribed':
Assert::oneOf($value, ['yes', 'no', true, false]);
Expand Down
14 changes: 12 additions & 2 deletions src/Api/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,19 @@
*/
trait Pagination
{
/**
* @param string $path
* @param array $parameters
* @param array $requestHeaders
* @return ResponseInterface
*/
abstract protected function httpGet(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface;


/**
* @param class-string $className
* @param ResponseInterface $response
* @param string $className
* @return mixed
*/
abstract protected function hydrateResponse(ResponseInterface $response, string $className);

Expand All @@ -49,8 +58,9 @@ public function previousPage(PagingProvider $response): ?PagingProvider
}

/**
* @param PagingProvider $response
* @param PagingProvider $response
* @return PagingProvider|null
* @throws ClientExceptionInterface
*/
public function firstPage(PagingProvider $response): ?PagingProvider
{
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function index(string $domain, int $limit, string $page, string $pivot, a

$params = [
'limit' => $limit,
'skip' => $page,
'page' => $page,
'p' => $pivot,
];

Expand Down
8 changes: 7 additions & 1 deletion src/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
*/
final class Assert extends \Webmozart\Assert\Assert
{
protected static function reportInvalidArgument($message)
/**
* @psalm-pure this method is not supposed to perform side-effects
* @psalm-return never
* @param $message
* @return void
*/
protected static function reportInvalidArgument($message): void

Check failure on line 29 in src/Assert.php

View workflow job for this annotation

GitHub Actions / PHPStan

PHPDoc tag @param has invalid value ($message): Unexpected token "$message", expected type at offset 116
{
throw new InvalidArgumentException($message);
}
Expand Down
32 changes: 32 additions & 0 deletions src/HttpClient/HttpClientConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,32 +101,50 @@ public function createConfiguredClient(): PluginClient
return new PluginClient($this->getHttpClient(), $plugins);
}

/**
* @param bool $debug
* @return $this
*/
public function setDebug(bool $debug): self
{
$this->debug = $debug;

return $this;
}

/**
* @param string $endpoint
* @return $this
*/
public function setEndpoint(string $endpoint): self
{
$this->endpoint = $endpoint;

return $this;
}

/**
* @return string
*/
public function getApiKey(): string
{
return $this->apiKey;
}

/**
* @param string $apiKey
* @return $this
*/
public function setApiKey(string $apiKey): self
{
$this->apiKey = $apiKey;

return $this;
}

/**
* @return UriFactoryInterface
*/
private function getUriFactory(): UriFactoryInterface
{
if (null === $this->uriFactory) {
Expand All @@ -136,13 +154,20 @@ private function getUriFactory(): UriFactoryInterface
return $this->uriFactory;
}

/**
* @param UriFactoryInterface $uriFactory
* @return $this
*/
public function setUriFactory(UriFactoryInterface $uriFactory): self
{
$this->uriFactory = $uriFactory;

return $this;
}

/**
* @return ClientInterface
*/
private function getHttpClient(): ClientInterface
{
if (null === $this->httpClient) {
Expand All @@ -152,13 +177,20 @@ private function getHttpClient(): ClientInterface
return $this->httpClient;
}

/**
* @param ClientInterface $httpClient
* @return $this
*/
public function setHttpClient(ClientInterface $httpClient): self
{
$this->httpClient = $httpClient;

return $this;
}

/**
* @return History
*/
public function getResponseHistory(): History
{
return $this->responseHistory;
Expand Down
9 changes: 9 additions & 0 deletions src/HttpClient/Plugin/ReplaceUriPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,20 @@ final class ReplaceUriPlugin implements Plugin
*/
private $uri;

/**
* @param UriInterface $uri
*/
public function __construct(UriInterface $uri)
{
$this->uri = $uri;
}

/**
* @param RequestInterface $request
* @param callable $next
* @param callable $first
* @return mixed
*/
public function doHandleRequest(RequestInterface $request, callable $next, callable $first)
{
$request = $request->withUri($this->uri);
Expand Down
31 changes: 16 additions & 15 deletions src/HttpClient/RequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class RequestBuilder

/**
* Creates a new PSR-7 request.
*
* @param string $method HTTP method
* @param string $uri URI
* @param array $headers Request headers
* @param array|string|null $body Request body. If body is an array we will send a as multipart stream request.
* If array, each array *item* MUST look like:
* array (
Expand All @@ -53,7 +55,7 @@ class RequestBuilder
public function create(string $method, string $uri, array $headers = [], $body = null): RequestInterface
{
if (!is_array($body)) {
$stream = $this->getStreamFactory()->createStream((string) $body);
$stream = $this->getStreamFactory()->createStream((string)$body);

return $this->createRequest($method, $uri, $headers, $stream);
}
Expand All @@ -62,8 +64,7 @@ public function create(string $method, string $uri, array $headers = [], $body =
foreach ($body as $item) {
$name = $this->getItemValue($item, 'name');
$content = $this->getItemValue($item, 'content');
unset($item['name']);
unset($item['content']);
unset($item['name'], $item['content']);

$builder->addResource($name, $content, $item);
}
Expand All @@ -72,7 +73,7 @@ public function create(string $method, string $uri, array $headers = [], $body =
$boundary = $builder->getBoundary();
$builder->reset();

$headers['Content-Type'] = 'multipart/form-data; boundary="'.$boundary.'"';
$headers['Content-Type'] = 'multipart/form-data; boundary="' . $boundary . '"';

return $this->createRequest($method, $uri, $headers, $multipartStream);
}
Expand All @@ -90,7 +91,7 @@ private function getRequestFactory(): RequestFactoryInterface
}

/**
* @param RequestFactoryInterface $requestFactory
* @param RequestFactoryInterface $requestFactory
* @return $this
*/
public function setRequestFactory(RequestFactoryInterface $requestFactory): self
Expand All @@ -113,7 +114,7 @@ private function getStreamFactory(): StreamFactoryInterface
}

/**
* @param StreamFactoryInterface $streamFactory
* @param StreamFactoryInterface $streamFactory
* @return $this
*/
public function setStreamFactory(StreamFactoryInterface $streamFactory): self
Expand All @@ -136,7 +137,7 @@ private function getMultipartStreamBuilder(): MultipartStreamBuilder
}

/**
* @param MultipartStreamBuilder $multipartStreamBuilder
* @param MultipartStreamBuilder $multipartStreamBuilder
* @return $this
*/
public function setMultipartStreamBuilder(MultipartStreamBuilder $multipartStreamBuilder): self
Expand All @@ -147,10 +148,10 @@ public function setMultipartStreamBuilder(MultipartStreamBuilder $multipartStrea
}

/**
* @param string $method
* @param string $uri
* @param array $headers
* @param StreamInterface $stream
* @param string $method
* @param string $uri
* @param array $headers
* @param StreamInterface $stream
* @return RequestInterface
*/
private function createRequest(string $method, string $uri, array $headers, StreamInterface $stream): RequestInterface
Expand All @@ -165,14 +166,14 @@ private function createRequest(string $method, string $uri, array $headers, Stre
}

/**
* @param array $item
* @param string $key
* @param array $item
* @param string $key
* @return mixed|string
*/
private function getItemValue(array $item, string $key)
{
if (is_bool($item[$key])) {
return (string) $item[$key];
return (string)$item[$key];
}

return $item[$key];
Expand Down
2 changes: 1 addition & 1 deletion src/Mailgun.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function tags(): Api\Tag
*/
public function webhooks(): Api\Webhook
{
return new Api\Webhook($this->httpClient, $this->requestBuilder, $this->hydrator, $this->apiKey);
return new Api\Webhook($this->httpClient, $this->requestBuilder, $this->hydrator, $this->apiKey ?? '');
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Message/BatchMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ public function __construct(Message $messageApi, string $domain, bool $autoSend)
* full_name?: string,
* first?: string,
* last?: string,
*
* @return MessageBuilder
* @throws MissingRequiredParameter
* @throws TooManyRecipients
* @throws TooManyRecipients|ClientExceptionInterface
*/
protected function addRecipient(string $headerName, string $address, array $variables): MessageBuilder
{
Expand Down
5 changes: 5 additions & 0 deletions src/Message/Exceptions/LimitExceeded.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

class LimitExceeded extends \Exception implements Exception
{
/**
* @param string $field
* @param int $limit
* @return self
*/
public static function create(string $field, int $limit)
{
return new self(sprintf('You\'ve exceeded the maximum (%d) %s for a single message.', $limit, $field));
Expand Down
5 changes: 5 additions & 0 deletions src/Message/Exceptions/MissingRequiredParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

class MissingRequiredParameter extends \Exception implements Exception
{
/**
* @param string $parameter
* @param string|null $message
* @return self
*/
public static function create(string $parameter, string $message = null)
{
if (null === $message) {
Expand Down
9 changes: 9 additions & 0 deletions src/Message/Exceptions/TooManyRecipients.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@

class TooManyRecipients extends LimitExceeded implements Exception
{
/**
* @param string $field
* @param int $limit
* @return LimitExceeded|self
*/
public static function create(string $field, int $limit = MessageBuilder::RECIPIENT_COUNT_LIMIT)
{
return new self(sprintf('You\'ve exceeded the maximum recipient count (%s) for filed "%s".', $limit, $field));
}

/**
* @param int $limit
* @return self
*/
public static function whenAutoSendDisabled(int $limit = MessageBuilder::RECIPIENT_COUNT_LIMIT)
{
return new self(sprintf('You\'ve exceeded the maximum recipient count (%s) with autosend disabled.', $limit));
Expand Down
Loading

0 comments on commit c8a5976

Please sign in to comment.