Merge pull request #4690 from BackEndTea/fix-phpstan-issues

Fix phpstan issues by making Escher generic
This commit is contained in:
oleibman
2025-10-24 00:14:50 +00:00
committed by GitHub
5 changed files with 39 additions and 26 deletions
-24
View File
@@ -6,30 +6,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/Sort.php
-
message: '#^Cannot call method getAllSpContainers\(\) on mixed\.$#'
identifier: method.nonObject
count: 1
path: src/PhpSpreadsheet/Reader/Xls/LoadSpreadsheet.php
-
message: '#^Cannot call method getBSECollection\(\) on mixed\.$#'
identifier: method.nonObject
count: 1
path: src/PhpSpreadsheet/Reader/Xls/LoadSpreadsheet.php
-
message: '#^Cannot call method getBstoreContainer\(\) on mixed\.$#'
identifier: method.nonObject
count: 1
path: src/PhpSpreadsheet/Reader/Xls/LoadSpreadsheet.php
-
message: '#^Cannot call method getSpgrContainer\(\) on mixed\.$#'
identifier: method.nonObject
count: 1
path: src/PhpSpreadsheet/Reader/Xls/LoadSpreadsheet.php
-
message: '#^Cannot access offset 0 on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
+9
View File
@@ -12,6 +12,9 @@ use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer;
use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE;
use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE\Blip;
/**
* @template T of BSE|BstoreContainer|DgContainer|DggContainer|\PhpOffice\PhpSpreadsheet\Shared\Escher|SpContainer|SpgrContainer
*/
class Escher
{
const DGGCONTAINER = 0xF000;
@@ -50,11 +53,15 @@ class Escher
/**
* The object to be returned by the reader. Modified during load.
*
* @var T
*/
private BSE|BstoreContainer|DgContainer|DggContainer|\PhpOffice\PhpSpreadsheet\Shared\Escher|SpContainer|SpgrContainer $object;
/**
* Create a new Escher instance.
*
* @param T $object
*/
public function __construct(BSE|BstoreContainer|DgContainer|DggContainer|\PhpOffice\PhpSpreadsheet\Shared\Escher|SpContainer|SpgrContainer $object)
{
@@ -84,6 +91,8 @@ class Escher
/**
* Load Escher stream data. May be a partial Escher stream.
*
* @return T
*/
public function load(string $data): BSE|BstoreContainer|DgContainer|DggContainer|\PhpOffice\PhpSpreadsheet\Shared\Escher|SpContainer|SpgrContainer
{
@@ -435,7 +435,7 @@ class LoadSpreadsheet extends Xls
// get all spContainers in one long array, so they can be mapped to OBJ records
/** @var SpContainer[] $allSpContainers */
$allSpContainers = method_exists($escherWorksheet, 'getDgContainer') ? $escherWorksheet->getDgContainer()->getSpgrContainer()->getAllSpContainers() : [];
$allSpContainers = $escherWorksheet->getDgContainerOrThrow()->getSpgrContainerOrThrow()->getAllSpContainers();
}
// treat OBJ records
@@ -497,7 +497,7 @@ class LoadSpreadsheet extends Xls
if ($escherWorkbook) {
/** @var BSE[] */
$BSECollection = method_exists($escherWorkbook, 'getDggContainer') ? $escherWorkbook->getDggContainer()->getBstoreContainer()->getBSECollection() : [];
$BSECollection = $escherWorkbook->getDggContainerOrThrow()->getBstoreContainerOrThrow()->getBSECollection();
$BSE = $BSECollection[$BSEindex - 1];
$blipType = $BSE->getBlipType();
+18
View File
@@ -2,6 +2,8 @@
namespace PhpOffice\PhpSpreadsheet\Shared;
use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException;
class Escher
{
/**
@@ -22,6 +24,14 @@ class Escher
return $this->dggContainer;
}
/**
* Get Drawing Group Container.
*/
public function getDggContainerOrThrow(): Escher\DggContainer
{
return $this->dggContainer ?? throw new SpreadsheetException('dggContainer is unexpectedly null');
}
/**
* Set Drawing Group Container.
*/
@@ -38,6 +48,14 @@ class Escher
return $this->dgContainer;
}
/**
* Get Drawing Container.
*/
public function getDgContainerOrThrow(): Escher\DgContainer
{
return $this->dgContainer ?? throw new SpreadsheetException('dgContainer is unexpectedly null');
}
/**
* Set Drawing Container.
*/
@@ -2,6 +2,8 @@
namespace PhpOffice\PhpSpreadsheet\Shared\Escher;
use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException;
class DggContainer
{
/**
@@ -94,6 +96,14 @@ class DggContainer
return $this->bstoreContainer;
}
/**
* Get BLIP Store Container.
*/
public function getBstoreContainerOrThrow(): DggContainer\BstoreContainer
{
return $this->bstoreContainer ?? throw new SpreadsheetException('bstoreContainer is unexpectedly null');
}
/**
* Set BLIP Store Container.
*/