aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/inc/Parsing/Handler
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2023-09-02 14:42:51 +0200
committerGitHub <noreply@github.com>2023-09-02 14:42:51 +0200
commit5ff5424d8c81c7123d8656a787af2ff85b3dec21 (patch)
tree322929ee01d892bb3c927e7fe1238369c647f820 /inc/Parsing/Handler
parent0613df3287b82a98b1e97cf86ed9d4c8fbd16f1c (diff)
parent91560755291852b8302767d454183a7662666f7e (diff)
downloaddokuwiki-5ff5424d8c81c7123d8656a787af2ff85b3dec21.tar.gz
dokuwiki-5ff5424d8c81c7123d8656a787af2ff85b3dec21.zip
Merge pull request #4045 from dokuwiki/autofix
Use Rector to autofix code smell
Diffstat (limited to 'inc/Parsing/Handler')
-rw-r--r--inc/Parsing/Handler/AbstractRewriter.php2
-rw-r--r--inc/Parsing/Handler/Block.php70
-rw-r--r--inc/Parsing/Handler/CallWriter.php1
-rw-r--r--inc/Parsing/Handler/Lists.php82
-rw-r--r--inc/Parsing/Handler/Nest.php12
-rw-r--r--inc/Parsing/Handler/Preformatted.php11
-rw-r--r--inc/Parsing/Handler/Quote.php18
-rw-r--r--inc/Parsing/Handler/Table.php87
8 files changed, 137 insertions, 146 deletions
diff --git a/inc/Parsing/Handler/AbstractRewriter.php b/inc/Parsing/Handler/AbstractRewriter.php
index d9becbf4b..674d8c7ae 100644
--- a/inc/Parsing/Handler/AbstractRewriter.php
+++ b/inc/Parsing/Handler/AbstractRewriter.php
@@ -11,7 +11,7 @@ abstract class AbstractRewriter implements ReWriterInterface
protected $callWriter;
/** @var array[] list of calls */
- public $calls = array();
+ public $calls = [];
/** @inheritdoc */
public function __construct(CallWriterInterface $callWriter)
diff --git a/inc/Parsing/Handler/Block.php b/inc/Parsing/Handler/Block.php
index 586810438..db0a470cb 100644
--- a/inc/Parsing/Handler/Block.php
+++ b/inc/Parsing/Handler/Block.php
@@ -9,37 +9,27 @@ namespace dokuwiki\Parsing\Handler;
*/
class Block
{
- protected $calls = array();
+ protected $calls = [];
protected $skipEol = false;
protected $inParagraph = false;
// Blocks these should not be inside paragraphs
- protected $blockOpen = array(
- 'header',
- 'listu_open','listo_open','listitem_open','listcontent_open',
- 'table_open','tablerow_open','tablecell_open','tableheader_open','tablethead_open',
- 'quote_open',
- 'code','file','hr','preformatted','rss',
- 'footnote_open',
- );
+ protected $blockOpen = [
+ 'header', 'listu_open', 'listo_open', 'listitem_open', 'listcontent_open', 'table_open', 'tablerow_open',
+ 'tablecell_open', 'tableheader_open', 'tablethead_open', 'quote_open', 'code', 'file', 'hr', 'preformatted',
+ 'rss', 'footnote_open'
+ ];
- protected $blockClose = array(
- 'header',
- 'listu_close','listo_close','listitem_close','listcontent_close',
- 'table_close','tablerow_close','tablecell_close','tableheader_close','tablethead_close',
- 'quote_close',
- 'code','file','hr','preformatted','rss',
- 'footnote_close',
- );
+ protected $blockClose = [
+ 'header', 'listu_close', 'listo_close', 'listitem_close', 'listcontent_close', 'table_close',
+ 'tablerow_close', 'tablecell_close', 'tableheader_close', 'tablethead_close', 'quote_close', 'code', 'file',
+ 'hr', 'preformatted', 'rss', 'footnote_close'
+ ];
// Stacks can contain paragraphs
- protected $stackOpen = array(
- 'section_open',
- );
+ protected $stackOpen = ['section_open'];
- protected $stackClose = array(
- 'section_close',
- );
+ protected $stackClose = ['section_close'];
/**
@@ -56,11 +46,11 @@ class Block
foreach ($DOKU_PLUGINS['syntax'] as $n => $p) {
$ptype = $p->getPType();
if ($ptype == 'block') {
- $this->blockOpen[] = 'plugin_'.$n;
- $this->blockClose[] = 'plugin_'.$n;
+ $this->blockOpen[] = 'plugin_' . $n;
+ $this->blockClose[] = 'plugin_' . $n;
} elseif ($ptype == 'stack') {
- $this->stackOpen[] = 'plugin_'.$n;
- $this->stackClose[] = 'plugin_'.$n;
+ $this->stackOpen[] = 'plugin_' . $n;
+ $this->stackClose[] = 'plugin_' . $n;
}
}
}
@@ -68,7 +58,7 @@ class Block
protected function openParagraph($pos)
{
if ($this->inParagraph) return;
- $this->calls[] = array('p_open',array(), $pos);
+ $this->calls[] = ['p_open', [], $pos];
$this->inParagraph = true;
$this->skipEol = true;
}
@@ -88,7 +78,7 @@ class Block
// look back if there was any content - we don't want empty paragraphs
$content = '';
$ccount = count($this->calls);
- for ($i=$ccount-1; $i>=0; $i--) {
+ for ($i = $ccount - 1; $i >= 0; $i--) {
if ($this->calls[$i][0] == 'p_open') {
break;
} elseif ($this->calls[$i][0] == 'cdata') {
@@ -99,16 +89,18 @@ class Block
}
}
- if (trim($content)=='') {
+ if (trim($content) == '') {
//remove the whole paragraph
//array_splice($this->calls,$i); // <- this is much slower than the loop below
- for ($x=$ccount; $x>$i;
- $x--) array_pop($this->calls);
+ for (
+ $x = $ccount; $x > $i;
+ $x--
+ ) array_pop($this->calls);
} else {
// remove ending linebreaks in the paragraph
- $i=count($this->calls)-1;
+ $i = count($this->calls) - 1;
if ($this->calls[$i][0] == 'cdata') $this->calls[$i][1][0] = rtrim($this->calls[$i][1][0], "\n");
- $this->calls[] = array('p_close',array(), $pos);
+ $this->calls[] = ['p_close', [], $pos];
}
$this->inParagraph = false;
@@ -118,8 +110,8 @@ class Block
protected function addCall($call)
{
$key = count($this->calls);
- if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) {
- $this->calls[$key-1][1][0] .= $call[1][0];
+ if ($key && $call[0] == 'cdata' && $this->calls[$key - 1][0] == 'cdata') {
+ $this->calls[$key - 1][1][0] .= $call[1][0];
} else {
$this->calls[] = $call;
}
@@ -148,7 +140,7 @@ class Block
foreach ($calls as $key => $call) {
$cname = $call[0];
if ($cname == 'plugin') {
- $cname='plugin_'.$call[1][0];
+ $cname = 'plugin_' . $call[1][0];
$plugin = true;
$plugin_open = (($call[1][2] == DOKU_LEXER_ENTER) || ($call[1][2] == DOKU_LEXER_SPECIAL));
$plugin_close = (($call[1][2] == DOKU_LEXER_EXIT) || ($call[1][2] == DOKU_LEXER_SPECIAL));
@@ -187,12 +179,12 @@ class Block
// Check this isn't an eol instruction to skip...
if (!$this->skipEol) {
// Next is EOL => double eol => mark as paragraph
- if (isset($calls[$key+1]) && $calls[$key+1][0] == 'eol') {
+ if (isset($calls[$key + 1]) && $calls[$key + 1][0] == 'eol') {
$this->closeParagraph($call[2]);
$this->openParagraph($call[2]);
} else {
//if this is just a single eol make a space from it
- $this->addCall(array('cdata',array("\n"), $call[2]));
+ $this->addCall(['cdata', ["\n"], $call[2]]);
}
}
continue;
diff --git a/inc/Parsing/Handler/CallWriter.php b/inc/Parsing/Handler/CallWriter.php
index 2457143ed..28b106d10 100644
--- a/inc/Parsing/Handler/CallWriter.php
+++ b/inc/Parsing/Handler/CallWriter.php
@@ -4,7 +4,6 @@ namespace dokuwiki\Parsing\Handler;
class CallWriter implements CallWriterInterface
{
-
/** @var \Doku_Handler $Handler */
protected $Handler;
diff --git a/inc/Parsing/Handler/Lists.php b/inc/Parsing/Handler/Lists.php
index 282ddfbe8..732e1c0c1 100644
--- a/inc/Parsing/Handler/Lists.php
+++ b/inc/Parsing/Handler/Lists.php
@@ -4,18 +4,18 @@ namespace dokuwiki\Parsing\Handler;
class Lists extends AbstractRewriter
{
- protected $listCalls = array();
- protected $listStack = array();
+ protected $listCalls = [];
+ protected $listStack = [];
protected $initialDepth = 0;
- const NODE = 1;
+ public const NODE = 1;
/** @inheritdoc */
public function finalise()
{
$last_call = end($this->calls);
- $this->writeCall(array('list_close',array(), $last_call[2]));
+ $this->writeCall(['list_close', [], $last_call[2]]);
$this->process();
$this->callWriter->finalise();
@@ -53,11 +53,11 @@ class Lists extends AbstractRewriter
$this->initialDepth = $depth;
// array(list type, current depth, index of current listitem_open)
- $this->listStack[] = array($listType, $depth, 1);
+ $this->listStack[] = [$listType, $depth, 1];
- $this->listCalls[] = array('list'.$listType.'_open',array(),$call[2]);
- $this->listCalls[] = array('listitem_open',array(1),$call[2]);
- $this->listCalls[] = array('listcontent_open',array(),$call[2]);
+ $this->listCalls[] = ['list' . $listType . '_open', [], $call[2]];
+ $this->listCalls[] = ['listitem_open', [1], $call[2]];
+ $this->listCalls[] = ['listcontent_open', [], $call[2]];
}
@@ -67,11 +67,11 @@ class Lists extends AbstractRewriter
while ($list = array_pop($this->listStack)) {
if ($closeContent) {
- $this->listCalls[] = array('listcontent_close',array(),$call[2]);
+ $this->listCalls[] = ['listcontent_close', [], $call[2]];
$closeContent = false;
}
- $this->listCalls[] = array('listitem_close',array(),$call[2]);
- $this->listCalls[] = array('list'.$list[0].'_close', array(), $call[2]);
+ $this->listCalls[] = ['listitem_close', [], $call[2]];
+ $this->listCalls[] = ['list' . $list[0] . '_close', [], $call[2]];
}
}
@@ -89,40 +89,40 @@ class Lists extends AbstractRewriter
if ($depth == $end[1]) {
// Just another item in the list...
if ($listType == $end[0]) {
- $this->listCalls[] = array('listcontent_close',array(),$call[2]);
- $this->listCalls[] = array('listitem_close',array(),$call[2]);
- $this->listCalls[] = array('listitem_open',array($depth-1),$call[2]);
- $this->listCalls[] = array('listcontent_open',array(),$call[2]);
+ $this->listCalls[] = ['listcontent_close', [], $call[2]];
+ $this->listCalls[] = ['listitem_close', [], $call[2]];
+ $this->listCalls[] = ['listitem_open', [$depth - 1], $call[2]];
+ $this->listCalls[] = ['listcontent_open', [], $call[2]];
// new list item, update list stack's index into current listitem_open
$this->listStack[$key][2] = count($this->listCalls) - 2;
// Switched list type...
} else {
- $this->listCalls[] = array('listcontent_close',array(),$call[2]);
- $this->listCalls[] = array('listitem_close',array(),$call[2]);
- $this->listCalls[] = array('list'.$end[0].'_close', array(), $call[2]);
- $this->listCalls[] = array('list'.$listType.'_open', array(), $call[2]);
- $this->listCalls[] = array('listitem_open', array($depth-1), $call[2]);
- $this->listCalls[] = array('listcontent_open',array(),$call[2]);
+ $this->listCalls[] = ['listcontent_close', [], $call[2]];
+ $this->listCalls[] = ['listitem_close', [], $call[2]];
+ $this->listCalls[] = ['list' . $end[0] . '_close', [], $call[2]];
+ $this->listCalls[] = ['list' . $listType . '_open', [], $call[2]];
+ $this->listCalls[] = ['listitem_open', [$depth - 1], $call[2]];
+ $this->listCalls[] = ['listcontent_open', [], $call[2]];
array_pop($this->listStack);
- $this->listStack[] = array($listType, $depth, count($this->listCalls) - 2);
+ $this->listStack[] = [$listType, $depth, count($this->listCalls) - 2];
}
} elseif ($depth > $end[1]) { // Getting deeper...
- $this->listCalls[] = array('listcontent_close',array(),$call[2]);
- $this->listCalls[] = array('list'.$listType.'_open', array(), $call[2]);
- $this->listCalls[] = array('listitem_open', array($depth-1), $call[2]);
- $this->listCalls[] = array('listcontent_open',array(),$call[2]);
+ $this->listCalls[] = ['listcontent_close', [], $call[2]];
+ $this->listCalls[] = ['list' . $listType . '_open', [], $call[2]];
+ $this->listCalls[] = ['listitem_open', [$depth - 1], $call[2]];
+ $this->listCalls[] = ['listcontent_open', [], $call[2]];
// set the node/leaf state of this item's parent listitem_open to NODE
$this->listCalls[$this->listStack[$key][2]][1][1] = self::NODE;
- $this->listStack[] = array($listType, $depth, count($this->listCalls) - 2);
+ $this->listStack[] = [$listType, $depth, count($this->listCalls) - 2];
} else { // Getting shallower ( $depth < $end[1] )
- $this->listCalls[] = array('listcontent_close',array(),$call[2]);
- $this->listCalls[] = array('listitem_close',array(),$call[2]);
- $this->listCalls[] = array('list'.$end[0].'_close',array(),$call[2]);
+ $this->listCalls[] = ['listcontent_close', [], $call[2]];
+ $this->listCalls[] = ['listitem_close', [], $call[2]];
+ $this->listCalls[] = ['list' . $end[0] . '_close', [], $call[2]];
// Throw away the end - done
array_pop($this->listStack);
@@ -135,31 +135,31 @@ class Lists extends AbstractRewriter
// Normalize depths
$depth = $end[1];
- $this->listCalls[] = array('listitem_close',array(),$call[2]);
+ $this->listCalls[] = ['listitem_close', [], $call[2]];
if ($end[0] == $listType) {
- $this->listCalls[] = array('listitem_open',array($depth-1),$call[2]);
- $this->listCalls[] = array('listcontent_open',array(),$call[2]);
+ $this->listCalls[] = ['listitem_open', [$depth - 1], $call[2]];
+ $this->listCalls[] = ['listcontent_open', [], $call[2]];
// new list item, update list stack's index into current listitem_open
$this->listStack[$key][2] = count($this->listCalls) - 2;
} else {
// Switching list type...
- $this->listCalls[] = array('list'.$end[0].'_close', array(), $call[2]);
- $this->listCalls[] = array('list'.$listType.'_open', array(), $call[2]);
- $this->listCalls[] = array('listitem_open', array($depth-1), $call[2]);
- $this->listCalls[] = array('listcontent_open',array(),$call[2]);
+ $this->listCalls[] = ['list' . $end[0] . '_close', [], $call[2]];
+ $this->listCalls[] = ['list' . $listType . '_open', [], $call[2]];
+ $this->listCalls[] = ['listitem_open', [$depth - 1], $call[2]];
+ $this->listCalls[] = ['listcontent_open', [], $call[2]];
array_pop($this->listStack);
- $this->listStack[] = array($listType, $depth, count($this->listCalls) - 2);
+ $this->listStack[] = [$listType, $depth, count($this->listCalls) - 2];
}
break;
// Haven't dropped down far enough yet.... ( $end[1] > $depth )
} else {
- $this->listCalls[] = array('listitem_close',array(),$call[2]);
- $this->listCalls[] = array('list'.$end[0].'_close',array(),$call[2]);
+ $this->listCalls[] = ['listitem_close', [], $call[2]];
+ $this->listCalls[] = ['list' . $end[0] . '_close', [], $call[2]];
array_pop($this->listStack);
}
@@ -172,7 +172,7 @@ class Lists extends AbstractRewriter
$this->listCalls[] = $call;
}
- protected function interpretSyntax($match, & $type)
+ protected function interpretSyntax($match, &$type)
{
if (substr($match, -1) == '*') {
$type = 'u';
diff --git a/inc/Parsing/Handler/Nest.php b/inc/Parsing/Handler/Nest.php
index 98d213412..f4e58e408 100644
--- a/inc/Parsing/Handler/Nest.php
+++ b/inc/Parsing/Handler/Nest.php
@@ -41,7 +41,7 @@ class Nest extends AbstractRewriter
public function finalise()
{
$last_call = end($this->calls);
- $this->writeCall(array($this->closingInstruction,array(), $last_call[2]));
+ $this->writeCall([$this->closingInstruction, [], $last_call[2]]);
$this->process();
$this->callWriter->finalise();
@@ -53,12 +53,12 @@ class Nest extends AbstractRewriter
{
// merge consecutive cdata
$unmerged_calls = $this->calls;
- $this->calls = array();
+ $this->calls = [];
foreach ($unmerged_calls as $call) $this->addCall($call);
$first_call = reset($this->calls);
- $this->callWriter->writeCall(array("nest", array($this->calls), $first_call[2]));
+ $this->callWriter->writeCall(["nest", [$this->calls], $first_call[2]]);
return $this->callWriter;
}
@@ -69,14 +69,12 @@ class Nest extends AbstractRewriter
protected function addCall($call)
{
$key = count($this->calls);
- if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) {
- $this->calls[$key-1][1][0] .= $call[1][0];
+ if ($key && $call[0] == 'cdata' && $this->calls[$key - 1][0] == 'cdata') {
+ $this->calls[$key - 1][1][0] .= $call[1][0];
} elseif ($call[0] == 'eol') {
// do nothing (eol shouldn't be allowed, to counter preformatted fix in #1652 & #1699)
} else {
$this->calls[] = $call;
}
}
-
-
}
diff --git a/inc/Parsing/Handler/Preformatted.php b/inc/Parsing/Handler/Preformatted.php
index 41beb662d..bda7dfa24 100644
--- a/inc/Parsing/Handler/Preformatted.php
+++ b/inc/Parsing/Handler/Preformatted.php
@@ -4,15 +4,14 @@ namespace dokuwiki\Parsing\Handler;
class Preformatted extends AbstractRewriter
{
-
protected $pos;
- protected $text ='';
+ protected $text = '';
/** @inheritdoc */
public function finalise()
{
$last_call = end($this->calls);
- $this->writeCall(array('preformatted_end',array(), $last_call[2]));
+ $this->writeCall(['preformatted_end', [], $last_call[2]]);
$this->process();
$this->callWriter->finalise();
@@ -35,11 +34,11 @@ class Preformatted extends AbstractRewriter
break;
case 'preformatted_end':
if (trim($this->text)) {
- $this->callWriter->writeCall(array('preformatted', array($this->text), $this->pos));
+ $this->callWriter->writeCall(['preformatted', [$this->text], $this->pos]);
}
// see FS#1699 & FS#1652, add 'eol' instructions to ensure proper triggering of following p_open
- $this->callWriter->writeCall(array('eol', array(), $this->pos));
- $this->callWriter->writeCall(array('eol', array(), $this->pos));
+ $this->callWriter->writeCall(['eol', [], $this->pos]);
+ $this->callWriter->writeCall(['eol', [], $this->pos]);
break;
}
}
diff --git a/inc/Parsing/Handler/Quote.php b/inc/Parsing/Handler/Quote.php
index 74861b1b2..caa04cc02 100644
--- a/inc/Parsing/Handler/Quote.php
+++ b/inc/Parsing/Handler/Quote.php
@@ -4,13 +4,13 @@ namespace dokuwiki\Parsing\Handler;
class Quote extends AbstractRewriter
{
- protected $quoteCalls = array();
+ protected $quoteCalls = [];
/** @inheritdoc */
public function finalise()
{
$last_call = end($this->calls);
- $this->writeCall(array('quote_end',array(), $last_call[2]));
+ $this->writeCall(['quote_end', [], $last_call[2]]);
$this->process();
$this->callWriter->finalise();
@@ -28,7 +28,7 @@ class Quote extends AbstractRewriter
/** @noinspection PhpMissingBreakStatementInspection */
case 'quote_start':
- $this->quoteCalls[] = array('quote_open',array(),$call[2]);
+ $this->quoteCalls[] = ['quote_open', [], $call[2]];
// fallthrough
case 'quote_newline':
$quoteLength = $this->getDepth($call[1][0]);
@@ -36,15 +36,15 @@ class Quote extends AbstractRewriter
if ($quoteLength > $quoteDepth) {
$quoteDiff = $quoteLength - $quoteDepth;
for ($i = 1; $i <= $quoteDiff; $i++) {
- $this->quoteCalls[] = array('quote_open',array(),$call[2]);
+ $this->quoteCalls[] = ['quote_open', [], $call[2]];
}
} elseif ($quoteLength < $quoteDepth) {
$quoteDiff = $quoteDepth - $quoteLength;
for ($i = 1; $i <= $quoteDiff; $i++) {
- $this->quoteCalls[] = array('quote_close',array(),$call[2]);
+ $this->quoteCalls[] = ['quote_close', [], $call[2]];
}
- } else {
- if ($call[0] != 'quote_start') $this->quoteCalls[] = array('linebreak',array(),$call[2]);
+ } elseif ($call[0] != 'quote_start') {
+ $this->quoteCalls[] = ['linebreak', [], $call[2]];
}
$quoteDepth = $quoteLength;
@@ -55,11 +55,11 @@ class Quote extends AbstractRewriter
if ($quoteDepth > 1) {
$quoteDiff = $quoteDepth - 1;
for ($i = 1; $i <= $quoteDiff; $i++) {
- $this->quoteCalls[] = array('quote_close',array(),$call[2]);
+ $this->quoteCalls[] = ['quote_close', [], $call[2]];
}
}
- $this->quoteCalls[] = array('quote_close',array(),$call[2]);
+ $this->quoteCalls[] = ['quote_close', [], $call[2]];
$this->callWriter->writeCalls($this->quoteCalls);
break;
diff --git a/inc/Parsing/Handler/Table.php b/inc/Parsing/Handler/Table.php
index 35ff5a832..9305df539 100644
--- a/inc/Parsing/Handler/Table.php
+++ b/inc/Parsing/Handler/Table.php
@@ -4,22 +4,21 @@ namespace dokuwiki\Parsing\Handler;
class Table extends AbstractRewriter
{
-
- protected $tableCalls = array();
+ protected $tableCalls = [];
protected $maxCols = 0;
protected $maxRows = 1;
protected $currentCols = 0;
protected $firstCell = false;
protected $lastCellType = 'tablecell';
protected $inTableHead = true;
- protected $currentRow = array('tableheader' => 0, 'tablecell' => 0);
+ protected $currentRow = ['tableheader' => 0, 'tablecell' => 0];
protected $countTableHeadRows = 0;
/** @inheritdoc */
public function finalise()
{
$last_call = end($this->calls);
- $this->writeCall(array('table_end',array(), $last_call[2]));
+ $this->writeCall(['table_end', [], $last_call[2]]);
$this->process();
$this->callWriter->finalise();
@@ -36,7 +35,7 @@ class Table extends AbstractRewriter
break;
case 'table_row':
$this->tableRowClose($call);
- $this->tableRowOpen(array('tablerow_open',$call[1],$call[2]));
+ $this->tableRowOpen(['tablerow_open', $call[1], $call[2]]);
break;
case 'tableheader':
case 'tablecell':
@@ -58,14 +57,14 @@ class Table extends AbstractRewriter
protected function tableStart($call)
{
- $this->tableCalls[] = array('table_open',$call[1],$call[2]);
- $this->tableCalls[] = array('tablerow_open',array(),$call[2]);
+ $this->tableCalls[] = ['table_open', $call[1], $call[2]];
+ $this->tableCalls[] = ['tablerow_open', [], $call[2]];
$this->firstCell = true;
}
protected function tableEnd($call)
{
- $this->tableCalls[] = array('table_close',$call[1],$call[2]);
+ $this->tableCalls[] = ['table_close', $call[1], $call[2]];
$this->finalizeTable();
}
@@ -77,7 +76,7 @@ class Table extends AbstractRewriter
$this->lastCellType = 'tablecell';
$this->maxRows++;
if ($this->inTableHead) {
- $this->currentRow = array('tablecell' => 0, 'tableheader' => 0);
+ $this->currentRow = ['tablecell' => 0, 'tableheader' => 0];
}
}
@@ -95,7 +94,7 @@ class Table extends AbstractRewriter
$this->currentRow[$discard[0]]--;
}
}
- $this->tableCalls[] = array('tablerow_close', array(), $call[2]);
+ $this->tableCalls[] = ['tablerow_close', [], $call[2]];
if ($this->currentCols > $this->maxCols) {
$this->maxCols = $this->currentCols;
@@ -108,7 +107,7 @@ class Table extends AbstractRewriter
$th = $this->currentRow['tableheader'];
if (!$th || $td > 2) return false;
- if (2*$td > $th) return false;
+ if (2 * $td > $th) return false;
return true;
}
@@ -124,14 +123,14 @@ class Table extends AbstractRewriter
// A cell call which follows an open cell means an empty cell so span
if ($lastCall[0] == 'tablecell_open' || $lastCall[0] == 'tableheader_open') {
- $this->tableCalls[] = array('colspan',array(),$call[2]);
+ $this->tableCalls[] = ['colspan', [], $call[2]];
}
- $this->tableCalls[] = array($this->lastCellType.'_close',array(),$call[2]);
- $this->tableCalls[] = array($call[0].'_open',array(1,null,1),$call[2]);
+ $this->tableCalls[] = [$this->lastCellType . '_close', [], $call[2]];
+ $this->tableCalls[] = [$call[0] . '_open', [1, null, 1], $call[2]];
$this->lastCellType = $call[0];
} else {
- $this->tableCalls[] = array($call[0].'_open',array(1,null,1),$call[2]);
+ $this->tableCalls[] = [$call[0] . '_open', [1, null, 1], $call[2]];
$this->lastCellType = $call[0];
$this->firstCell = false;
}
@@ -159,8 +158,8 @@ class Table extends AbstractRewriter
$lastRow = 0;
$lastCell = 0;
- $cellKey = array();
- $toDelete = array();
+ $cellKey = [];
+ $toDelete = [];
// if still in tableheader, then there can be no table header
// as all rows can't be within <THEAD>
@@ -168,18 +167,21 @@ class Table extends AbstractRewriter
$this->inTableHead = false;
$this->countTableHeadRows = 0;
}
+ // Look for the colspan elements and increment the colspan on the
+ // previous non-empty opening cell. Once done, delete all the cells
+ // that contain colspans
+ $counter = count($this->tableCalls);
// Look for the colspan elements and increment the colspan on the
// previous non-empty opening cell. Once done, delete all the cells
// that contain colspans
- for ($key = 0; $key < count($this->tableCalls); ++$key) {
+ for ($key = 0; $key < $counter; ++$key) {
$call = $this->tableCalls[$key];
switch ($call[0]) {
case 'table_open':
if ($this->countTableHeadRows) {
- array_splice($this->tableCalls, $key+1, 0, array(
- array('tablethead_open', array(), $call[2])));
+ array_splice($this->tableCalls, $key + 1, 0, [['tablethead_open', [], $call[2]]]);
}
break;
@@ -195,15 +197,15 @@ class Table extends AbstractRewriter
break;
case 'table_align':
- $prev = in_array($this->tableCalls[$key-1][0], array('tablecell_open', 'tableheader_open'));
- $next = in_array($this->tableCalls[$key+1][0], array('tablecell_close', 'tableheader_close'));
+ $prev = in_array($this->tableCalls[$key - 1][0], ['tablecell_open', 'tableheader_open']);
+ $next = in_array($this->tableCalls[$key + 1][0], ['tablecell_close', 'tableheader_close']);
// If the cell is empty, align left
if ($prev && $next) {
- $this->tableCalls[$key-1][1][1] = 'left';
+ $this->tableCalls[$key - 1][1][1] = 'left';
// If the previous element was a cell open, align right
} elseif ($prev) {
- $this->tableCalls[$key-1][1][1] = 'right';
+ $this->tableCalls[$key - 1][1][1] = 'right';
// If the next element is the close of an element, align either center or left
} elseif ($next) {
@@ -219,10 +221,11 @@ class Table extends AbstractRewriter
break;
case 'colspan':
- $this->tableCalls[$key-1][1][0] = false;
+ $this->tableCalls[$key - 1][1][0] = false;
- for ($i = $key-2; $i >= $cellKey[$lastRow][1]; $i--) {
- if ($this->tableCalls[$i][0] == 'tablecell_open' ||
+ for ($i = $key - 2; $i >= $cellKey[$lastRow][1]; $i--) {
+ if (
+ $this->tableCalls[$i][0] == 'tablecell_open' ||
$this->tableCalls[$i][0] == 'tableheader_open'
) {
if (false !== $this->tableCalls[$i][1][0]) {
@@ -232,13 +235,13 @@ class Table extends AbstractRewriter
}
}
- $toDelete[] = $key-1;
+ $toDelete[] = $key - 1;
$toDelete[] = $key;
- $toDelete[] = $key+1;
+ $toDelete[] = $key + 1;
break;
case 'rowspan':
- if ($this->tableCalls[$key-1][0] == 'cdata') {
+ if ($this->tableCalls[$key - 1][0] == 'cdata') {
// ignore rowspan if previous call was cdata (text mixed with :::)
// we don't have to check next call as that wont match regex
$this->tableCalls[$key][0] = 'cdata';
@@ -246,9 +249,10 @@ class Table extends AbstractRewriter
$spanning_cell = null;
// can't cross thead/tbody boundary
- if (!$this->countTableHeadRows || ($lastRow-1 != $this->countTableHeadRows)) {
- for ($i = $lastRow-1; $i > 0; $i--) {
- if ($this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tablecell_open' ||
+ if (!$this->countTableHeadRows || ($lastRow - 1 != $this->countTableHeadRows)) {
+ for ($i = $lastRow - 1; $i > 0; $i--) {
+ if (
+ $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tablecell_open' ||
$this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tableheader_open'
) {
if ($this->tableCalls[$cellKey[$i][$lastCell]][1][2] >= $lastRow - $i) {
@@ -267,21 +271,21 @@ class Table extends AbstractRewriter
}
$this->tableCalls[$cellKey[$spanning_cell][$lastCell]][1][2]++;
- $this->tableCalls[$key-1][1][2] = false;
+ $this->tableCalls[$key - 1][1][2] = false;
- $toDelete[] = $key-1;
+ $toDelete[] = $key - 1;
$toDelete[] = $key;
- $toDelete[] = $key+1;
+ $toDelete[] = $key + 1;
}
break;
case 'tablerow_close':
// Fix broken tables by adding missing cells
- $moreCalls = array();
+ $moreCalls = [];
while (++$lastCell < $this->maxCols) {
- $moreCalls[] = array('tablecell_open', array(1, null, 1), $call[2]);
- $moreCalls[] = array('cdata', array(''), $call[2]);
- $moreCalls[] = array('tablecell_close', array(), $call[2]);
+ $moreCalls[] = ['tablecell_open', [1, null, 1], $call[2]];
+ $moreCalls[] = ['cdata', [''], $call[2]];
+ $moreCalls[] = ['tablecell_close', [], $call[2]];
}
$moreCallsLength = count($moreCalls);
if ($moreCallsLength) {
@@ -290,8 +294,7 @@ class Table extends AbstractRewriter
}
if ($this->countTableHeadRows == $lastRow) {
- array_splice($this->tableCalls, $key+1, 0, array(
- array('tablethead_close', array(), $call[2])));
+ array_splice($this->tableCalls, $key + 1, 0, [['tablethead_close', [], $call[2]]]);
}
break;
}