Skip to content

Commit f036ea9

Browse files
committed
Adding support for PHP8, dropping support for PHP7
1 parent e8154b5 commit f036ea9

31 files changed

+80
-525
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: "Setup PHP"
1818
uses: "shivammathur/setup-php@v2"
1919
with:
20-
php-version: "7.3"
20+
php-version: "8.0"
2121
extensions: "curl, soap"
2222
tools: "composer:v2"
2323

@@ -40,7 +40,7 @@ jobs:
4040
- name: "Setup PHP"
4141
uses: "shivammathur/setup-php@v2"
4242
with:
43-
php-version: "7.3"
43+
php-version: "8.0"
4444
extensions: "curl, soap"
4545
tools: "composer:v2"
4646

@@ -57,7 +57,7 @@ jobs:
5757
strategy:
5858
fail-fast: true
5959
matrix:
60-
php: ["7.3", "7.4"]
60+
php: ["8.0"]
6161
composer_flags: ["", "--prefer-lowest"]
6262

6363
name: "Tests PHP ${{ matrix.php }} ${{ matrix.composer_flags}}"
@@ -92,7 +92,7 @@ jobs:
9292
strategy:
9393
fail-fast: true
9494
matrix:
95-
guzzle: ["3", "5", "6"]
95+
guzzle: ["5", "6"]
9696

9797
name: "Integration test for Guzzle ${{ matrix.guzzle }}"
9898

@@ -105,7 +105,7 @@ jobs:
105105
- name: "Setup PHP"
106106
uses: "shivammathur/setup-php@v2"
107107
with:
108-
php-version: "7.3"
108+
php-version: "8.0"
109109
extensions: "curl, soap"
110110
tools: "composer:v2"
111111
coverage: "pcov"
@@ -137,7 +137,7 @@ jobs:
137137
- name: "Setup PHP"
138138
uses: "shivammathur/setup-php@v2"
139139
with:
140-
php-version: "7.3"
140+
php-version: "8.0"
141141
extensions: "curl, soap"
142142
tools: "composer:v2"
143143
coverage: "pcov"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ tests/fixtures/cassette*
88
/.php_cs
99
composer.lock
1010
.phpunit.result.cache
11+
.php-cs-fixer.cache

