diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c9d67dc8f..88905eb9c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -45,6 +45,11 @@ parameters: count: 5 path: tests/Unit/CassetteTest.php + - + message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertCount\\(\\) with arguments 22, array\\{url\\: string, content_type\\: string\\|null, http_code\\: int, header_size\\: int, request_size\\: int, filetime\\: int, ssl_verify_result\\: int, redirect_count\\: int, \\.\\.\\.\\} and 'curl_getinfo\\(\\)…' will always evaluate to false\\.$#" + count: 1 + path: tests/Unit/LibraryHooks/CurlHookTest.php + - message: "#^Parameter \\#2 \\$requestMatchers of method VCR\\\\Request\\:\\:matches\\(\\) expects array\\, array\\{array\\{'some', 'method'\\}\\} given\\.$#" count: 1 diff --git a/src/VCR/Configuration.php b/src/VCR/Configuration.php index b6d488cff..d2b0a9a3b 100644 --- a/src/VCR/Configuration.php +++ b/src/VCR/Configuration.php @@ -23,7 +23,7 @@ class Configuration * * A value of null means all hooks are enabled. * - * @see \VCR\LibraryHooks\LibraryHook + * @see LibraryHooks\LibraryHook * * @var string[]|null list of enabled LibraryHook names */ diff --git a/src/VCR/LibraryHooks/CurlHook.php b/src/VCR/LibraryHooks/CurlHook.php index 7edbb20f9..ffb651ad4 100644 --- a/src/VCR/LibraryHooks/CurlHook.php +++ b/src/VCR/LibraryHooks/CurlHook.php @@ -126,7 +126,7 @@ public static function __callStatic($method, array $args) /** * @see http://www.php.net/manual/en/function.curl-init.php */ - public static function curlInit(string $url = null): \CurlHandle|false + public static function curlInit(?string $url = null): \CurlHandle|false { $curlHandle = curl_init($url); if (false !== $curlHandle) { diff --git a/src/VCR/Response.php b/src/VCR/Response.php index 0cfc9b506..51a52deb5 100644 --- a/src/VCR/Response.php +++ b/src/VCR/Response.php @@ -32,7 +32,7 @@ class Response * @param array $headers * @param array $curlInfo */ - final public function __construct($status, array $headers = [], string $body = null, array $curlInfo = []) + final public function __construct($status, array $headers = [], ?string $body = null, array $curlInfo = []) { $this->setStatus($status); $this->headers = $headers; @@ -110,7 +110,7 @@ public function getBody(): string /** * @return array|mixed|null */ - public function getCurlInfo(string $option = null): mixed + public function getCurlInfo(?string $option = null): mixed { if (empty($option)) { return $this->curlInfo; diff --git a/src/VCR/Storage/Yaml.php b/src/VCR/Storage/Yaml.php index 253fbb374..b1a826f81 100644 --- a/src/VCR/Storage/Yaml.php +++ b/src/VCR/Storage/Yaml.php @@ -19,7 +19,7 @@ class Yaml extends AbstractStorage protected Dumper $yamlDumper; - public function __construct(string $cassettePath, string $cassetteName, Parser $parser = null, Dumper $dumper = null) + public function __construct(string $cassettePath, string $cassetteName, ?Parser $parser = null, ?Dumper $dumper = null) { parent::__construct($cassettePath, $cassetteName, ''); diff --git a/src/VCR/Util/Assertion.php b/src/VCR/Util/Assertion.php index 522da3a87..c6e02c9d7 100644 --- a/src/VCR/Util/Assertion.php +++ b/src/VCR/Util/Assertion.php @@ -20,9 +20,9 @@ class Assertion extends BaseAssertion * @param string $message exception message to show if value is not a callable * @param null $propertyPath * - * @throws \VCR\VCRException if specified value is not a callable + * @throws VCRException if specified value is not a callable */ - public static function isCallable($value, $message = null, string $propertyPath = null): bool + public static function isCallable($value, $message = null, ?string $propertyPath = null): bool { if (!\is_callable($value)) { throw new VCRException($message, self::INVALID_CALLABLE, $propertyPath); diff --git a/src/VCR/Util/CurlHelper.php b/src/VCR/Util/CurlHelper.php index 4d772fbf4..677625464 100644 --- a/src/VCR/Util/CurlHelper.php +++ b/src/VCR/Util/CurlHelper.php @@ -186,7 +186,7 @@ public static function setCurlOptionOnRequest(Request $request, int $option, $va * Makes sure we've properly handled the POST body, such as ensuring that * CURLOPT_INFILESIZE is set if CURLOPT_READFUNCTION is set. */ - public static function validateCurlPOSTBody(Request $request, \CurlHandle $curlHandle = null): void + public static function validateCurlPOSTBody(Request $request, ?\CurlHandle $curlHandle = null): void { $readFunction = $request->getCurlOption(\CURLOPT_READFUNCTION); if (null === $readFunction) { diff --git a/src/VCR/Util/StreamHelper.php b/src/VCR/Util/StreamHelper.php index a10c4b351..43f626272 100644 --- a/src/VCR/Util/StreamHelper.php +++ b/src/VCR/Util/StreamHelper.php @@ -19,7 +19,7 @@ class StreamHelper * * @param resource $context stream context resource */ - public static function createRequestFromStreamContext($context, string $path, Request $existing = null): Request + public static function createRequestFromStreamContext($context, string $path, ?Request $existing = null): Request { $http = self::getHttpOptionsFromContext($context); $request = $existing; diff --git a/src/VCR/Util/StreamProcessor.php b/src/VCR/Util/StreamProcessor.php index 1369f4b52..9417346e2 100644 --- a/src/VCR/Util/StreamProcessor.php +++ b/src/VCR/Util/StreamProcessor.php @@ -51,7 +51,7 @@ class StreamProcessor protected bool $isIntercepting = false; - public function __construct(Configuration $configuration = null) + public function __construct(?Configuration $configuration = null) { if ($configuration) { static::$configuration = $configuration; diff --git a/src/VCR/VCRFactory.php b/src/VCR/VCRFactory.php index 21d8e51b7..9fa20f3a5 100644 --- a/src/VCR/VCRFactory.php +++ b/src/VCR/VCRFactory.php @@ -21,7 +21,7 @@ class VCRFactory protected static ?self $instance = null; - protected function __construct(Configuration $config = null) + protected function __construct(?Configuration $config = null) { $this->config = $config ?: $this->getOrCreate('VCR\Configuration'); } @@ -59,7 +59,7 @@ protected function createStorage(string $cassetteName): Storage protected function createVCRLibraryHooksSoapHook(): SoapHook { - return new LibraryHooks\SoapHook( + return new SoapHook( $this->getOrCreate('VCR\CodeTransform\SoapCodeTransform'), $this->getOrCreate('VCR\Util\StreamProcessor') ); @@ -67,13 +67,13 @@ protected function createVCRLibraryHooksSoapHook(): SoapHook protected function createVCRLibraryHooksCurlHook(): CurlHook { - return new LibraryHooks\CurlHook( + return new CurlHook( $this->getOrCreate('VCR\CodeTransform\CurlCodeTransform'), $this->getOrCreate('VCR\Util\StreamProcessor') ); } - public static function getInstance(Configuration $config = null): self + public static function getInstance(?Configuration $config = null): self { if (!self::$instance) { self::$instance = new self($config); diff --git a/src/VCR/Videorecorder.php b/src/VCR/Videorecorder.php index 08bc52da7..83b2c803b 100644 --- a/src/VCR/Videorecorder.php +++ b/src/VCR/Videorecorder.php @@ -63,7 +63,7 @@ public function getEventDispatcher(): EventDispatcherInterface return $this->eventDispatcher; } - private function dispatch(Event $event, string $eventName = null): Event + private function dispatch(Event $event, ?string $eventName = null): Event { $res = $this->getEventDispatcher()->dispatch($event, $eventName); diff --git a/tests/Unit/ConfigurationTest.php b/tests/Unit/ConfigurationTest.php index 8f0405631..b875844a3 100644 --- a/tests/Unit/ConfigurationTest.php +++ b/tests/Unit/ConfigurationTest.php @@ -90,7 +90,7 @@ public function testEnableRequestMatchersFailsWithNoExistingName(): void public function testAddRequestMatcherFailsWithNoName(): void { - $this->expectException(\VCR\VCRException::class); + $this->expectException(VCRException::class); $this->expectExceptionMessage("A request matchers name must be at least one character long. Found ''"); $expected = fn ($first, $second) => true; $this->config->addRequestMatcher('', $expected); @@ -123,7 +123,7 @@ public function availableStorageProvider(): array public function testSetStorageInvalidName(): void { - $this->expectException(\VCR\VCRException::class); + $this->expectException(VCRException::class); $this->expectExceptionMessage("Storage 'Does not exist' not available."); $this->config->setStorage('Does not exist'); } @@ -156,7 +156,7 @@ public function testBlacklist(): void public function testSetModeInvalidName(): void { - $this->expectException(\VCR\VCRException::class); + $this->expectException(VCRException::class); $this->expectExceptionMessage("Mode 'invalid' does not exist."); $this->config->setMode('invalid'); } diff --git a/tests/Unit/Util/StreamProcessorTest.php b/tests/Unit/Util/StreamProcessorTest.php index 54e32c609..e2edf3eee 100644 --- a/tests/Unit/Util/StreamProcessorTest.php +++ b/tests/Unit/Util/StreamProcessorTest.php @@ -30,7 +30,7 @@ public function testFlockWithFilePutContents(): void /** * @dataProvider streamOpenAppendFilterProvider */ - public function testStreamOpenShouldAppendFilters(bool $expected, int $option, bool $shouldProcess = null): void + public function testStreamOpenShouldAppendFilters(bool $expected, int $option, ?bool $shouldProcess = null): void { $mock = $this->getMockBuilder('VCR\Util\StreamProcessor') ->disableOriginalConstructor() diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 623e17619..89d939b42 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -4,5 +4,5 @@ require_once __DIR__.'/../vendor/autoload.php'; -\VCR\VCR::turnOn(); -\VCR\VCR::turnOff(); +VCR\VCR::turnOn(); +VCR\VCR::turnOff();