Skip to content

Commit a7a40fb

Browse files
committed
Automatic code style fixes
1 parent 9a026de commit a7a40fb

File tree

8 files changed

+64
-64
lines changed

8 files changed

+64
-64
lines changed

Functions.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
<?php
2+
23
/**
34
* @noinspection PhpUndefinedMethodInspection
45
* @noinspection PhpComposerExtensionStubsInspection
56
*/
67

7-
88
namespace dokuwiki\plugin\sqlite;
99

1010
/**
1111
* SQLite registered functions
1212
*/
1313
class Functions
1414
{
15-
1615
/**
1716
* Register all standard functions
1817
*
@@ -74,7 +73,7 @@ public static function GroupConcatFinalize(&$context, $rownumber)
7473
if (empty($context['data'][0])) {
7574
return null;
7675
}
77-
return join($context['sep'], $context['data']);
76+
return implode($context['sep'], $context['data']);
7877
}
7978

8079

@@ -119,7 +118,6 @@ public static function pageExists($pageid)
119118
static $cache = [];
120119
if (!isset($cache[$pageid])) {
121120
$cache[$pageid] = page_exists($pageid);
122-
123121
}
124122
return (int)$cache[$pageid];
125123
}
@@ -157,5 +155,4 @@ public static function resolvePage($page, $context)
157155
resolve_pageid($ns, $page, $exists);
158156
return $page;
159157
}
160-
161158
}

QuerySaver.php

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
class QuerySaver
88
{
9-
109
protected $db;
1110
protected $upstream;
1211

SQLiteDB.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
class SQLiteDB
1818
{
19-
const FILE_EXTENSION = '.sqlite3';
19+
public const FILE_EXTENSION = '.sqlite3';
2020

2121
/** @var \PDO */
2222
protected $pdo;
@@ -239,8 +239,10 @@ public function saveRecord($table, $data, $replace = true)
239239
}
240240