composer.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"test": "./vendor/bin/phpunit",
77
"lint": "./vendor/bin/php-cs-fixer fix --verbose --diff --dry-run",
88
"fix": "./vendor/bin/php-cs-fixer fix --verbose --diff",
9-
"phpstan": "phpstan analyse -c phpstan.neon --no-progress -vvv"
9+
"phpstan": "php -d memory_limit=-1 vendor/bin/phpstan analyse -c phpstan.neon --no-progress -vvv"
1010
},
1111
"authors": [
1212
{
@@ -15,20 +15,22 @@
1515
}
1616
],
1717
"require": {
18-
"php": ">=7.3",
18+
"php": "^8.0",
1919
"ext-curl": "*",
2020
"beberlei/assert": "^3.2.5",
21-
"symfony/yaml": "~2.1|^3.0|^4.0|^5.0",
22-
"symfony/event-dispatcher": "^2.4|^3.0|^4.0|^5.0"
21+
"symfony/yaml": "^3.0|^4.0|^5.0",
22+
"symfony/event-dispatcher": "^5.0"
2323
},
2424
"require-dev": {
2525
"phpunit/phpunit": "^8.4.0",
26-
"mikey179/vfsstream": "^1.6",
27-
"phpstan/phpstan": "^0.12",
26+
"mikey179/vfsstream": "^1.6.10",
27+
"phpstan/phpstan": "^0.12.92",
2828
"phpstan/phpstan-beberlei-assert": "^0.12.0",
2929
"thecodingmachine/phpstan-strict-rules": "^0.12",
3030
"sebastian/version": "^1.0.3|^2.0",
31-
"friendsofphp/php-cs-fixer": "^2.16"
31+
"friendsofphp/php-cs-fixer": "^3.0",
32+
"phpstan/phpstan-phpunit": "^0.12.22",
33+
"phpstan/extension-installer": "^1.1"
3234
},
3335
"autoload": {
3436
"psr-4": {

phpstan.neon

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,3 @@ parameters:
99
- "#Access to an undefined property object::\\$datalen\\.#"
1010
# PHPStan cannot detect that strrpos will succeed (because of Assertion above) in HttpUtil::parseStatus
1111
- '#Parameter .* \$str(ing)? of function substr expects string, string\|false given.#'
12-
# The EventDispatcherInterface::dispatch signature is different (!) between Symfony <4.3 and >=4.3
13-
- '/Parameter #1 \$event of method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\) expects object, string\|null given./'
14-
- '/Parameter #2 \$eventName of method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\) expects string\|null, VCR\\Event\\Event given./'
15-
- '#Call to an undefined method org\\bovigo\\vfs\\vfsStreamContent::hasChild\(\)\.#'
16-
includes:
17-
- vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon
18-
- vendor/phpstan/phpstan-beberlei-assert/extension.neon

resources/docker/workspace/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:7.3-cli-alpine
1+
FROM php:8.0-cli-alpine
22

33
ARG PUID=1000
44
ARG PGID=1000

src/VCR/Event/Event.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,6 @@
22

33
namespace VCR\Event;
44

5-
use Symfony\Component\EventDispatcher\Event as LegacyEvent;
6-
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
7-
8-
if (class_exists(ContractsEvent::class) && !class_exists(LegacyEvent::class)) {
9-
abstract class SymphonyEvent extends ContractsEvent
10-
{
11-
}
12-
} elseif (class_exists(LegacyEvent::class)) {
13-
abstract class SymphonyEvent extends LegacyEvent
14-
{
15-
}
16-
}
17-
18-
abstract class Event extends SymphonyEvent
5+
abstract class Event extends \Symfony\Contracts\EventDispatcher\Event
196
{
207
}

src/VCR/LibraryHooks/CurlHook.php

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace VCR\LibraryHooks;
44

5+
use CurlHandle;
56
use VCR\CodeTransform\AbstractCodeTransform;
67
use VCR\Request;
78
use VCR\Response;
@@ -166,15 +167,9 @@ public static function __callStatic($method, array $args)
166167
}
167168

168169
/**
169-
* Initialize a cURL session.
170-
*
171170
* @see http://www.php.net/manual/en/function.curl-init.php
172-
*
173-
* @param string|null $url (Optional) url
174-
*
175-
* @return resource|false cURL handle
176171
*/
177-
public static function curlInit(?string $url = null)
172+
public static function curlInit(?string $url = null): CurlHandle|false
178173
{
179174
$curlHandle = curl_init($url);
180175
if (false !== $curlHandle) {
@@ -186,13 +181,9 @@ public static function curlInit(?string $url = null)
186181
}
187182

188183
/**
189-
* Reset a cURL session.
190-
*
191184
* @see http://www.php.net/manual/en/function.curl-reset.php
192-
*
193-
* @param resource $curlHandle a cURL handle returned by curl_init()
194185
*/
195-
public static function curlReset($curlHandle): void
186+
public static function curlReset(CurlHandle $curlHandle): void
196187
{
197188
curl_reset($curlHandle);
198189
self::$requests[(int) $curlHandle] = new Request('GET', null);
@@ -205,13 +196,11 @@ public static function curlReset($curlHandle): void
205196
*
206197
* @see http://www.php.net/manual/en/function.curl-exec.php
207198
*
208-
* @param resource $curlHandle a cURL handle returned by curl_init()
209-
*
210199
* @return mixed Returns TRUE on success or FALSE on failure.
211200
* However, if the CURLOPT_RETURNTRANSFER option is set, it will return the
212201
* result on success, FALSE on failure.
213202
*/
214-
public static function curlExec($curlHandle)
203+
public static function curlExec(CurlHandle $curlHandle)
215204
{
216205
try {
217206
$request = self::$requests[(int) $curlHandle];
@@ -330,12 +319,9 @@ public static function curlMultiGetcontent($curlHandle): ?string
330319
*
331320
* @see http://www.php.net/manual/en/function.curl-getinfo.php
332321
*
333-
* @param resource $curlHandle a cURL handle returned by curl_init()
334-
* @param int $option a cURL option defined in the cURL Predefined Constants
335-
*
336322
* @return mixed
337323
*/
338-
public static function curlGetinfo($curlHandle, int $option = 0)
324+
public static function curlGetinfo(CurlHandle $curlHandle, int $option = 0)
339325
{
340326
if (isset(self::$responses[(int) $curlHandle])) {
341327
return CurlHelper::getCurlOptionFromResponse(
@@ -354,15 +340,11 @@ public static function curlGetinfo($curlHandle, int $option = 0)
354340
*
355341
* @see http://www.php.net/manual/en/function.curl-setopt.php
356342
*
357-
* @param resource $curlHandle a cURL handle returned by curl_init()
358-
* @param int $option the CURLOPT_XXX option to set
359-
* @param mixed $value the value to be set on option
360-
*
361-
* @return bool returns TRUE on success or FALSE on failure
343+
* @param mixed $value the value to be set on option
362344
*/
363-
public static function curlSetopt($curlHandle, int $option, $value): bool
345+
public static function curlSetopt(CurlHandle $curlHandle, int $option, $value): bool
364346
{
365-
CurlHelper::setCurlOptionOnRequest(self::$requests[(int) $curlHandle], $option, $value, $curlHandle);
347+
CurlHelper::setCurlOptionOnRequest(self::$requests[(int) $curlHandle], $option, $value);
366348

367349
static::$curlOptions[(int) $curlHandle][$option] = $value;
368350

@@ -374,29 +356,21 @@ public static function curlSetopt($curlHandle, int $option, $value): bool
374356
*
375357
* @see http://www.php.net/manual/en/function.curl-setopt-array.php
376358
*
377-
* @param resource $curlHandle a cURL handle returned by curl_init()
378-
* @param array<int, mixed> $options an array specifying which options to set and their values
359+
* @param array<int, mixed> $options an array specifying which options to set and their values
379360
*/
380-
public static function curlSetoptArray($curlHandle, array $options): void
361+
public static function curlSetoptArray(CurlHandle $curlHandle, array $options): void
381362
{
382-
if (\is_array($options)) {
383-
foreach ($options as $option => $value) {
384-
static::curlSetopt($curlHandle, $option, $value);
385-
}
363+
foreach ($options as $option => $value) {
364+
static::curlSetopt($curlHandle, $option, $value);
386365
}
387366
}
388367

389368
/**
390369
* Return a string containing the last error for the current session.
391370
*
392371
* @see https://php.net/manual/en/function.curl-error.php
393-
*
394-
* @param resource $curlHandle
395-
*
396-
* @return string the error message or '' (the empty string) if no
397-
* error occurred
398372
*/
399-
public static function curlError($curlHandle): string
373+
public static function curlError(CurlHandle $curlHandle): string
400374
{
401375
if (isset(self::$lastErrors[(int) $curlHandle])) {
402376
return self::$lastErrors[(int) $curlHandle]->getMessage();
@@ -409,13 +383,8 @@ public static function curlError($curlHandle): string
409383
* Return the last error number.
410384
*
411385
* @see https://php.net/manual/en/function.curl-errno.php
412-
*
413-
* @param resource $curlHandle
414-
*
415-
* @return int the error number or 0 (zero) if no error
416-
* occurred
417386
*/
418-
public static function curlErrno($curlHandle): int
387+
public static function curlErrno(CurlHandle $curlHandle): int
419388
{
420389
if (isset(self::$lastErrors[(int) $curlHandle])) {
421390
return self::$lastErrors[(int) $curlHandle]->getCode();

src/VCR/LibraryHooks/SoapHook.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ public function __construct(AbstractCodeTransform $codeTransformer, StreamProces
5454

5555
/**
5656
* @param array<string,mixed> $options
57-
*
58-
* @return string SOAP response
5957
*/
60-
public function doRequest(string $request, string $location, string $action, int $version, int $one_way = 0, array $options = []): string
58+
public function doRequest(string $request, string $location, string $action, int $version, bool $one_way = false, array $options = []): string
6159
{
6260
if (self::DISABLED === $this->status) {
6361
throw new VCRException('Hook must be enabled.', VCRException::LIBRARY_HOOK_DISABLED);

src/VCR/Util/CurlException.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@
22

33
namespace VCR\Util;
44

5+
use CurlHandle;
6+
57
class CurlException extends \Exception
68
{
79
/**
810
* @var array<string,mixed>
911
*/
1012
private $info;
1113

12-
/**
13-
* @param resource $ch The cURL handler
14-
*
15-
* @return CurlException
16-
*/
17-
public static function create($ch): self
14+
public static function create(CurlHandle $ch): self
1815
{
1916
$e = new self(curl_error($ch), curl_errno($ch));
2017
$e->info = curl_getinfo($ch);

src/VCR/Util/CurlHelper.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace VCR\Util;
44

5+
use CurlHandle;
56
use VCR\Request;
67
use VCR\Response;
78

@@ -46,11 +47,9 @@ class CurlHelper
4647
*
4748
* The response header might be passed to a custom function.
4849
*
49-
* @param Response $response response which contains the response body
5050
* @param array<int, mixed> $curlOptions cURL options which are not stored within the Response
51-
* @param resource $ch cURL handle to add headers if needed
5251
*/
53-
public static function handleOutput(Response $response, array $curlOptions, $ch): ?string
52+
public static function handleOutput(Response $response, array $curlOptions, CurlHandle $ch): ?string
5453
{
5554
// If there is a header function set, feed the http status and headers to it.
5655
if (isset($curlOptions[\CURLOPT_HEADERFUNCTION])) {
@@ -129,14 +128,9 @@ public static function getCurlOptionFromResponse(Response $response, int $option
129128
}
130129

131130
/**
132-
* Sets a cURL option on a Request.
133-
*
134-
* @param Request $request request to set cURL option to
135-
* @param int $option cURL option to set
136-
* @param mixed $value value of the cURL option
137-
* @param resource $curlHandle cURL handle where this option is set on (optional)
131+
* @param mixed $value value of the cURL option
138132
*/
139-
public static function setCurlOptionOnRequest(Request $request, int $option, $value, $curlHandle = null): void
133+
public static function setCurlOptionOnRequest(Request $request, int $option, $value): void
140134
{
141135
switch ($option) {
142136
case \CURLOPT_URL:
@@ -194,11 +188,8 @@ public static function setCurlOptionOnRequest(Request $request, int $option, $va
194188
/**
195189
* Makes sure we've properly handled the POST body, such as ensuring that
196190
* CURLOPT_INFILESIZE is set if CURLOPT_READFUNCTION is set.
197-
*
198-
* @param Request $request request to set cURL option to
199-
* @param resource $curlHandle cURL handle associated with the request
200191
*/
201-
public static function validateCurlPOSTBody(Request $request, $curlHandle = null): void
192+
public static function validateCurlPOSTBody(Request $request, CurlHandle $curlHandle = null): void
202193
{
203194
$readFunction = $request->getCurlOption(\CURLOPT_READFUNCTION);
204195
if (null === $readFunction) {
@@ -221,13 +212,12 @@ public static function validateCurlPOSTBody(Request $request, $curlHandle = null
221212
* A wrapper around call_user_func that attempts to properly handle private
222213
* and protected methods on objects.
223214
*
224-
* @param mixed $callback The callable to pass to call_user_func
225-
* @param resource $curlHandle cURL handle associated with the request
226-
* @param mixed $argument The third argument to pass to call_user_func
215+
* @param mixed $callback The callable to pass to call_user_func
216+
* @param mixed $argument The third argument to pass to call_user_func
227217
*
228218
* @return mixed value returned by the callback function
229219
*/
230-
private static function callFunction($callback, $curlHandle, $argument)
220+
private static function callFunction($callback, CurlHandle $curlHandle, $argument)
231221
{
232222
if (!\is_callable($callback) && \is_array($callback) && 2 === \count($callback)) {
233223
// This is probably a private or protected method on an object. Try and

0 commit comments

Comments
 (0)