From 9730265cac55f032a41e08c80cc41610b870373b Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 19 Dec 2024 09:54:18 +0100 Subject: [PATCH] automatic code style fixes --- conf/default.php | 2 +- conf/metadata.php | 3 +-- helper.php | 9 ++++++--- renderer.php | 2 -- syntax/macro.php | 7 ++++--- syntax/query.php | 19 +++++++++---------- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/conf/default.php b/conf/default.php index 17bd438..da35fd7 100644 --- a/conf/default.php +++ b/conf/default.php @@ -1,4 +1,5 @@ */ -class helper_plugin_dbquery extends dokuwiki\Extension\Plugin +class helper_plugin_dbquery extends Plugin { /** @var PDO[] do not access directly, use getPDO instead */ protected $pdo = []; @@ -76,6 +78,7 @@ public function executeQuery($query, $dsnalias = null) $params = $this->gatherVariables(); $sth = $this->prepareStatement($pdo, $query, $params); $sth->execute(); + $data = $sth->fetchAll(PDO::FETCH_ASSOC); $sth->closeCursor(); @@ -101,13 +104,13 @@ public function prepareStatement(\PDO $pdo, $sql, $parameters) $groupids[] = ":$id"; } unset($parameters[':groups']); - $sql = str_replace(':groups', join(',', $groupids), $sql); + $sql = str_replace(':groups', implode(',', $groupids), $sql); $sth = $pdo->prepare($sql); foreach ($parameters as $key => $val) { if (is_array($val)) continue; if (is_object($val)) continue; - if (strpos($sql, $key) === false) continue; // skip if parameter is missing + if (!str_contains($sql, $key)) continue; // skip if parameter is missing if (is_int($val)) { $sth->bindValue($key, $val, PDO::PARAM_INT); diff --git a/renderer.php b/renderer.php index e1d72a3..dd2231d 100644 --- a/renderer.php +++ b/renderer.php @@ -10,7 +10,6 @@ */ class renderer_plugin_dbquery extends \Doku_Renderer { - protected $codeBlocks = []; protected $lastHeader = ''; @@ -53,5 +52,4 @@ public function document_end() 'macros' => $this->info['dbquery'], ]); } - } diff --git a/syntax/macro.php b/syntax/macro.php index 8de860a..1cb1ac3 100644 --- a/syntax/macro.php +++ b/syntax/macro.php @@ -1,12 +1,14 @@ */ -class syntax_plugin_dbquery_macro extends \dokuwiki\Extension\SyntaxPlugin +class syntax_plugin_dbquery_macro extends SyntaxPlugin { /** @inheritDoc */ public function getType() @@ -45,10 +47,9 @@ public function render($mode, Doku_Renderer $renderer, $data) [$name, $value] = sexplode('=', $data[0], 2); $name = trim($name); $value = trim($value); - if(!$value) $value = true; + if (!$value) $value = true; $renderer->info['dbquery'][$name] = $value; return true; } } - diff --git a/syntax/query.php b/syntax/query.php index 7403462..947e227 100644 --- a/syntax/query.php +++ b/syntax/query.php @@ -1,12 +1,14 @@ */ -class syntax_plugin_dbquery_query extends DokuWiki_Syntax_Plugin +class syntax_plugin_dbquery_query extends SyntaxPlugin { /** @inheritDoc */ public function getType() @@ -57,12 +59,10 @@ public function render($mode, Doku_Renderer $renderer, $data) if (count($result) === 1 && isset($result[0]['status']) && isset($qdata['codeblocks'][$result[0]['status']])) { $this->renderStatus($result, $qdata['codeblocks'][$result[0]['status']], $renderer); + } elseif ($qdata['macros']['transpose']) { + $this->renderTransposedResultTable($result, $renderer); } else { - if ($qdata['macros']['transpose']) { - $this->renderTransposedResultTable($result, $renderer); - } else { - $this->renderResultTable($result, $renderer); - } + $this->renderResultTable($result, $renderer); } return true; @@ -77,7 +77,7 @@ public function render($mode, Doku_Renderer $renderer, $data) */ public function renderStatus($result, $html, Doku_Renderer $R) { - $value = isset($result[0]['result']) ? $result[0]['result'] : ''; + $value = $result[0]['result'] ?? ''; $html = str_replace(':result', hsc($value), $html); $R->doc .= $html; } @@ -172,7 +172,7 @@ protected function cellFormat($content, Doku_Renderer $R) if (preg_match('/^\[\[(https?:\/\/[^|\]]+)(|.*?)?]]$/', $content, $m)) { $url = $m[1]; $title = $m[2] ?? ''; - $title = trim($title,'|'); + $title = trim($title, '|'); $R->externallink($url, $title); return; } @@ -181,7 +181,7 @@ protected function cellFormat($content, Doku_Renderer $R) if (preg_match('/^\[\[([^|\]]+)(|.*?)?]]$/', $content, $m)) { $page = cleanID($m[1]); $title = $m[2] ?? ''; - $title = trim($title,'|'); + $title = trim($title, '|'); $R->internallink($page, $title); return; } @@ -189,4 +189,3 @@ protected function cellFormat($content, Doku_Renderer $R) $R->cdata($content); } } -