aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2023-08-29 18:14:40 +0200
committerAndreas Gohr <andi@splitbrain.org>2023-08-29 18:14:40 +0200
commitbcaec9f47d06126b3e653fea89a86d8b6a6cbef8 (patch)
tree16cc1b9d4f53736f1dddbd094c4621b34d0dcbbc
parentfaf3f01b9af152b16aca96437c109c41b8250689 (diff)
downloaddokuwiki-bcaec9f47d06126b3e653fea89a86d8b6a6cbef8.tar.gz
dokuwiki-bcaec9f47d06126b3e653fea89a86d8b6a6cbef8.zip
Apply rector fixes to inc/Parsing
-rw-r--r--_test/rector.php2
-rw-r--r--inc/Parsing/Handler/AbstractRewriter.php2
-rw-r--r--inc/Parsing/Handler/Block.php44
-rw-r--r--inc/Parsing/Handler/Lists.php78
-rw-r--r--inc/Parsing/Handler/Nest.php8
-rw-r--r--inc/Parsing/Handler/Preformatted.php8
-rw-r--r--inc/Parsing/Handler/Quote.php18
-rw-r--r--inc/Parsing/Handler/Table.php54
-rw-r--r--inc/Parsing/Lexer/Lexer.php25
-rw-r--r--inc/Parsing/Lexer/ParallelRegex.php15
-rw-r--r--inc/Parsing/Lexer/StateStack.php4
-rw-r--r--inc/Parsing/Parser.php5
-rw-r--r--inc/Parsing/ParserMode/AbstractMode.php5
-rw-r--r--inc/Parsing/ParserMode/Acronym.php6
-rw-r--r--inc/Parsing/ParserMode/Entity.php2
-rw-r--r--inc/Parsing/ParserMode/Eol.php2
-rw-r--r--inc/Parsing/ParserMode/Externallink.php4
-rw-r--r--inc/Parsing/ParserMode/Filelink.php1
-rw-r--r--inc/Parsing/ParserMode/Formatting.php43
-rw-r--r--inc/Parsing/ParserMode/Smiley.php2
-rw-r--r--inc/Parsing/ParserMode/Wordblock.php2
21 files changed, 158 insertions, 172 deletions
diff --git a/_test/rector.php b/_test/rector.php
index 21eefd33b..225dc2c4f 100644
--- a/_test/rector.php
+++ b/_test/rector.php
@@ -22,6 +22,7 @@ use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
+use Rector\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector;
use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
use Rector\Php71\Rector\ClassConst\PublicConstantVisibilityRector;
@@ -102,5 +103,6 @@ return static function (RectorConfig $rectorConfig): void {
TypedPropertyFromAssignsRector::class, // maybe?
JoinStringConcatRector::class, // this does not count variables, so it creates overlong lines
RemoveExtraParametersRector::class, // this actually broke code
+ RemoveUnusedNonEmptyArrayBeforeForeachRector::class, // seems unreliable when checking on array keys
]);
};
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;
}
diff --git a/inc/Parsing/Lexer/Lexer.php b/inc/Parsing/Lexer/Lexer.php
index 20040938e..cf0a2138c 100644
--- a/inc/Parsing/Lexer/Lexer.php
+++ b/inc/Parsing/Lexer/Lexer.php
@@ -18,13 +18,13 @@ namespace dokuwiki\Parsing\Lexer;
class Lexer
{
/** @var ParallelRegex[] */
- protected $regexes;
+ protected $regexes = [];
/** @var \Doku_Handler */
protected $handler;
/** @var StateStack */
protected $modeStack;
/** @var array mode "rewrites" */
- protected $mode_handlers;
+ protected $mode_handlers = [];
/** @var bool case sensitive? */
protected $case;
@@ -38,10 +38,8 @@ class Lexer
public function __construct($handler, $start = "accept", $case = false)
{
$this->case = $case;
- $this->regexes = array();
$this->handler = $handler;
$this->modeStack = new StateStack($start);
- $this->mode_handlers = array();
}
/**
@@ -141,13 +139,13 @@ class Lexer
$length = $initialLength;
$pos = 0;
while (is_array($parsed = $this->reduce($raw))) {
- list($unmatched, $matched, $mode) = $parsed;
+ [$unmatched, $matched, $mode] = $parsed;
$currentLength = strlen($raw);
$matchPos = $initialLength - $currentLength - strlen($matched);
if (! $this->dispatchTokens($unmatched, $matched, $mode, $pos, $matchPos)) {
return false;
}
- if ($currentLength == $length) {
+ if ($currentLength === $length) {
return false;
}
$length = $currentLength;
@@ -266,7 +264,7 @@ class Lexer
// modes starting with plugin_ are all handled by the same
// handler but with an additional parameter
if (substr($handler, 0, 7)=='plugin_') {
- list($handler,$plugin) = sexplode('_', $handler, 2, '');
+ [$handler, $plugin] = sexplode('_', $handler, 2, '');
return $this->handler->$handler($content, $is_match, $pos, $plugin);
}
@@ -291,8 +289,8 @@ class Lexer
return true;
}
if ($action = $this->regexes[$this->modeStack->getCurrent()]->split($raw, $split)) {
- list($unparsed, $match, $raw) = $split;
- return array($unparsed, $match, $action);
+ [$unparsed, $match, $raw] = $split;
+ return [$unparsed, $match, $action];
}
return true;
}
@@ -305,7 +303,7 @@ class Lexer
*/
public static function escape($str)
{
- $chars = array(
+ $chars = [
'/\\\\/',
'/\./',
'/\+/',
@@ -323,9 +321,9 @@ class Lexer
'/\>/',
'/\|/',
'/\:/'
- );
+ ];
- $escaped = array(
+ $escaped = [
'\\\\\\\\',
'\.',
'\+',
@@ -343,7 +341,8 @@ class Lexer
'\>',
'\|',
'\:'
- );
+ ];
+
return preg_replace($chars, $escaped, $str);
}
}
diff --git a/inc/Parsing/Lexer/ParallelRegex.php b/inc/Parsing/Lexer/ParallelRegex.php
index bf1979950..cc47c2e9b 100644
--- a/inc/Parsing/Lexer/ParallelRegex.php
+++ b/inc/Parsing/Lexer/ParallelRegex.php
@@ -17,9 +17,9 @@ namespace dokuwiki\Parsing\Lexer;
class ParallelRegex
{
/** @var string[] patterns to match */
- protected $patterns;
+ protected $patterns = [];
/** @var string[] labels for above patterns */
- protected $labels;
+ protected $labels = [];
/** @var string the compound regex matching all patterns */
protected $regex;
/** @var bool case sensitive matching? */
@@ -34,9 +34,6 @@ class ParallelRegex
public function __construct($case)
{
$this->case = $case;
- $this->patterns = array();
- $this->labels = array();
- $this->regex = null;
}
/**
@@ -121,15 +118,15 @@ class ParallelRegex
}
}
- $split = array($subject, "", "");
+ $split = [$subject, "", ""];
return false;
}
$idx = count($matches)-2;
- list($pre, $post) = preg_split($this->patterns[$idx].$this->getPerlMatchingFlags(), $subject, 2);
- $split = array($pre, $matches[0], $post);
+ [$pre, $post] = preg_split($this->patterns[$idx].$this->getPerlMatchingFlags(), $subject, 2);
+ $split = [$pre, $matches[0], $post];
- return isset($this->labels[$idx]) ? $this->labels[$idx] : true;
+ return $this->labels[$idx] ?? true;
}
/**
diff --git a/inc/Parsing/Lexer/StateStack.php b/inc/Parsing/Lexer/StateStack.php
index 325412bb4..5ec065967 100644
--- a/inc/Parsing/Lexer/StateStack.php
+++ b/inc/Parsing/Lexer/StateStack.php
@@ -22,7 +22,7 @@ class StateStack
*/
public function __construct($start)
{
- $this->stack = array($start);
+ $this->stack = [$start];
}
/**
@@ -41,7 +41,7 @@ class StateStack
*/
public function enter($state)
{
- array_push($this->stack, $state);
+ $this->stack[] = $state;
}
/**
diff --git a/inc/Parsing/Parser.php b/inc/Parsing/Parser.php
index 63f014161..2e495f588 100644
--- a/inc/Parsing/Parser.php
+++ b/inc/Parsing/Parser.php
@@ -2,6 +2,7 @@
namespace dokuwiki\Parsing;
+use dokuwiki\Debug\DebugHelper;
use Doku_Handler;
use dokuwiki\Parsing\Lexer\Lexer;
use dokuwiki\Parsing\ParserMode\Base;
@@ -20,7 +21,7 @@ class Parser {
protected $lexer;
/** @var ModeInterface[] $modes */
- protected $modes = array();
+ protected $modes = [];
/** @var bool mode connections may only be set up once */
protected $connected = false;
@@ -111,7 +112,7 @@ class Parser {
if (!method_exists($this->handler, 'finalize')) {
/** @deprecated 2019-10 we have a legacy handler from a plugin, assume legacy _finalize exists */
- \dokuwiki\Debug\DebugHelper::dbgCustomDeprecationEvent(
+ DebugHelper::dbgCustomDeprecationEvent(
'finalize()',
get_class($this->handler) . '::_finalize()',
__METHOD__,
diff --git a/inc/Parsing/ParserMode/AbstractMode.php b/inc/Parsing/ParserMode/AbstractMode.php
index 15fc9fe04..edd826e21 100644
--- a/inc/Parsing/ParserMode/AbstractMode.php
+++ b/inc/Parsing/ParserMode/AbstractMode.php
@@ -2,6 +2,7 @@
namespace dokuwiki\Parsing\ParserMode;
+use dokuwiki\Parsing\Lexer\Lexer;
/**
* This class and all the subclasses below are used to reduce the effort required to register
* modes with the Lexer.
@@ -10,9 +11,9 @@ namespace dokuwiki\Parsing\ParserMode;
*/
abstract class AbstractMode implements ModeInterface
{
- /** @var \dokuwiki\Parsing\Lexer\Lexer $Lexer will be injected on loading FIXME this should be done by setter */
+ /** @var Lexer $Lexer will be injected on loading FIXME this should be done by setter */
public $Lexer;
- protected $allowedModes = array();
+ protected $allowedModes = [];
/** @inheritdoc */
abstract public function getSort();
diff --git a/inc/Parsing/ParserMode/Acronym.php b/inc/Parsing/ParserMode/Acronym.php
index b42a7b573..c123d73c4 100644
--- a/inc/Parsing/ParserMode/Acronym.php
+++ b/inc/Parsing/ParserMode/Acronym.php
@@ -5,7 +5,7 @@ namespace dokuwiki\Parsing\ParserMode;
class Acronym extends AbstractMode
{
// A list
- protected $acronyms = array();
+ protected $acronyms = [];
protected $pattern = '';
/**
@@ -15,7 +15,7 @@ class Acronym extends AbstractMode
*/
public function __construct($acronyms)
{
- usort($acronyms, array($this,'compare'));
+ usort($acronyms, [$this, 'compare']);
$this->acronyms = $acronyms;
}
@@ -26,7 +26,7 @@ class Acronym extends AbstractMode
$bound = '[\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]';
$acronyms = array_map(['\\dokuwiki\\Parsing\\Lexer\\Lexer', 'escape'], $this->acronyms);
- $this->pattern = '(?<=^|'.$bound.')(?:'.join('|', $acronyms).')(?='.$bound.')';
+ $this->pattern = '(?<=^|'.$bound.')(?:'.implode('|', $acronyms).')(?='.$bound.')';
}
/** @inheritdoc */
diff --git a/inc/Parsing/ParserMode/Entity.php b/inc/Parsing/ParserMode/Entity.php
index b670124b2..4c58d1915 100644
--- a/inc/Parsing/ParserMode/Entity.php
+++ b/inc/Parsing/ParserMode/Entity.php
@@ -7,7 +7,7 @@ use dokuwiki\Parsing\Lexer\Lexer;
class Entity extends AbstractMode
{
- protected $entities = array();
+ protected $entities = [];
protected $pattern = '';
/**
diff --git a/inc/Parsing/ParserMode/Eol.php b/inc/Parsing/ParserMode/Eol.php
index a5886b51f..cfe36fb6c 100644
--- a/inc/Parsing/ParserMode/Eol.php
+++ b/inc/Parsing/ParserMode/Eol.php
@@ -8,7 +8,7 @@ class Eol extends AbstractMode
/** @inheritdoc */
public function connectTo($mode)
{
- $badModes = array('listblock','table');
+ $badModes = ['listblock', 'table'];
if (in_array($mode, $badModes)) {
return;
}
diff --git a/inc/Parsing/ParserMode/Externallink.php b/inc/Parsing/ParserMode/Externallink.php
index 530d5dbba..35ebb618d 100644
--- a/inc/Parsing/ParserMode/Externallink.php
+++ b/inc/Parsing/ParserMode/Externallink.php
@@ -4,8 +4,8 @@ namespace dokuwiki\Parsing\ParserMode;
class Externallink extends AbstractMode
{
- protected $schemes = array();
- protected $patterns = array();
+ protected $schemes = [];
+ protected $patterns = [];
/** @inheritdoc */
public function preConnect()
diff --git a/inc/Parsing/ParserMode/Filelink.php b/inc/Parsing/ParserMode/Filelink.php
index 3cd86cb8b..21791a84b 100644
--- a/inc/Parsing/ParserMode/Filelink.php
+++ b/inc/Parsing/ParserMode/Filelink.php
@@ -14,7 +14,6 @@ class Filelink extends AbstractMode
$ltrs = '\w';
$gunk = '/\#~:.?+=&%@!\-';
$punc = '.:?\-;,';
- $host = $ltrs.$punc;
$any = $ltrs.$gunk.$punc;
$this->pattern = '\b(?i)file(?-i)://['.$any.']+?['.
diff --git a/inc/Parsing/ParserMode/Formatting.php b/inc/Parsing/ParserMode/Formatting.php
index a3c465cc0..7949698b1 100644
--- a/inc/Parsing/ParserMode/Formatting.php
+++ b/inc/Parsing/ParserMode/Formatting.php
@@ -10,49 +10,44 @@ class Formatting extends AbstractMode
{
protected $type;
- protected $formatting = array(
- 'strong' => array(
+ protected $formatting = [
+ 'strong' => [
'entry' => '\*\*(?=.*\*\*)',
'exit' => '\*\*',
'sort' => 70
- ),
-
- 'emphasis' => array(
- 'entry' => '//(?=[^\x00]*[^:])', //hack for bugs #384 #763 #1468
+ ],
+ 'emphasis' => [
+ 'entry' => '//(?=[^\x00]*[^:])',
+ //hack for bugs #384 #763 #1468
'exit' => '//',
- 'sort' => 80
- ),
-
- 'underline' => array(
+ 'sort' => 80,
+ ],
+ 'underline' => [
'entry' => '__(?=.*__)',
'exit' => '__',
'sort' => 90
- ),
-
- 'monospace' => array(
+ ],
+ 'monospace' => [
'entry' => '\x27\x27(?=.*\x27\x27)',
'exit' => '\x27\x27',
'sort' => 100
- ),
-
- 'subscript' => array(
+ ],
+ 'subscript' => [
'entry' => '<sub>(?=.*</sub>)',
'exit' => '</sub>',
'sort' => 110
- ),
-
- 'superscript' => array(
+ ],
+ 'superscript' => [
'entry' => '<sup>(?=.*</sup>)',
'exit' => '</sup>',
'sort' => 120
- ),
-
- 'deleted' => array(
+ ],
+ 'deleted' => [
'entry' => '<del>(?=.*</del>)',
'exit' => '</del>',
'sort' => 130
- ),
- );
+ ]
+ ];
/**
* @param string $type
diff --git a/inc/Parsing/ParserMode/Smiley.php b/inc/Parsing/ParserMode/Smiley.php
index 084ccc9ed..99f9099ba 100644
--- a/inc/Parsing/ParserMode/Smiley.php
+++ b/inc/Parsing/ParserMode/Smiley.php
@@ -6,7 +6,7 @@ use dokuwiki\Parsing\Lexer\Lexer;
class Smiley extends AbstractMode
{
- protected $smileys = array();
+ protected $smileys = [];
protected $pattern = '';
/**
diff --git a/inc/Parsing/ParserMode/Wordblock.php b/inc/Parsing/ParserMode/Wordblock.php
index 50b24b2db..2fcd03eb5 100644
--- a/inc/Parsing/ParserMode/Wordblock.php
+++ b/inc/Parsing/ParserMode/Wordblock.php
@@ -9,7 +9,7 @@ use dokuwiki\Parsing\Lexer\Lexer;
*/
class Wordblock extends AbstractMode
{
- protected $badwords = array();
+ protected $badwords = [];
protected $pattern = '';
/**