Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoray committed Jan 15, 2025
1 parent 8ce7714 commit 0a784a5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
22 changes: 19 additions & 3 deletions src/Http/Adapter/CurlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@
use Mollie\Api\Http\PendingRequest;
use Mollie\Api\Types\Method;

/**
* @phpstan-type CurlType resource|CurlHandle
*/
class CurlFactory

Check failure on line 13 in src/Http/Adapter/CurlFactory.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Type alias CurlType contains unknown class CurlHandle.

Check failure on line 13 in src/Http/Adapter/CurlFactory.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Type alias CurlType contains unknown class CurlHandle.
{
public const DEFAULT_TIMEOUT = 10;
public const DEFAULT_CONNECT_TIMEOUT = 2;

private CurlHandle $handle;
/**
* @var CurlType The curl handle
*/
private $handle;

Check failure on line 21 in src/Http/Adapter/CurlFactory.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Property Mollie\Api\Http\Adapter\CurlFactory::$handle has unknown class CurlHandle as its type.

Check failure on line 21 in src/Http/Adapter/CurlFactory.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Property Mollie\Api\Http\Adapter\CurlFactory::$handle has unknown class CurlHandle as its type.
private PendingRequest $pendingRequest;

private function __construct(CurlHandle $handle, PendingRequest $pendingRequest)
/**
* @param CurlType $handle
*/
private function __construct($handle, PendingRequest $pendingRequest)

Check failure on line 27 in src/Http/Adapter/CurlFactory.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Parameter $handle of method Mollie\Api\Http\Adapter\CurlFactory::__construct() has invalid type CurlHandle.

Check failure on line 27 in src/Http/Adapter/CurlFactory.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Parameter $handle of method Mollie\Api\Http\Adapter\CurlFactory::__construct() has invalid type CurlHandle.
{
$this->handle = $handle;
$this->pendingRequest = $pendingRequest;
Expand Down Expand Up @@ -85,11 +94,18 @@ public function withMethod(string $method, ?string $body): self
return $this;
}

public function create(): CurlHandle
/**
* @return CurlType
*/
public function create()

Check failure on line 100 in src/Http/Adapter/CurlFactory.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Method Mollie\Api\Http\Adapter\CurlFactory::create() has invalid return type CurlHandle.

Check failure on line 100 in src/Http/Adapter/CurlFactory.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Method Mollie\Api\Http\Adapter\CurlFactory::create() has invalid return type CurlHandle.
{
return $this->handle;
}

/**
* @param int $option
* @param mixed $value
*/
private function setOption(int $option, $value): void
{
if (curl_setopt($this->handle, $option, $value) === false) {
Expand Down
13 changes: 11 additions & 2 deletions src/Http/Adapter/CurlMollieHttpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Mollie\Api\Http\Adapter;

use CurlHandle;
use Mollie\Api\Contracts\HttpAdapterContract;
use Mollie\Api\Exceptions\NetworkRequestException;
use Mollie\Api\Exceptions\RetryableNetworkRequestException;
Expand All @@ -12,6 +11,9 @@
use Mollie\Api\Traits\HasDefaultFactories;
use Throwable;

/**
* @phpstan-import-type CurlType from CurlFactory
*/
final class CurlMollieHttpAdapter implements HttpAdapterContract
{
use HasDefaultFactories;
Expand Down Expand Up @@ -51,9 +53,11 @@ public function sendRequest(PendingRequest $pendingRequest): Response

/**
* @throws NetworkRequestException
* @return array{0: array<string, string>, 1: string, 2: int}
*/
protected function send(PendingRequest $pendingRequest): array
{
/** @var CurlType|null */
$curl = null;

Check failure on line 61 in src/Http/Adapter/CurlMollieHttpAdapter.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

PHPDoc tag @var contains unknown class CurlHandle.

Check failure on line 61 in src/Http/Adapter/CurlMollieHttpAdapter.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

PHPDoc tag @var contains unknown class CurlHandle.
$request = $pendingRequest->createPsrRequest();

Expand Down Expand Up @@ -100,7 +104,12 @@ protected function createResponse(PendingRequest $pendingRequest, int $statusCod
);
}

private function extractResponseDetails(CurlHandle $curl, string $response): array
/**
* @param CurlType $curl
* @param string $response
* @return array{0: array<string, string>, 1: string, 2: int}
*/
private function extractResponseDetails($curl, string $response): array

Check failure on line 112 in src/Http/Adapter/CurlMollieHttpAdapter.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Parameter $curl of method Mollie\Api\Http\Adapter\CurlMollieHttpAdapter::extractResponseDetails() has invalid type CurlHandle.

Check failure on line 112 in src/Http/Adapter/CurlMollieHttpAdapter.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Parameter $curl of method Mollie\Api\Http\Adapter\CurlMollieHttpAdapter::extractResponseDetails() has invalid type CurlHandle.
{
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$headerValues = substr($response, 0, $headerSize);
Expand Down

0 comments on commit 0a784a5

Please sign in to comment.