Skip to content

Commit 3ee684c

Browse files
committed
fix: PHPStan errors
1 parent 9f996b3 commit 3ee684c

File tree

3 files changed

+17
-113
lines changed

3 files changed

+17
-113
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"cs": "vendor/bin/php-cs-fixer fix --ansi --verbose --dry-run --diff",
7979
"rector": "vendor/bin/rector process --dry-run",
8080
"phpstan": "bash -c \"XDEBUG_MODE=off phpstan analyse\"",
81+
"phpstan-baseline": "bash -c \"XDEBUG_MODE=off phpstan analyse --generate-baseline phpstan-baseline.php\"",
8182
"test": "vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml --coverage-php build/cov/coverage.cov --testsuite main"
8283
}
8384
}

phpstan-baseline.php

Lines changed: 1 addition & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -7,84 +7,12 @@
77
'count' => 1,
88
'path' => __DIR__ . '/src/Secure.php',
99
];
10-
$ignoreErrors[] = [
11-
// identifier: offsetAccess.nonOffsetAccessible
12-
'message' => '#^Cannot access offset \'blockSize\' on mixed\\.$#',
13-
'count' => 2,
14-
'path' => __DIR__ . '/src/Secure.php',
15-
];
16-
$ignoreErrors[] = [
17-
// identifier: offsetAccess.nonOffsetAccessible
18-
'message' => '#^Cannot access offset \'cipherAlgorithm\' on mixed\\.$#',
19-
'count' => 2,
20-
'path' => __DIR__ . '/src/Secure.php',
21-
];
22-
$ignoreErrors[] = [
23-
// identifier: offsetAccess.nonOffsetAccessible
24-
'message' => '#^Cannot access offset \'cipherChaining\' on mixed\\.$#',
25-
'count' => 2,
26-
'path' => __DIR__ . '/src/Secure.php',
27-
];
28-
$ignoreErrors[] = [
29-
// identifier: offsetAccess.nonOffsetAccessible
30-
'message' => '#^Cannot access offset \'encryptedHmacKey\' on mixed\\.$#',
31-
'count' => 1,
32-
'path' => __DIR__ . '/src/Secure.php',
33-
];
34-
$ignoreErrors[] = [
35-
// identifier: offsetAccess.nonOffsetAccessible
36-
'message' => '#^Cannot access offset \'encryptedHmacValue\' on mixed\\.$#',
37-
'count' => 1,
38-
'path' => __DIR__ . '/src/Secure.php',
39-
];
40-
$ignoreErrors[] = [
41-
// identifier: offsetAccess.nonOffsetAccessible
42-
'message' => '#^Cannot access offset \'encryptedKeyValue\' on mixed\\.$#',
43-
'count' => 1,
44-
'path' => __DIR__ . '/src/Secure.php',
45-
];
46-
$ignoreErrors[] = [
47-
// identifier: offsetAccess.nonOffsetAccessible
48-
'message' => '#^Cannot access offset \'encryptedVerifierHa…\' on mixed\\.$#',
49-
'count' => 2,
50-
'path' => __DIR__ . '/src/Secure.php',
51-
];
52-
$ignoreErrors[] = [
53-
// identifier: offsetAccess.nonOffsetAccessible
54-
'message' => '#^Cannot access offset \'hashAlgorithm\' on mixed\\.$#',
55-
'count' => 2,
56-
'path' => __DIR__ . '/src/Secure.php',
57-
];
58-
$ignoreErrors[] = [
59-
// identifier: offsetAccess.nonOffsetAccessible
60-
'message' => '#^Cannot access offset \'hashSize\' on mixed\\.$#',
61-
'count' => 2,
62-
'path' => __DIR__ . '/src/Secure.php',
63-
];
64-
$ignoreErrors[] = [
65-
// identifier: offsetAccess.nonOffsetAccessible
66-
'message' => '#^Cannot access offset \'keyBits\' on mixed\\.$#',
67-
'count' => 2,
68-
'path' => __DIR__ . '/src/Secure.php',
69-
];
7010
$ignoreErrors[] = [
7111
// identifier: offsetAccess.nonOffsetAccessible
7212
'message' => '#^Cannot access offset \'name\' on mixed\\.$#',
7313
'count' => 3,
7414
'path' => __DIR__ . '/src/Secure.php',
7515
];
76-
$ignoreErrors[] = [
77-
// identifier: offsetAccess.nonOffsetAccessible
78-
'message' => '#^Cannot access offset \'saltValue\' on mixed\\.$#',
79-
'count' => 4,
80-
'path' => __DIR__ . '/src/Secure.php',
81-
];
82-
$ignoreErrors[] = [
83-
// identifier: offsetAccess.nonOffsetAccessible
84-
'message' => '#^Cannot access offset \'spinCount\' on mixed\\.$#',
85-
'count' => 1,
86-
'path' => __DIR__ . '/src/Secure.php',
87-
];
8816
$ignoreErrors[] = [
8917
// identifier: missingType.return
9018
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:_convertPasswordToKey\\(\\) has no return type specified\\.$#',
@@ -289,36 +217,6 @@
289217
'count' => 1,
290218
'path' => __DIR__ . '/src/Secure.php',
291219
];
292-
$ignoreErrors[] = [
293-
// identifier: missingType.return
294-
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:_hmac\\(\\) has no return type specified\\.$#',
295-
'count' => 1,
296-
'path' => __DIR__ . '/src/Secure.php',
297-
];
298-
$ignoreErrors[] = [
299-
// identifier: missingType.parameter
300-
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:_hmac\\(\\) has parameter \\$algorithm with no type specified\\.$#',
301-
'count' => 1,
302-
'path' => __DIR__ . '/src/Secure.php',
303-
];
304-
$ignoreErrors[] = [
305-
// identifier: missingType.parameter
306-
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:_hmac\\(\\) has parameter \\$fileName with no type specified\\.$#',
307-
'count' => 1,
308-
'path' => __DIR__ . '/src/Secure.php',
309-
];
310-
$ignoreErrors[] = [
311-
// identifier: missingType.parameter
312-
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:_hmac\\(\\) has parameter \\$key with no type specified\\.$#',
313-
'count' => 1,
314-
'path' => __DIR__ . '/src/Secure.php',
315-
];
316-
$ignoreErrors[] = [
317-
// identifier: missingType.return
318-
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:build\\(\\) has no return type specified\\.$#',
319-
'count' => 1,
320-
'path' => __DIR__ . '/src/Secure.php',
321-
];
322220
$ignoreErrors[] = [
323221
// identifier: return.type
324222
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:output\\(\\) should return string but returns string\\|false\\.$#',
@@ -331,12 +229,6 @@
331229
'count' => 1,
332230
'path' => __DIR__ . '/src/Secure.php',
333231
];
334-
$ignoreErrors[] = [
335-
// identifier: argument.unpackNonIterable
336-
'message' => '#^Only iterables can be unpacked, mixed given in argument \\#2\\.$#',
337-
'count' => 7,
338-
'path' => __DIR__ . '/src/Secure.php',
339-
];
340232
$ignoreErrors[] = [
341233
// identifier: argument.type
342234
'message' => '#^Parameter \\#1 \\$array of function array_pad expects array, mixed given\\.$#',
@@ -412,7 +304,7 @@
412304
$ignoreErrors[] = [
413305
// identifier: argument.type
414306
'message' => '#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#',
415-
'count' => 5,
307+
'count' => 1,
416308
'path' => __DIR__ . '/src/Secure.php',
417309
];
418310
$ignoreErrors[] = [

src/Secure.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function output(?string $filePath = null)
172172

173173
// Create the data integrity fields used by clients for integrity checks.
174174
// First generate a random array of bytes to use in HMAC. The docs say to use the same length as the key salt, but Excel seems to use 64.
175-
$hmacKey = unpack('C*', random_bytes(64));
175+
$hmacKey = (array) unpack('C*', random_bytes(64));
176176
// Then create an initialization vector using the package encryption info and the appropriate block key.
177177
$hmacKeyIV = $this->_createIV(
178178
$encryptionInfo['package']['hashAlgorithm'],
@@ -321,7 +321,7 @@ public function output(?string $filePath = null)
321321
/**
322322
* Encryption Info
323323
*
324-
* @param array<string, mixed> $encryptionInfo Data
324+
* @param array<string, array<string, array<string, int|string>>> $encryptionInfo Data
325325
*
326326
* @return array<string, mixed>
327327
*/
@@ -445,7 +445,7 @@ private function _hash($algorithm, ...$buffers)
445445
$buffers = [...$buffers];
446446

447447
if (! in_array($algorithm, hash_algos(), true)) {
448-
throw new Exception("Hash algorithm '{$algorithm}' not supported!");
448+
throw new Exception("Hash algorithm '{$algorithm}' not supported!"); // @codeCoverageIgnore
449449
}
450450

451451
$ctx = hash_init($algorithm);
@@ -455,9 +455,18 @@ private function _hash($algorithm, ...$buffers)
455455
return unpack('C*', hash_final($ctx, true));
456456
}
457457

458+
/**
459+
* Hmac
460+
*
461+
* @param string $algorithm Algorithm
462+
* @param list<string> $key Key
463+
* @param string $fileName Filename
464+
*
465+
* @return list<string>
466+
*/
458467
private function _hmac($algorithm, $key, $fileName)
459468
{
460-
return unpack('C*', hash_hmac_file(
469+
return (array) unpack('C*', hash_hmac_file(
461470
strtolower($algorithm),
462471
$fileName,
463472
pack('C*', ...$key),
@@ -582,6 +591,8 @@ private function _cryptPackage(
582591
*
583592
* @param array<string, mixed> $data Data
584593
* @param SimpleXMLElement $rootNode Node
594+
*
595+
* @return void
585596
*/
586597
private function build($data, $rootNode)
587598
{

0 commit comments

Comments
 (0)