Skip to content

Commit c84b935

Browse files
committed
Refactor substr calls to remove null parameters and improve code clarity
1 parent 02acfa6 commit c84b935

File tree

8 files changed

+17
-14
lines changed

8 files changed

+17
-14
lines changed

.ci-tools/phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9441,7 +9441,7 @@ parameters:
94419441
-
94429442
rawMessage: 'Parameter #2 ...$values of function sprintf expects bool|float|int|string|null, mixed given.'
94439443
identifier: argument.type
9444-
count: 2
9444+
count: 1
94459445
path: ../src/Library/KeyManagement/Analyzer/UsageAnalyzer.php
94469446

94479447
-

.ci-tools/rector.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Rector\PHPUnit\Set\PHPUnitSetList;
99
use Rector\Set\ValueObject\LevelSetList;
1010
use Rector\Set\ValueObject\SetList;
11-
use Rector\Symfony\Symfony73\Rector\Class_\InvokableCommandInputAttributeRector;
1211
use Rector\ValueObject\PhpVersion;
1312

1413
$builder = RectorConfig::configure();
@@ -37,7 +36,6 @@
3736
]
3837
);
3938
$builder->withSkip([
40-
InvokableCommandInputAttributeRector::class,
4139
PreferPHPUnitThisCallRector::class,
4240
__DIR__ . '/../src/Library/Core/JWKSet.php',
4341
__DIR__ . '/../src/Bundle/JoseFramework/DependencyInjection/Source/KeyManagement/JWKSource.php',

src/Library/Console/KeyFileLoaderCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected function configure(): void
2222
{
2323
parent::configure();
2424
$this->addArgument('file', InputArgument::REQUIRED, 'Filename of the key.')
25-
->addOption('secret', 's', InputOption::VALUE_OPTIONAL, 'Secret if the key is encrypted.', null);
25+
->addOption('secret', 's', InputOption::VALUE_OPTIONAL, 'Secret if the key is encrypted.');
2626
}
2727

2828
#[Override]

src/Library/Console/P12CertificateLoaderCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected function configure(): void
2222
{
2323
parent::configure();
2424
$this->addArgument('file', InputArgument::REQUIRED, 'Filename of the P12 certificate.')
25-
->addOption('secret', 's', InputOption::VALUE_OPTIONAL, 'Secret if the key is encrypted.', null);
25+
->addOption('secret', 's', InputOption::VALUE_OPTIONAL, 'Secret if the key is encrypted.');
2626
}
2727

2828
#[Override]

src/Library/Core/Util/ECSignature.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private static function preparePositiveInteger(string $data): string
9797

9898
while (str_starts_with($data, self::ASN1_NEGATIVE_INTEGER)
9999
&& substr($data, 2, self::BYTE_SIZE) <= self::ASN1_BIG_INTEGER_LIMIT) {
100-
$data = substr($data, 2, null);
100+
$data = substr($data, 2);
101101
}
102102

103103
return $data;

src/Library/Encryption/Algorithm/KeyEncryption/Util/RSACrypt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static function decryptWithRSA15(RSAKey $key, string $c): string
9898
throw new InvalidArgumentException('Unable to decrypt');
9999
}
100100
$ps = substr($em, 2, (int) strpos($em, chr(0), 2) - 2);
101-
$m = substr($em, strlen($ps) + 3, null);
101+
$m = substr($em, strlen($ps) + 3);
102102
if (strlen($ps) < 8) {
103103
throw new InvalidArgumentException('Unable to decrypt');
104104
}

src/Library/KeyManagement/Analyzer/UsageAnalyzer.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,18 @@ public function analyze(JWK $jwk, MessageBag $bag): void
2929
if ($jwk->has('key_ops')) {
3030
$key_ops = $jwk->get('key_ops');
3131
if (! is_array($key_ops)) {
32-
$bag->add(
33-
Message::high(
34-
'The parameter "key_ops" must be an array of key operation values.'
35-
)
36-
);
32+
$bag->add(Message::high('The parameter "key_ops" must be an array of key operation values.'));
3733
} else {
38-
$allowedOps = ['sign', 'verify', 'encrypt', 'decrypt', 'wrapKey', 'unwrapKey', 'deriveKey', 'deriveBits'];
34+
$allowedOps = [
35+
'sign',
36+
'verify',
37+
'encrypt',
38+
'decrypt',
39+
'wrapKey',
40+
'unwrapKey',
41+
'deriveKey',
42+
'deriveBits',
43+
];
3944
$unsupportedOps = array_diff($key_ops, $allowedOps);
4045
if ($unsupportedOps !== []) {
4146
$bag->add(

src/Library/Signature/Algorithm/Util/RSA.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private static function verifyEMSAPSS(string $m, string $em, int $emBits, Hash $
182182
if (ord($db[$temp]) !== 1) {
183183
throw new InvalidArgumentException();
184184
}
185-
$salt = substr($db, $temp + 1, null); // should be $sLen long
185+
$salt = substr($db, $temp + 1); // should be $sLen long
186186
$m2 = "\0\0\0\0\0\0\0\0" . $mHash . $salt;
187187
$h2 = $hash->hash($m2);
188188

0 commit comments

Comments
 (0)