Skip to content

Commit dcb56bf

Browse files
committed
Pass checkImplicitMixed
1 parent 7de7536 commit dcb56bf

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

phpstan.dist.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ parameters:
1111
analyseAndScan:
1212
- vendor/
1313
checkBenevolentUnionTypes: true
14-
checkImplicitMixed: false # TODO pass
1514
checkMissingOverrideMethodAttribute: true
1615
checkTooWideReturnTypesInProtectedAndPublicMethods: true
1716
reportAnyTypeWideningInVarTag: true
@@ -20,7 +19,6 @@ parameters:
2019
disallowedEmpty: false
2120
disallowedLooseComparison: false
2221
disallowedShortTernary: false
23-
strictArrayFilter: false # TODO pas
2422
exceptions:
2523
check:
2624
missingCheckedExceptionInThrows: true

src/XlsxFastEditor.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ private function getDomFromPath(string $path): \DOMDocument
195195
public function getWorkbookDateSystem(): int
196196
{
197197
static $baseYear = 0;
198-
if ($baseYear == 0) {
198+
if ($baseYear == 0 || !in_array($baseYear, [1900, 1904], true)) {
199199
$xpath = $this->getXPathFromPath(self::WORKBOOK_PATH);
200200
$date1904 = $xpath->evaluate('normalize-space(/o:workbook/o:workbookPr/@date1904)');
201201
if (is_string($date1904) && in_array(strtolower(trim($date1904)), ['true', '1'], true)) {
@@ -228,13 +228,13 @@ public static function excelDateToDateTime(float $excelDateTime, int $workbookDa
228228
$excelDateTime++;
229229
}
230230
// 1 January 1900 as serial number 1 in the 1900 Date System, accounting for leap year problem
231-
if ($baseDate1900 === null) {
231+
if (!($baseDate1900 instanceof \DateTimeImmutable)) {
232232
$baseDate1900 = new \DateTimeImmutable('1899-12-30');
233233
}
234234
$excelBaseDate = $baseDate1900;
235235
} elseif ($workbookDateSystem === 1904) {
236236
// 1 January 1904 as serial number 0 in the 1904 Date System
237-
if ($baseDate1904 === null) {
237+
if (!($baseDate1904 instanceof \DateTimeImmutable)) {
238238
$baseDate1904 = new \DateTimeImmutable('1904-01-01');
239239
}
240240
$excelBaseDate = $baseDate1904;
@@ -438,10 +438,14 @@ public function getRow(int $sheetNumber, int $rowNumber, int $accessMode = XlsxF
438438

439439
// Excel expects the lines to be sorted
440440
$sibling = $sheetData->firstElementChild;
441-
while ($sibling !== null && (int)$sibling->getAttribute('r') < $rowNumber) {
441+
while ($sibling instanceof \DOMElement && (int)$sibling->getAttribute('r') < $rowNumber) {
442442
$sibling = $sibling->nextElementSibling;
443443
}
444-
$sheetData->insertBefore($row, $sibling);
444+
if ($sibling instanceof \DOMElement) {
445+
$sheetData->insertBefore($row, $sibling);
446+
} else {
447+
$sheetData->appendChild($row);
448+
}
445449
break;
446450
default:
447451
case XlsxFastEditor::ACCESS_MODE_NULL:
@@ -1032,6 +1036,9 @@ public function _makeNewSharedString(string $value): int
10321036
throw new XlsxFastEditorXmlException('Error creating <t> in shared strings!');
10331037
}
10341038
$si->appendChild($t);
1039+
if (!($dom->firstElementChild instanceof \DOMElement)) {
1040+
throw new XlsxFastEditorXmlException('Invalid shared strings!');
1041+
}
10351042
$dom->firstElementChild->appendChild($si);
10361043

10371044
$count = (int)$dom->firstElementChild->getAttribute('count');

src/XlsxFastEditorCell.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function column(): string
7878
public function getPreviousCell(): ?XlsxFastEditorCell
7979
{
8080
$c = $this->c->previousElementSibling;
81-
while ($c !== null) {
81+
while ($c instanceof \DOMElement) {
8282
if ($c->localName === 'c') {
8383
return new XlsxFastEditorCell($this->editor, $this->sheetNumber, $c);
8484
}
@@ -94,7 +94,7 @@ public function getPreviousCell(): ?XlsxFastEditorCell
9494
public function getNextCell(): ?XlsxFastEditorCell
9595
{
9696
$c = $this->c->nextElementSibling;
97-
while ($c !== null) {
97+
while ($c instanceof \DOMElement) {
9898
if ($c->localName === 'c') {
9999
return new XlsxFastEditorCell($this->editor, $this->sheetNumber, $c);
100100
}

src/XlsxFastEditorRow.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private function getXPath(): \DOMXPath
5757
public function getPreviousRow(): ?XlsxFastEditorRow
5858
{
5959
$r = $this->r->previousElementSibling;
60-
while ($r !== null) {
60+
while ($r instanceof \DOMElement) {
6161
if ($r->localName === 'row') {
6262
return new XlsxFastEditorRow($this->editor, $this->sheetNumber, $r);
6363
}
@@ -73,7 +73,7 @@ public function getPreviousRow(): ?XlsxFastEditorRow
7373
public function getNextRow(): ?XlsxFastEditorRow
7474
{
7575
$r = $this->r->nextElementSibling;
76-
while ($r !== null) {
76+
while ($r instanceof \DOMElement) {
7777
if ($r->localName === 'row') {
7878
return new XlsxFastEditorRow($this->editor, $this->sheetNumber, $r);
7979
}
@@ -90,7 +90,7 @@ public function getNextRow(): ?XlsxFastEditorRow
9090
public function cellsIterator(): \Traversable
9191
{
9292
$c = $this->r->firstElementChild;
93-
while ($c !== null) {
93+
while ($c instanceof \DOMElement) {
9494
if ($c->localName === 'c') {
9595
yield new XlsxFastEditorCell($this->editor, $this->sheetNumber, $c);
9696
}
@@ -106,7 +106,7 @@ public function cellsIterator(): \Traversable
106106
public function getFirstCell(): ?XlsxFastEditorCell
107107
{
108108
$c = $this->r->firstElementChild;
109-
while ($c !== null) {
109+
while ($c instanceof \DOMElement) {
110110
if ($c->localName === 'c') {
111111
return new XlsxFastEditorCell($this->editor, $this->sheetNumber, $c);
112112
}
@@ -172,10 +172,14 @@ public function getCell(string $cellName, int $accessMode = XlsxFastEditor::ACCE
172172

173173
// Excel expects the cells to be sorted
174174
$sibling = $this->r->firstElementChild;
175-
while ($sibling !== null && XlsxFastEditor::cellOrderCompare($sibling->getAttribute('r'), $cellName) < 0) {
175+
while ($sibling instanceof \DOMElement && XlsxFastEditor::cellOrderCompare($sibling->getAttribute('r'), $cellName) < 0) {
176176
$sibling = $sibling->nextElementSibling;
177177
}
178-
$this->r->insertBefore($c, $sibling);
178+
if ($sibling instanceof \DOMElement) {
179+
$this->r->insertBefore($c, $sibling);
180+
} else {
181+
$this->r->appendChild($c);
182+
}
179183
}
180184

181185
if ($c === null) {
@@ -233,7 +237,7 @@ public function getCellAutocreate(string $cellName): XlsxFastEditorCell
233237
public function getLastCell(): ?XlsxFastEditorCell
234238
{
235239
$c = $this->r->lastElementChild;
236-
while ($c !== null) {
240+
while ($c instanceof \DOMElement) {
237241
if ($c->localName === 'c') {
238242
return new XlsxFastEditorCell($this->editor, $this->sheetNumber, $c);
239243
}

0 commit comments

Comments
 (0)