Merge pull request #4421 from oleibman/stan2lv906

Phpstan Level 9 - Part 6 of Many (Shared/OLE)
This commit is contained in:
oleibman
2025-03-28 05:43:33 +00:00
committed by GitHub
4 changed files with 16 additions and 80 deletions
-72
View File
@@ -533,75 +533,3 @@ parameters:
identifier: return.type
count: 1
path: src/PhpSpreadsheet/Calculation/TextData/Replace.php
-
message: '#^Cannot access an offset on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/PhpSpreadsheet/Shared/OLE.php
-
message: '#^Parameter \#1 \$array of function array_keys expects array, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Shared/OLE.php
-
message: '#^Cannot access offset array\<mixed\>\|string on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
-
message: '#^Cannot access property \$_file_handle on mixed\.$#'
identifier: property.nonObject
count: 4
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
-
message: '#^Cannot access property \$bbat on mixed\.$#'
identifier: property.nonObject
count: 1
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
-
message: '#^Cannot access property \$bigBlockSize on mixed\.$#'
identifier: property.nonObject
count: 3
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
-
message: '#^Cannot access property \$bigBlockThreshold on mixed\.$#'
identifier: property.nonObject
count: 1
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
-
message: '#^Cannot access property \$root on mixed\.$#'
identifier: property.nonObject
count: 2
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
-
message: '#^Cannot access property \$sbat on mixed\.$#'
identifier: property.nonObject
count: 1
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
-
message: '#^Cannot call method getBlockOffset\(\) on mixed\.$#'
identifier: method.nonObject
count: 2
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
-
message: '#^Property PhpOffice\\PhpSpreadsheet\\Shared\\OLE\\ChainedBlockStream\:\:\$ole \(PhpOffice\\PhpSpreadsheet\\Shared\\OLE\|null\) does not accept mixed\.$#'
identifier: assign.propertyType
count: 1
path: src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php
-
message: '#^Cannot clone mixed\.$#'
identifier: clone.nonObject
count: 2
path: src/PhpSpreadsheet/Shared/OLE/PPS.php
+6 -4
View File
@@ -83,7 +83,7 @@ class OLE
/**
* Size of big blocks. This is usually 512.
*
* @var int number of octets per block
* @var int<1, max> number of octets per block
*/
public int $bigBlockSize;
@@ -124,7 +124,9 @@ class OLE
throw new ReaderException('Only Little-Endian encoding is supported.');
}
// Size of blocks and short blocks in bytes
$this->bigBlockSize = 2 ** self::readInt2($fh);
/** @var int<1, max> */
$temp = 2 ** self::readInt2($fh);
$this->bigBlockSize = $temp;
$this->smallBlockSize = 2 ** self::readInt2($fh);
// Skip UID, revision number and version number
@@ -217,8 +219,8 @@ class OLE
// Store current instance in global array, so that it can be accessed
// in OLE_ChainedBlockStream::stream_open().
// Object is removed from self::$instances in OLE_Stream::close().
$GLOBALS['_OLE_INSTANCES'][] = $this;
$keys = array_keys($GLOBALS['_OLE_INSTANCES']);
$GLOBALS['_OLE_INSTANCES'][] = $this; //* @phpstan-ignore-line
$keys = array_keys($GLOBALS['_OLE_INSTANCES']); //* @phpstan-ignore-line
$instanceId = end($keys);
$path = 'ole-chainedblockstream://oleInstanceId=' . $instanceId;
@@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Shared\OLE;
use PhpOffice\PhpSpreadsheet\Exception;
use PhpOffice\PhpSpreadsheet\Shared\OLE;
class ChainedBlockStream
@@ -55,20 +56,23 @@ class ChainedBlockStream
// 25 is length of "ole-chainedblockstream://"
parse_str(substr($path, 25), $this->params);
if (!isset($this->params['oleInstanceId'], $this->params['blockId'], $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']])) {
if (!isset($this->params['oleInstanceId'], $this->params['blockId'], $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']])) { //* @phpstan-ignore-line
if ($options & STREAM_REPORT_ERRORS) {
trigger_error('OLE stream not found', E_USER_WARNING);
}
return false;
}
$this->ole = $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']];
$this->ole = $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']]; //* @phpstan-ignore-line
if (!($this->ole instanceof OLE)) {
throw new Exception('class is not OLE');
}
$blockId = $this->params['blockId'];
$this->data = '';
if (isset($this->params['size']) && $this->params['size'] < $this->ole->bigBlockThreshold && $blockId != $this->ole->root->startBlock) {
// Block id refers to small blocks
$rootPos = $this->ole->getBlockOffset($this->ole->root->startBlock);
$rootPos = $this->ole->getBlockOffset((int) $this->ole->root->startBlock);
while ($blockId != -2) {
$pos = $rootPos + $blockId * $this->ole->bigBlockSize;
$blockId = $this->ole->sbat[$blockId];
+3 -1
View File
@@ -181,7 +181,9 @@ class PPS
{
if (!is_array($to_save) || (empty($to_save))) {
return self::ALL_ONE_BITS;
} elseif (count($to_save) == 1) {
}
/** @var self[] $to_save */
if (count($to_save) == 1) {
$cnt = count($raList);
// If the first entry, it's the root... Don't clone it!
$raList[$cnt] = ($depth == 0) ? $to_save[0] : clone $to_save[0];