diff options
author | Andreas Gohr <andi@splitbrain.org> | 2023-08-29 18:14:40 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2023-08-29 18:14:40 +0200 |
commit | bcaec9f47d06126b3e653fea89a86d8b6a6cbef8 (patch) | |
tree | 16cc1b9d4f53736f1dddbd094c4621b34d0dcbbc /inc/Parsing/Handler | |
parent | faf3f01b9af152b16aca96437c109c41b8250689 (diff) | |
download | dokuwiki-bcaec9f47d06126b3e653fea89a86d8b6a6cbef8.tar.gz dokuwiki-bcaec9f47d06126b3e653fea89a86d8b6a6cbef8.zip |
Apply rector fixes to inc/Parsing
Diffstat (limited to 'inc/Parsing/Handler')
-rw-r--r-- | inc/Parsing/Handler/AbstractRewriter.php | 2 | ||||
-rw-r--r-- | inc/Parsing/Handler/Block.php | 44 | ||||
-rw-r--r-- | inc/Parsing/Handler/Lists.php | 78 | ||||
-rw-r--r-- | inc/Parsing/Handler/Nest.php | 8 | ||||
-rw-r--r-- | inc/Parsing/Handler/Preformatted.php | 8 | ||||
-rw-r--r-- | inc/Parsing/Handler/Quote.php | 18 | ||||
-rw-r--r-- | inc/Parsing/Handler/Table.php | 54 |
7 files changed, 102 insertions, 110 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..2c6d4792e 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']; /** @@ -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; } @@ -108,7 +98,7 @@ class Block // remove ending linebreaks in the paragraph $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,7 +108,7 @@ class Block protected function addCall($call) { $key = count($this->calls); - if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) { + if ($key && $call[0] == 'cdata' && $this->calls[$key-1][0] == 'cdata') { $this->calls[$key-1][1][0] .= $call[1][0]; } else { $this->calls[] = $call; @@ -192,7 +182,7 @@ class Block $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/Lists.php b/inc/Parsing/Handler/Lists.php index 282ddfbe8..faea6cfca 100644 --- a/inc/Parsing/Handler/Lists.php +++ b/inc/Parsing/Handler/Lists.php @@ -4,8 +4,8 @@ namespace dokuwiki\Parsing\Handler; class Lists extends AbstractRewriter { - protected $listCalls = array(); - protected $listStack = array(); + protected $listCalls = []; + protected $listStack = []; protected $initialDepth = 0; @@ -15,7 +15,7 @@ class Lists extends AbstractRewriter 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); } diff --git a/inc/Parsing/Handler/Nest.php b/inc/Parsing/Handler/Nest.php index 98d213412..7cd667a5e 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,7 +69,7 @@ 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')) { + 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) diff --git a/inc/Parsing/Handler/Preformatted.php b/inc/Parsing/Handler/Preformatted.php index 41beb662d..bebc842a6 100644 --- a/inc/Parsing/Handler/Preformatted.php +++ b/inc/Parsing/Handler/Preformatted.php @@ -12,7 +12,7 @@ class Preformatted extends AbstractRewriter 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 +35,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..a8148a7f0 100644 --- a/inc/Parsing/Handler/Table.php +++ b/inc/Parsing/Handler/Table.php @@ -5,21 +5,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 +36,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 +58,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 +77,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 +95,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; @@ -124,14 +124,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 +159,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 +168,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,8 +198,8 @@ 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'; @@ -277,11 +280,11 @@ class Table extends AbstractRewriter 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 +293,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; } |