Skip to content

Commit 729c4dc

Browse files
authored
Merge pull request #4421 from oleibman/stan2lv906
Phpstan Level 9 - Part 6 of Many (Shared/OLE)
2 parents 5dee5a7 + 5a486a1 commit 729c4dc

File tree

4 files changed

+16
-80
lines changed

4 files changed

+16
-80
lines changed

Diff for: phpstan-baseline.neon

-72
Original file line numberDiff line numberDiff line change
@@ -533,75 +533,3 @@ parameters:
533533
identifier: return.type
534534
count: 1
535535
path: src/PhpSpreadsheet/Calculation/TextData/Replace.php
536-
537-
-
538-
message: '#^Cannot access an offset on mixed\.$#'
539-
identifier: offsetAccess.nonOffsetAccessible
540-
count: 1
541-
path: src/PhpSpreadsheet/Shared/OLE.php
542-
543-
-
544-
message: '#^Parameter \#1 \$array of function array_keys expects array, mixed given\.$#'
545-
identifier: argument.type
546-
count: 1
547-
path: src/PhpSpreadsheet/Shared/OLE.php
548-
549-
-
550-
message: '#^Cannot access offset array\<mixed\>\|string on mixed\.$#'
551-
identifier: offsetAccess.nonOffsetAccessible
552-
count: 1
553-
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
554-
555-
-
556-
message: '#^Cannot access property \$_file_handle on mixed\.$#'
557-
identifier: property.nonObject
558-
count: 4
559-
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
560-
561-
-
562-
message: '#^Cannot access property \$bbat on mixed\.$#'
563-
identifier: property.nonObject
564-
count: 1
565-
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
566-
567-
-
568-
message: '#^Cannot access property \$bigBlockSize on mixed\.$#'
569-
identifier: property.nonObject
570-
count: 3
571-
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
572-
573-
-
574-
message: '#^Cannot access property \$bigBlockThreshold on mixed\.$#'
575-
identifier: property.nonObject
576-
count: 1
577-
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
578-
579-
-
580-
message: '#^Cannot access property \$root on mixed\.$#'
581-
identifier: property.nonObject
582-
count: 2
583-
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
584-
585-
-
586-
message: '#^Cannot access property \$sbat on mixed\.$#'
587-
identifier: property.nonObject
588-
count: 1
589-
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
590-
591-
-
592-
message: '#^Cannot call method getBlockOffset\(\) on mixed\.$#'
593-
identifier: method.nonObject
594-
count: 2
595-
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
596-
597-
-
598-
message: '#^Property PhpOffice\\PhpSpreadsheet\\Shared\\OLE\\ChainedBlockStream\:\:\$ole \(PhpOffice\\PhpSpreadsheet\\Shared\\OLE\|null\) does not accept mixed\.$#'
599-
identifier: assign.propertyType
600-
count: 1
601-
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
602-
603-
-
604-
message: '#^Cannot clone mixed\.$#'
605-
identifier: clone.nonObject
606-
count: 2
607-
path: src/PhpSpreadsheet/Shared/OLE/PPS.php

Diff for: src/PhpSpreadsheet/Shared/OLE.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class OLE
8383
/**
8484
* Size of big blocks. This is usually 512.
8585
*
86-
* @var int number of octets per block
86+
* @var int<1, max> number of octets per block
8787
*/
8888
public int $bigBlockSize;
8989

@@ -124,7 +124,9 @@ public function read(string $filename): bool
124124
throw new ReaderException('Only Little-Endian encoding is supported.');
125125
}
126126
// Size of blocks and short blocks in bytes
127-
$this->bigBlockSize = 2 ** self::readInt2($fh);
127+
/** @var int<1, max> */
128+
$temp = 2 ** self::readInt2($fh);
129+
$this->bigBlockSize = $temp;
128130
$this->smallBlockSize = 2 ** self::readInt2($fh);
129131

130132
// Skip UID, revision number and version number
@@ -217,8 +219,8 @@ public function getStream($blockIdOrPps)
217219
// Store current instance in global array, so that it can be accessed
218220
// in OLE_ChainedBlockStream::stream_open().
219221
// Object is removed from self::$instances in OLE_Stream::close().
220-
$GLOBALS['_OLE_INSTANCES'][] = $this;
221-
$keys = array_keys($GLOBALS['_OLE_INSTANCES']);
222+
$GLOBALS['_OLE_INSTANCES'][] = $this; //* @phpstan-ignore-line
223+
$keys = array_keys($GLOBALS['_OLE_INSTANCES']); //* @phpstan-ignore-line
222224
$instanceId = end($keys);
223225

224226
$path = 'ole-chainedblockstream://oleInstanceId=' . $instanceId;

Diff for: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PhpOffice\PhpSpreadsheet\Shared\OLE;
44

5+
use PhpOffice\PhpSpreadsheet\Exception;
56
use PhpOffice\PhpSpreadsheet\Shared\OLE;
67

78
class ChainedBlockStream
@@ -55,20 +56,23 @@ public function stream_open(string $path, string $mode, int $options, ?string &$
5556

5657
// 25 is length of "ole-chainedblockstream://"
5758
parse_str(substr($path, 25), $this->params);
58-
if (!isset($this->params['oleInstanceId'], $this->params['blockId'], $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']])) {
59+
if (!isset($this->params['oleInstanceId'], $this->params['blockId'], $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']])) { //* @phpstan-ignore-line
5960
if ($options & STREAM_REPORT_ERRORS) {
6061
trigger_error('OLE stream not found', E_USER_WARNING);
6162
}
6263

6364
return false;
6465
}
65-
$this->ole = $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']];
66+
$this->ole = $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']]; //* @phpstan-ignore-line
67+
if (!($this->ole instanceof OLE)) {
68+
throw new Exception('class is not OLE');
69+
}
6670

6771
$blockId = $this->params['blockId'];
6872
$this->data = '';
6973
if (isset($this->params['size']) && $this->params['size'] < $this->ole->bigBlockThreshold && $blockId != $this->ole->root->startBlock) {
7074
// Block id refers to small blocks
71-
$rootPos = $this->ole->getBlockOffset($this->ole->root->startBlock);
75+
$rootPos = $this->ole->getBlockOffset((int) $this->ole->root->startBlock);
7276
while ($blockId != -2) {
7377
$pos = $rootPos + $blockId * $this->ole->bigBlockSize;
7478
$blockId = $this->ole->sbat[$blockId];

Diff for: src/PhpSpreadsheet/Shared/OLE/PPS.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ public static function savePpsSetPnt(array &$raList, mixed $to_save, int $depth
181181
{
182182
if (!is_array($to_save) || (empty($to_save))) {
183183
return self::ALL_ONE_BITS;
184-
} elseif (count($to_save) == 1) {
184+
}
185+
/** @var self[] $to_save */
186+
if (count($to_save) == 1) {
185187
$cnt = count($raList);
186188
// If the first entry, it's the root... Don't clone it!
187189
$raList[$cnt] = ($depth == 0) ? $to_save[0] : clone $to_save[0];

0 commit comments

Comments
 (0)