Skip to content

Commit

Permalink
Pass checkImplicitMixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkarex committed Jan 13, 2025
1 parent 7de7536 commit dcb56bf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
2 changes: 0 additions & 2 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ parameters:
analyseAndScan:
- vendor/
checkBenevolentUnionTypes: true
checkImplicitMixed: false # TODO pass
checkMissingOverrideMethodAttribute: true
checkTooWideReturnTypesInProtectedAndPublicMethods: true
reportAnyTypeWideningInVarTag: true
Expand All @@ -20,7 +19,6 @@ parameters:
disallowedEmpty: false
disallowedLooseComparison: false
disallowedShortTernary: false
strictArrayFilter: false # TODO pas
exceptions:
check:
missingCheckedExceptionInThrows: true
Expand Down
17 changes: 12 additions & 5 deletions src/XlsxFastEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private function getDomFromPath(string $path): \DOMDocument
public function getWorkbookDateSystem(): int
{
static $baseYear = 0;
if ($baseYear == 0) {
if ($baseYear == 0 || !in_array($baseYear, [1900, 1904], true)) {
$xpath = $this->getXPathFromPath(self::WORKBOOK_PATH);
$date1904 = $xpath->evaluate('normalize-space(/o:workbook/o:workbookPr/@date1904)');
if (is_string($date1904) && in_array(strtolower(trim($date1904)), ['true', '1'], true)) {
Expand Down Expand Up @@ -228,13 +228,13 @@ public static function excelDateToDateTime(float $excelDateTime, int $workbookDa
$excelDateTime++;
}
// 1 January 1900 as serial number 1 in the 1900 Date System, accounting for leap year problem
if ($baseDate1900 === null) {
if (!($baseDate1900 instanceof \DateTimeImmutable)) {
$baseDate1900 = new \DateTimeImmutable('1899-12-30');
}
$excelBaseDate = $baseDate1900;
} elseif ($workbookDateSystem === 1904) {
// 1 January 1904 as serial number 0 in the 1904 Date System
if ($baseDate1904 === null) {
if (!($baseDate1904 instanceof \DateTimeImmutable)) {
$baseDate1904 = new \DateTimeImmutable('1904-01-01');
}
$excelBaseDate = $baseDate1904;
Expand Down Expand Up @@ -438,10 +438,14 @@ public function getRow(int $sheetNumber, int $rowNumber, int $accessMode = XlsxF

// Excel expects the lines to be sorted
$sibling = $sheetData->firstElementChild;
while ($sibling !== null && (int)$sibling->getAttribute('r') < $rowNumber) {
while ($sibling instanceof \DOMElement && (int)$sibling->getAttribute('r') < $rowNumber) {
$sibling = $sibling->nextElementSibling;
}
$sheetData->insertBefore($row, $sibling);
if ($sibling instanceof \DOMElement) {
$sheetData->insertBefore($row, $sibling);
} else {
$sheetData->appendChild($row);
}
break;
default:
case XlsxFastEditor::ACCESS_MODE_NULL:
Expand Down Expand Up @@ -1032,6 +1036,9 @@ public function _makeNewSharedString(string $value): int
throw new XlsxFastEditorXmlException('Error creating <t> in shared strings!');
}
$si->appendChild($t);
if (!($dom->firstElementChild instanceof \DOMElement)) {
throw new XlsxFastEditorXmlException('Invalid shared strings!');
}
$dom->firstElementChild->appendChild($si);

$count = (int)$dom->firstElementChild->getAttribute('count');
Expand Down
4 changes: 2 additions & 2 deletions src/XlsxFastEditorCell.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function column(): string
public function getPreviousCell(): ?XlsxFastEditorCell
{
$c = $this->c->previousElementSibling;
while ($c !== null) {
while ($c instanceof \DOMElement) {
if ($c->localName === 'c') {
return new XlsxFastEditorCell($this->editor, $this->sheetNumber, $c);
}
Expand All @@ -94,7 +94,7 @@ public function getPreviousCell(): ?XlsxFastEditorCell
public function getNextCell(): ?XlsxFastEditorCell
{
$c = $this->c->nextElementSibling;
while ($c !== null) {
while ($c instanceof \DOMElement) {
if ($c->localName === 'c') {
return new XlsxFastEditorCell($this->editor, $this->sheetNumber, $c);
}
Expand Down
18 changes: 11 additions & 7 deletions src/XlsxFastEditorRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private function getXPath(): \DOMXPath
public function getPreviousRow(): ?XlsxFastEditorRow
{
$r = $this->r->previousElementSibling;
while ($r !== null) {
while ($r instanceof \DOMElement) {
if ($r->localName === 'row') {
return new XlsxFastEditorRow($this->editor, $this->sheetNumber, $r);
}
Expand All @@ -73,7 +73,7 @@ public function getPreviousRow(): ?XlsxFastEditorRow
public function getNextRow(): ?XlsxFastEditorRow
{
$r = $this->r->nextElementSibling;
while ($r !== null) {
while ($r instanceof \DOMElement) {
if ($r->localName === 'row') {
return new XlsxFastEditorRow($this->editor, $this->sheetNumber, $r);
}
Expand All @@ -90,7 +90,7 @@ public function getNextRow(): ?XlsxFastEditorRow
public function cellsIterator(): \Traversable
{
$c = $this->r->firstElementChild;
while ($c !== null) {
while ($c instanceof \DOMElement) {
if ($c->localName === 'c') {
yield new XlsxFastEditorCell($this->editor, $this->sheetNumber, $c);
}
Expand All @@ -106,7 +106,7 @@ public function cellsIterator(): \Traversable
public function getFirstCell(): ?XlsxFastEditorCell
{
$c = $this->r->firstElementChild;
while ($c !== null) {
while ($c instanceof \DOMElement) {
if ($c->localName === 'c') {
return new XlsxFastEditorCell($this->editor, $this->sheetNumber, $c);
}
Expand Down Expand Up @@ -172,10 +172,14 @@ public function getCell(string $cellName, int $accessMode = XlsxFastEditor::ACCE

// Excel expects the cells to be sorted
$sibling = $this->r->firstElementChild;
while ($sibling !== null && XlsxFastEditor::cellOrderCompare($sibling->getAttribute('r'), $cellName) < 0) {
while ($sibling instanceof \DOMElement && XlsxFastEditor::cellOrderCompare($sibling->getAttribute('r'), $cellName) < 0) {
$sibling = $sibling->nextElementSibling;
}
$this->r->insertBefore($c, $sibling);
if ($sibling instanceof \DOMElement) {
$this->r->insertBefore($c, $sibling);
} else {
$this->r->appendChild($c);
}
}

if ($c === null) {
Expand Down Expand Up @@ -233,7 +237,7 @@ public function getCellAutocreate(string $cellName): XlsxFastEditorCell
public function getLastCell(): ?XlsxFastEditorCell
{
$c = $this->r->lastElementChild;
while ($c !== null) {
while ($c instanceof \DOMElement) {
if ($c->localName === 'c') {
return new XlsxFastEditorCell($this->editor, $this->sheetNumber, $c);
}
Expand Down

0 comments on commit dcb56bf

Please sign in to comment.