Skip to content

Commit 60c8678

Browse files
committed
Updates based on scrutinizer results
1 parent 6f9616d commit 60c8678

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

lib/Caxy/HtmlDiff/Table/AbstractTableElement.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ public function getAttribute($name)
6969
return $this->domNode->getAttribute($name);
7070
}
7171

72+
/**
73+
* @param \DOMDocument $domDocument
74+
*
75+
* @return \DOMElement
76+
*/
77+
public function cloneNode(\DOMDocument $domDocument)
78+
{
79+
return $domDocument->importNode($this->getDomNode()->cloneNode(false), false);
80+
}
81+
7282
/**
7383
* @param \DOMElement $node
7484
*

lib/Caxy/HtmlDiff/Table/Table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public function getRow($index)
5959
}
6060

6161
/**
62-
* @param array $rows
63-
* @param null|int $position
62+
* @param TableRow[] $rows
63+
* @param null|int $position
6464
*/
6565
public function insertRows($rows, $position = null)
6666
{

lib/Caxy/HtmlDiff/Table/TableCell.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function setRow(TableRow $row = null)
3030
{
3131
$this->row = $row;
3232

33-
if (!in_array($this, $row->getCells())) {
33+
if (null !== $row && !in_array($this, $row->getCells())) {
3434
$row->addCell($this);
3535
}
3636

@@ -42,14 +42,14 @@ public function setRow(TableRow $row = null)
4242
*/
4343
public function getColspan()
4444
{
45-
return $this->getAttribute('colspan') ?: 1;
45+
return (int)$this->getAttribute('colspan') ?: 1;
4646
}
4747

4848
/**
4949
* @return int
5050
*/
5151
public function getRowspan()
5252
{
53-
return $this->getAttribute('rowspan') ?: 1;
53+
return (int)$this->getAttribute('rowspan') ?: 1;
5454
}
5555
}

lib/Caxy/HtmlDiff/Table/TableDiff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function build()
8787
protected function diffTableContent()
8888
{
8989
$this->diffDom = new \DOMDocument();
90-
$this->diffTable = $this->diffDom->importNode($this->newTable->getDomNode()->cloneNode(false), false);
90+
$this->diffTable = $this->newTable->cloneNode($this->diffDom);
9191
$this->diffDom->appendChild($this->diffTable);
9292

9393
$oldRows = $this->oldTable->getRows();
@@ -426,7 +426,7 @@ protected function diffRows($oldRow, $newRow, array &$appliedRowSpans, $forceExp
426426
$row = $oldRow;
427427
$targetRow = $diffRow;
428428
}
429-
if ($row && (!$type === 'old' || isset($oldCells[$position->getIndexInOld()]))) {
429+
if ($row && $targetRow && (!$type === 'old' || isset($oldCells[$position->getIndexInOld()]))) {
430430
$this->syncVirtualColumns($row, $position, $cellsWithMultipleRows, $targetRow, $type, true);
431431

432432
continue;

lib/Caxy/HtmlDiff/Table/TableRow.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function setTable(Table $table = null)
3535
{
3636
$this->table = $table;
3737

38-
if (!in_array($this, $table->getRows())) {
38+
if ($table && !in_array($this, $table->getRows())) {
3939
$table->addRow($this);
4040
}
4141

@@ -92,8 +92,8 @@ public function getCell($index)
9292
}
9393

9494
/**
95-
* @param array $cells
96-
* @param null|int $position
95+
* @param TableCell[] $cells
96+
* @param null|int $position
9797
*/
9898
public function insertCells($cells, $position = null)
9999
{

0 commit comments

Comments
 (0)