Skip to content

Commit 10ade11

Browse files
authored
Rector 8.1 rule (#485)
1 parent a04e246 commit 10ade11

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+103
-142
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"squizlabs/php_codesniffer": "^3.5",
3232
"softcreatr/jsonpath": "^0.7 || ^0.8",
3333
"phpspec/prophecy-phpunit": "^2.0",
34-
"rector/rector": "^0.14.8",
34+
"rector/rector": "^1.1",
3535
"phpstan/phpstan": "^1.10"
3636
},
3737
"config": {

rector.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Core\ValueObject\PhpVersion;
7+
use Rector\Set\ValueObject\SetList;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
// Define the paths to refactor
11+
$rectorConfig->paths([
12+
__DIR__ . '/src',
13+
__DIR__ . '/test',
14+
]);
15+
16+
// Set the target PHP version to 8.1
17+
$rectorConfig->sets([
18+
\Rector\Set\ValueObject\LevelSetList::UP_TO_PHP_81
19+
]);
20+
21+
// Define sets of rules
22+
$rectorConfig->sets([
23+
SetList::PHP_81,
24+
]);
25+
};

src/Account/Network.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function fromArray(array $data): void
7373
$storage = [];
7474

7575
foreach ($data as $k => $v) {
76-
$k = strtolower(ltrim(preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '_$0', $k), '_'));
76+
$k = strtolower(ltrim((string) preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '_$0', $k), '_'));
7777
$storage[$k] = $v;
7878
}
7979

src/Account/Price.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function fromArray(array $data): void
8989
$storage = [];
9090

9191
foreach ($data as $k => $v) {
92-
$k = strtolower(ltrim(preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '_$0', $k), '_'));
92+
$k = strtolower(ltrim((string) preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '_$0', $k), '_'));
9393