241241
/** @noinspection SqlResolve */
242-
$sql = $command . ' INTO "' . $table . '" (' . join(',', $columns) . ') VALUES (' . join(',',
243-
$placeholders) . ')';
242+
$sql = $command . ' INTO "' . $table . '" (' . implode(',', $columns) . ') VALUES (' . implode(
243+
',',
244+
$placeholders
245+
) . ')';
244246
$stm = $this->query($sql, $values);
245247
$success = $stm->rowCount();
246248
$stm->closeCursor();
@@ -371,7 +373,7 @@ public function dumpToFile($filename)
371373
$sql = "SELECT * FROM " . $table['name'];
372374
$res = $this->query($sql);
373375
while ($row = $res->fetch(\PDO::FETCH_ASSOC)) {
374-
$values = join(',', array_map(function ($value) {
376+
$values = implode(',', array_map(function ($value) {
375377
if ($value === null) return 'NULL';
376378
return $this->pdo->quote($value);
377379
}, $row));
@@ -415,7 +417,7 @@ protected function applyMigrations()
415417
'sqlite' => $this->helper,
416418
'adapter' => $this,
417419
];
418-
$event = new \Doku_Event('PLUGIN_SQLITE_DATABASE_UPGRADE', $data);
420+
$event = new Event('PLUGIN_SQLITE_DATABASE_UPGRADE', $data);
419421

420422
$this->pdo->beginTransaction();
421423
try {
@@ -425,11 +427,9 @@ protected function applyMigrations()
425427
foreach ($sql as $query) {
426428
$this->pdo->exec($query);
427429
}
428-
} else {
429-
if (!$event->result) {
430-
// advise before returned false, but the result was false
431-
throw new \PDOException('Plugin event did not signal success');
432-
}
430+
} elseif (!$event->result) {
431+
// advise before returned false, but the result was false
432+
throw new \PDOException('Plugin event did not signal success');
433433
}
434434
$this->setOpt('dbversion', $newVersion);
435435
$this->pdo->commit();

Tools.php

+18-17
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace dokuwiki\plugin\sqlite;
44

5-
class Tools {
6-
5+
class Tools
6+
{
77
/**
88
* Split sql queries on semicolons, unless when semicolons are quoted
99
*
@@ -13,36 +13,37 @@ class Tools {
1313
* @param string $sql
1414
* @return string[] sql queries
1515
*/
16-
public static function SQLstring2array($sql) {
17-
$statements = array();
16+
public static function SQLstring2array($sql)
17+
{
18+
$statements = [];
1819
$len = strlen($sql);
1920

2021
// Simple state machine to "parse" sql into single statements
2122
$in_str = false;
2223
$in_com = false;
2324
$statement = '';
24-
for($i=0; $i<$len; $i++){
25-
$prev = $i ? $sql[$i-1] : "\n";
25+
for ($i = 0; $i < $len; $i++) {
26+
$prev = $i ? $sql[$i - 1] : "\n";
2627
$char = $sql[$i];
27-
$next = $i < ($len - 1) ? $sql[$i+1] : '';
28+
$next = $i < ($len - 1) ? $sql[$i + 1] : '';
2829

2930
// in comment? ignore everything until line end
30-
if($in_com){
31-
if($char == "\n"){
31+
if ($in_com) {
32+
if ($char == "\n") {
3233
$in_com = false;
3334
}
3435
continue;
3536
}
3637

3738
// handle strings
38-
if($in_str){
39-
if($char == "'"){
40-
if($next == "'"){
39+
if ($in_str) {
40+
if ($char == "'") {
41+
if ($next == "'") {
4142
// current char is an escape for the next
4243
$statement .= $char . $next;
4344
$i++;
4445
continue;
45-
}else{
46+
} else {
4647
// end of string
4748
$statement .= $char;
4849
$in_str = false;
@@ -55,20 +56,20 @@ public static function SQLstring2array($sql) {
5556
}
5657

5758
// new comment?
58-
if($char == '-' && $next == '-' && $prev == "\n"){
59+
if ($char == '-' && $next == '-' && $prev == "\n") {
5960
$in_com = true;
6061
continue;
6162
}
6263

6364
// new string?
64-
if($char == "'"){
65+
if ($char == "'") {
6566
$in_str = true;
6667
$statement .= $char;
6768
continue;
6869
}
6970

7071
// the real delimiter
71-
if($char == ';'){
72+
if ($char == ';') {
7273
$statements[] = trim($statement);
7374
$statement = '';
7475
continue;
@@ -77,7 +78,7 @@ public static function SQLstring2array($sql) {
7778
// some standard query stuff
7879
$statement .= $char;
7980
}
80-
if($statement) $statements[] = trim($statement);
81+
if ($statement) $statements[] = trim($statement);
8182

8283
return array_filter($statements); // remove empty statements
8384
}

admin.php

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use dokuwiki\Extension\AdminPlugin;
34
use dokuwiki\Form\Form;
45
use dokuwiki\Form\InputElement;
56
use dokuwiki\plugin\sqlite\QuerySaver;
@@ -12,13 +13,13 @@
1213
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
1314
* @author Andreas Gohr <[email protected]>
1415
*/
15-
class admin_plugin_sqlite extends DokuWiki_Admin_Plugin
16+
class admin_plugin_sqlite extends AdminPlugin
1617
{
1718
/** @var SQLiteDB */
18-
protected $db = null;
19+
protected $db;
1920

2021
/** @var QuerySaver */
21-
protected $querySaver = null;
22+
protected $querySaver;
2223

2324
/** @inheritdoc */
2425
public function getMenuSort()
@@ -148,12 +149,7 @@ public function getTOC()
148149
$dbfiles = glob($conf['metadir'] . '/*.sqlite3');
149150
if (is_array($dbfiles)) foreach ($dbfiles as $file) {
150151
$db = basename($file, '.sqlite3');
151-
$toc[] = array(
152-
'link' => wl($ID, array('do' => 'admin', 'page' => 'sqlite', 'db' => $db, 'sectok' => getSecurityToken())),
153-
'title' => $db,
154-
'level' => 2,
155-
'type' => 'ul',
156-
);
152+
$toc[] = ['link' => wl($ID, ['do' => 'admin', 'page' => 'sqlite', 'db' => $db, 'sectok' => getSecurityToken()]), 'title' => $db, 'level' => 2, 'type' => 'ul'];
157153
}
158154

159155
return $toc;
@@ -238,7 +234,8 @@ protected function selfLink($form = true, $params = [])
238234
'page' => 'sqlite',
239235
'db' => $this->db ? $this->db->getDBName() : '',
240236
'sectok' => getSecurityToken(),
241-
], $params
237+
],
238+
$params
242239
);
243240

244241
return wl($ID, $params, false, $form ? '&' : '&amp;');

helper.php

+23-19
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@
66
* @noinspection PhpComposerExtensionStubsInspection
77
*/
88

9+
use dokuwiki\Extension\Plugin;
910
use dokuwiki\plugin\sqlite\SQLiteDB;
1011
use dokuwiki\plugin\sqlite\Tools;
1112

12-
13-
1413
/**
1514
* For compatibility with previous adapter implementation.
1615
*/
17-
if(!defined('DOKU_EXT_PDO')) define('DOKU_EXT_PDO', 'pdo');
16+
if (!defined('DOKU_EXT_PDO')) define('DOKU_EXT_PDO', 'pdo');
1817
class helper_plugin_sqlite_adapter_dummy
1918
{
20-
public function getName() {
19+
public function getName()
20+
{
2121
return DOKU_EXT_PDO;
2222
}
2323

24-
public function setUseNativeAlter($set) {}
24+
public function setUseNativeAlter($set)
25+
{
26+
}
2527
}
2628

2729
/**
@@ -31,10 +33,10 @@ public function setUseNativeAlter($set) {}
3133
* @author Andreas Gohr <[email protected]>
3234
* @deprecated 2023-03-15
3335
*/
34-
class helper_plugin_sqlite extends DokuWiki_Plugin
36+
class helper_plugin_sqlite extends Plugin
3537
{
3638
/** @var SQLiteDB|null */
37-
protected $adapter = null;
39+
protected $adapter;
3840

3941
/** @var array result cache */
4042
protected $data;
@@ -89,7 +91,7 @@ public function existsPDOSqlite()
8991
*/
9092
public function init($dbname, $updatedir)
9193
{
92-
if(!defined('DOKU_UNITTEST')) { // for now we don't want to trigger the deprecation warning in the tests
94+
if (!defined('DOKU_UNITTEST')) { // for now we don't want to trigger the deprecation warning in the tests
9395
dbg_deprecated(SQLiteDB::class);
9496
}
9597

@@ -108,7 +110,7 @@ public function init($dbname, $updatedir)
108110
* @param SQLiteDB $adapter
109111
* @return void
110112
*/
111-
function setAdapter($adapter)
113+
public function setAdapter($adapter)
112114
{
113115
$this->adapter = $adapter;
114116
}
@@ -182,17 +184,18 @@ public function query()
182184
* @return bool|string
183185
* @throws Exception
184186
*/
185-
public function prepareSql($args) {
187+
public function prepareSql($args)
188+
{
186189

187190
$sql = trim(array_shift($args));
188191
$sql = rtrim($sql, ';');
189192

190-
if(!$sql) {
193+
if (!$sql) {
191194
throw new \Exception('No SQL statement given', -1);
192195
}
193196

194197
$argc = count($args);
195-
if($argc > 0 && is_array($args[0])) {
198+
if ($argc > 0 && is_array($args[0])) {
196199
$args = $args[0];
197200
$argc = count($args);
198201
}
@@ -201,18 +204,18 @@ public function prepareSql($args) {
201204
$qmc = substr_count($sql, '?');
202205
if ($argc < $qmc) {
203206
throw new \Exception('Not enough arguments passed for statement. ' .
204-
'Expected '.$qmc.' got '. $argc.' - '.hsc($sql));
205-
} elseif($argc > $qmc) {
207+
'Expected ' . $qmc . ' got ' . $argc . ' - ' . hsc($sql));
208+
} elseif ($argc > $qmc) {
206209
throw new \Exception('Too much arguments passed for statement. ' .
207-
'Expected '.$qmc.' got '. $argc.' - '.hsc($sql));
210+
'Expected ' . $qmc . ' got ' . $argc . ' - ' . hsc($sql));
208211
}
209212

210213
// explode at wildcard, then join again
211214
$parts = explode('?', $sql, $argc + 1);
212215
$args = array_map([$this->adapter->getPdo(), 'quote'], $args);
213216
$sql = '';
214217

215-
while(($part = array_shift($parts)) !== null) {
218+
while (($part = array_shift($parts)) !== null) {
216219
$sql .= $part;
217220
$sql .= array_shift($args);
218221
}
@@ -356,7 +359,7 @@ public function countChanges($res)
356359
public function quote_and_join($vals, $sep = ',')
357360
{
358361
$vals = array_map([$this->adapter->getPdo(), 'quote'], $vals);
359-
return join($sep, $vals);
362+
return implode($sep, $vals);
360363
}
361364

362365
/**
@@ -391,7 +394,7 @@ public function escape_string($str)
391394
*/
392395
public function SQLstring2array($sql)
393396
{
394-
if(!DOKU_UNITTEST) { // for now we don't want to trigger the deprecation warning in the tests
397+
if (!DOKU_UNITTEST) { // for now we don't want to trigger the deprecation warning in the tests
395398
dbg_deprecated(Tools::class . '::SQLstring2array');
396399
}
397400
return Tools::SQLstring2array($sql);
@@ -400,7 +403,8 @@ public function SQLstring2array($sql)
400403
/**
401404
* @deprecated needs to be fixed in stuct and structpublish
402405
*/
403-
public function doTransaction($sql, $sqlpreparing = true) {
406+
public function doTransaction($sql, $sqlpreparing = true)
407+
{
404408
throw new \Exception(
405409
'This method seems to never have done what it suggests. Please use the query() function instead.'
406410
);

0 commit comments

Comments
 (0)