Skip to content

Commit

Permalink
Merge pull request #407 from php-vcr/406-fix-pipeline-phpstan-phpcsfixer
Browse files Browse the repository at this point in the history
Fix pipeline (phpstan & phpcsfixer)
  • Loading branch information
higidi committed Feb 23, 2024
2 parents dd3a797 + 00d9e45 commit eb21dc6
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 21 deletions.
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Expand Up @@ -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\\<callable\\(\\)\\: mixed\\>, array\\{array\\{'some', 'method'\\}\\} given\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion src/VCR/Configuration.php
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/VCR/LibraryHooks/CurlHook.php
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/VCR/Response.php
Expand Up @@ -32,7 +32,7 @@ class Response
* @param array<string,string> $headers
* @param array<string,mixed> $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;
Expand Down Expand Up @@ -110,7 +110,7 @@ public function getBody(): string
/**
* @return array<string,mixed>|mixed|null
*/
public function getCurlInfo(string $option = null): mixed
public function getCurlInfo(?string $option = null): mixed
{
if (empty($option)) {
return $this->curlInfo;
Expand Down
2 changes: 1 addition & 1 deletion src/VCR/Storage/Yaml.php
Expand Up @@ -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, '');

Expand Down
4 changes: 2 additions & 2 deletions src/VCR/Util/Assertion.php
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/VCR/Util/CurlHelper.php
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/VCR/Util/StreamHelper.php
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/VCR/Util/StreamProcessor.php
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/VCR/VCRFactory.php
Expand Up @@ -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');
}
Expand Down Expand Up @@ -59,21 +59,21 @@ 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')
);
}

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);
Expand Down
2 changes: 1 addition & 1 deletion src/VCR/Videorecorder.php
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/ConfigurationTest.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Util/StreamProcessorTest.php
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/bootstrap.php
Expand Up @@ -4,5 +4,5 @@

require_once __DIR__.'/../vendor/autoload.php';

\VCR\VCR::turnOn();
\VCR\VCR::turnOff();
VCR\VCR::turnOn();
VCR\VCR::turnOff();

0 comments on commit eb21dc6

Please sign in to comment.