9494
// PrefixPrice fixes
9595
switch ($k) {

src/Application/Webhook.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function getUrl(): ?string
2929

3030
public function __toString(): string
3131
{
32-
return $this->getUrl();
32+
return (string) $this->getUrl();
3333
}
3434

3535
public function getSocketTimeout(): ?string

src/Client.php

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function __construct(
157157
if (is_null($client)) {
158158
// Since the user did not pass a client, try and make a client
159159
// using the Guzzle 6 adapter or Guzzle 7 (depending on availability)
160-
list($guzzleVersion) = explode('@', InstalledVersions::getVersion('guzzlehttp/guzzle'), 1);
160+
[$guzzleVersion] = explode('@', (string) InstalledVersions::getVersion('guzzlehttp/guzzle'), 1);
161161
$guzzleVersion = (float) $guzzleVersion;
162162

163163
if ($guzzleVersion >= 6.0 && $guzzleVersion < 7) {
@@ -235,15 +235,13 @@ public function __construct(
235235

236236
// Additional utility classes
237237
APIResource::class => APIResource::class,
238-
Client::class => function () {
239-
return $this;
240-
}
238+
Client::class => fn() => $this
241239
];
242240

243241
if (class_exists('Vonage\Video\ClientFactory')) {
244242
$services['video'] = 'Vonage\Video\ClientFactory';
245243
} else {
246-
$services['video'] = function () {
244+
$services['video'] = function (): never {
247245
throw new \RuntimeException('Please install @vonage/video to use the Video API');
248246
};
249247
}
@@ -258,15 +256,7 @@ public function __construct(
258256
// Disable throwing E_USER_DEPRECATED notices by default, the user can turn it on during development
259257
if (array_key_exists('show_deprecations', $this->options) && ($this->options['show_deprecations'] == true)) {
260258
set_error_handler(
261-
static function (
262-
int $errno,
263-
string $errstr,
264-
string $errfile = null,
265-
int $errline = null,
266-
array $errorcontext = null
267-
) {
268-
return true;
269-
},
259+
static fn(int $errno, string $errstr, string $errfile = null, int $errline = null, array $errorcontext = null) => true,
270260
E_USER_DEPRECATED
271261
);
272262
}
@@ -539,7 +529,7 @@ protected function validateAppOptions($app): void
539529
}
540530

541531
foreach ($disallowedCharacters as $char) {
542-
if (strpos($app[$key], $char) !== false) {
532+
if (str_contains((string) $app[$key], $char)) {
543533
throw new InvalidArgumentException('app.' . $key . ' cannot contain the ' . $char . ' character');
544534
}
545535
}
@@ -611,8 +601,8 @@ public function getCredentials(): CredentialsInterface
611601
protected static function requiresBasicAuth(RequestInterface $request): bool
612602
{
613603
$path = $request->getUri()->getPath();
614-
$isSecretManagementEndpoint = strpos($path, '/accounts') === 0 && strpos($path, '/secrets') !== false;
615-
$isApplicationV2 = strpos($path, '/v2/applications') === 0;
604+
$isSecretManagementEndpoint = str_starts_with($path, '/accounts') && str_contains($path, '/secrets');
605+
$isApplicationV2 = str_starts_with($path, '/v2/applications');
616606

617607
return $isSecretManagementEndpoint || $isApplicationV2;
618608
}
@@ -625,8 +615,8 @@ protected static function requiresAuthInUrlNotBody(RequestInterface $request): b
625615
{
626616
$path = $request->getUri()->getPath();
627617

628-
$isRedact = strpos($path, '/v1/redact') === 0;
629-
$isMessages = strpos($path, '/v1/messages') === 0;
618+
$isRedact = str_starts_with($path, '/v1/redact');
619+
$isMessages = str_starts_with($path, '/v1/messages');
630620

631621
return $isRedact || $isMessages;
632622
}
@@ -638,10 +628,10 @@ protected static function requiresAuthInUrlNotBody(RequestInterface $request): b
638628
protected function needsKeypairAuthentication(RequestInterface $request): bool
639629
{
640630
$path = $request->getUri()->getPath();
641-
$isCallEndpoint = strpos($path, '/v1/calls') === 0;
642-
$isRecordingUrl = strpos($path, '/v1/files') === 0;
643-
$isStitchEndpoint = strpos($path, '/beta/conversation') === 0;
644-
$isUserEndpoint = strpos($path, '/beta/users') === 0;
631+
$isCallEndpoint = str_starts_with($path, '/v1/calls');
632+
$isRecordingUrl = str_starts_with($path, '/v1/files');
633+
$isStitchEndpoint = str_starts_with($path, '/beta/conversation');
634+
$isUserEndpoint = str_starts_with($path, '/beta/users');
645635

646636
return $isCallEndpoint || $isRecordingUrl || $isStitchEndpoint || $isUserEndpoint;
647637
}

src/Client/APIResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function addAuth(RequestInterface $request): RequestInterface
7474
try {
7575
$request = $handler($request, $credentials);
7676
break;
77-
} catch (\RuntimeException $e) {
77+
} catch (\RuntimeException) {
7878
continue; // We are OK if multiple are sent but only one match
7979
// This has a really nasty side effect for complex handlers where we never see the error
8080
}

src/Client/Exception/Validation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class Validation extends Request
1010
{
11-
public function __construct(string $message = '', int $code = 0, Throwable $previous = null, private array $errors = [])
11+
public function __construct(string $message = '', int $code = 0, Throwable $previous = null, private readonly array $errors = [])
1212
{
1313
parent::__construct($message, $code, $previous);
1414
}

src/Client/Signature.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected function sign($signatureMethod, $data, $secret): string
8181
case 'sha1':
8282
case 'sha256':
8383
case 'sha512':
84-
return strtoupper(hash_hmac($signatureMethod, $data, $secret));
84+
return strtoupper(hash_hmac((string) $signatureMethod, (string) $data, (string) $secret));
8585
default:
8686
throw new ClientException(
8787
'Unknown signature algorithm: ' . $signatureMethod .
@@ -135,7 +135,7 @@ public function check($signature): bool
135135
throw new InvalidArgumentException('signature must be string, or present in array or parameters');
136136
}
137137

138-
return strtolower($signature) === strtolower($this->signed['sig']);
138+
return strtolower($signature) === strtolower((string) $this->signed['sig']);
139139
}
140140

141141
/**

src/Conversation/ConversationObjects/ConversationCallback.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class ConversationCallback implements ArrayHydrateInterface
1010
{
1111
protected string $method = 'POST';
12-
protected ?array $params;
12+
protected ?array $params = null;
1313

1414
public function __construct(
1515
protected ?string $url = null,

0 commit comments

Comments
 (0)