Skip to content

Commit adb2c57

Browse files
authored
PHPStan+ECs error fixed (#517)
1 parent 81d17ce commit adb2c57

File tree

6 files changed

+59
-52
lines changed

6 files changed

+59
-52
lines changed

.github/workflows/infection.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow
2+
3+
name: "Integrate"
4+
5+
on:
6+
push:
7+
branches:
8+
- "*.x"
9+
10+
jobs:
11+
mutation_testing:
12+
name: "5️⃣ Mutation Testing"
13+
needs:
14+
- "byte_level"
15+
- "syntax_errors"
16+
runs-on: "ubuntu-latest"
17+
steps:
18+
- name: "Set up PHP"
19+
uses: "shivammathur/setup-php@v2"
20+
with:
21+
php-version: "8.1"
22+
extensions: "json, mbstring, openssl, sqlite3, curl, uuid"
23+
24+
- name: "Checkout code"
25+
uses: "actions/checkout@v4"
26+
27+
- name: "Fetch Git base reference"
28+
run: "git fetch --depth=1 origin ${GITHUB_BASE_REF}"
29+
30+
- name: "Install dependencies"
31+
uses: "ramsey/composer-install@v2"
32+
with:
33+
dependency-versions: "highest"
34+
composer-options: "--optimize-autoloader"
35+
36+
- name: "Execute Infection"
37+
run: "make ci-mu"

.github/workflows/integrate.yml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -145,34 +145,6 @@ jobs:
145145
- name: "Check coding style"
146146
run: "make ci-cs"
147147

148-
mutation_testing:
149-
name: "5️⃣ Mutation Testing"
150-
needs:
151-
- "byte_level"
152-
- "syntax_errors"
153-
runs-on: "ubuntu-latest"
154-
steps:
155-
- name: "Set up PHP"
156-
uses: "shivammathur/setup-php@v2"
157-
with:
158-
php-version: "8.1"
159-
extensions: "json, mbstring, openssl, sqlite3, curl, uuid"
160-
161-
- name: "Checkout code"
162-
uses: "actions/checkout@v4"
163-
164-
- name: "Fetch Git base reference"
165-
run: "git fetch --depth=1 origin ${GITHUB_BASE_REF}"
166-
167-
- name: "Install dependencies"
168-
uses: "ramsey/composer-install@v2"
169-
with:
170-
dependency-versions: "highest"
171-
composer-options: "--optimize-autoloader"
172-
173-
- name: "Execute Infection"
174-
run: "make ci-mu"
175-
176148
rector_checkstyle:
177149
name: "6️⃣ Rector Checkstyle"
178150
needs:

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,11 +1870,6 @@ parameters:
18701870
count: 1
18711871
path: src/Library/KeyManagement/KeyConverter/KeyConverter.php
18721872

1873-
-
1874-
message: "#^Parameter \\#3 \\$subject of function preg_replace expects array\\|string, string\\|null given\\.$#"
1875-
count: 1
1876-
path: src/Library/KeyManagement/KeyConverter/KeyConverter.php
1877-
18781873
-
18791874
message: "#^Method Jose\\\\Component\\\\KeyManagement\\\\KeyConverter\\\\RSAKey\\:\\:__construct\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
18801875
count: 1

src/Library/Encryption/Algorithm/KeyEncryption/AbstractECDH.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ protected function calculateAgreementKey(JWK $private_key, JWK $public_key): str
7474
throw new InvalidArgumentException('Invalid key parameter "crv"');
7575
}
7676
switch ($crv) {
77-
case 'P-256' :
78-
case 'P-384' :
79-
case 'P-521' :
77+
case 'P-256':
78+
case 'P-384':
79+
case 'P-521':
8080
$curve = $this->getCurve($crv);
8181
if (function_exists('openssl_pkey_derive')) {
8282
try {
@@ -115,7 +115,7 @@ protected function calculateAgreementKey(JWK $private_key, JWK $public_key): str
115115

116116
return $this->convertDecToBin(EcDH::computeSharedKey($curve, $pub_key, $priv_key));
117117

118-
case 'X25519' :
118+
case 'X25519':
119119
$this->checkSodiumExtensionIsAvailable();
120120
$x = $public_key->get('x');
121121
if (! is_string($x)) {
@@ -130,7 +130,7 @@ protected function calculateAgreementKey(JWK $private_key, JWK $public_key): str
130130

131131
return sodium_crypto_scalarmult($sKey, $recipientPublickey);
132132

133-
default :
133+
default:
134134
throw new InvalidArgumentException(sprintf('The curve "%s" is not supported', $crv));
135135
}
136136
}
@@ -212,19 +212,19 @@ private function checkKey(JWK $key, bool $is_private): void
212212
throw new InvalidArgumentException('Invalid key parameter "crv"');
213213
}
214214
switch ($crv) {
215-
case 'P-256' :
216-
case 'P-384' :
217-
case 'P-521' :
215+
case 'P-256':
216+
case 'P-384':
217+
case 'P-521':
218218
if (! $key->has('y')) {
219219
throw new InvalidArgumentException('The key parameter "y" is missing.');
220220
}
221221

222222
break;
223223

224-
case 'X25519' :
224+
case 'X25519':
225225
break;
226226

227-
default :
227+
default:
228228
throw new InvalidArgumentException(sprintf('The curve "%s" is not supported', $crv));
229229
}
230230
if ($is_private === true && ! $key->has('d')) {
@@ -279,14 +279,14 @@ private function createOKPKey(string $curve): JWK
279279
$this->checkSodiumExtensionIsAvailable();
280280

281281
switch ($curve) {
282-
case 'X25519' :
282+
case 'X25519':
283283
$keyPair = sodium_crypto_box_keypair();
284284
$d = sodium_crypto_box_secretkey($keyPair);
285285
$x = sodium_crypto_box_publickey($keyPair);
286286

287287
break;
288288

289-
case 'Ed25519' :
289+
case 'Ed25519':
290290
$keyPair = sodium_crypto_sign_keypair();
291291
$secret = sodium_crypto_sign_secretkey($keyPair);
292292
$secretLength = mb_strlen($secret, '8bit');
@@ -295,7 +295,7 @@ private function createOKPKey(string $curve): JWK
295295

296296
break;
297297

298-
default :
298+
default:
299299
throw new InvalidArgumentException(sprintf('Unsupported "%s" curve', $curve));
300300
}
301301

src/Library/Encryption/JWEBuilder.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,11 @@ private function determineCEK(array &$additionalHeader): string
434434
}
435435

436436
switch ($this->keyManagementMode) {
437-
case KeyEncryption::MODE_ENCRYPT :
438-
case KeyEncryption::MODE_WRAP :
437+
case KeyEncryption::MODE_ENCRYPT:
438+
case KeyEncryption::MODE_WRAP:
439439
return $this->createCEK($this->contentEncryptionAlgorithm->getCEKSize());
440440

441-
case KeyEncryption::MODE_AGREEMENT :
441+
case KeyEncryption::MODE_AGREEMENT:
442442
if (count($this->recipients) !== 1) {
443443
throw new LogicException(
444444
'Unable to encrypt for multiple recipients using key agreement algorithms.'
@@ -465,7 +465,7 @@ private function determineCEK(array &$additionalHeader): string
465465
$additionalHeader
466466
);
467467

468-
case KeyEncryption::MODE_DIRECT :
468+
case KeyEncryption::MODE_DIRECT:
469469
if (count($this->recipients) !== 1) {
470470
throw new LogicException(
471471
'Unable to encrypt for multiple recipients using key agreement algorithms.'
@@ -483,7 +483,7 @@ private function determineCEK(array &$additionalHeader): string
483483

484484
return Base64UrlSafe::decodeNoPadding($k);
485485

486-
default :
486+
default:
487487
throw new InvalidArgumentException(sprintf(
488488
'Unsupported key management mode "%s".',
489489
$this->keyManagementMode

tests/Component/Signature/RFC7520/NestingTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public function signatureVerification(): void
5353

5454
static::assertTrue($jwsVerifier->verifyWithKey($loaded_compact_json, $signature_key, 0));
5555
static::assertSame($signature_header, $loaded_compact_json->getSignature(0)->getProtectedHeader());
56-
static::assertSame($payload, json_decode((string) $loaded_compact_json->getPayload(), true, 512, JSON_THROW_ON_ERROR));
56+
static::assertSame(
57+
$payload,
58+
json_decode((string) $loaded_compact_json->getPayload(), true, 512, JSON_THROW_ON_ERROR)
59+
);
5760
}
5861
}

0 commit comments

Comments
 (0)