Skip to content

Commit 9312c4b

Browse files
authored
Merge pull request #96 from woolfg/bot/autofix
🤖 Automatic code style fixes
2 parents c305c06 + c365e7d commit 9312c4b

File tree

4 files changed

+51
-81
lines changed

4 files changed

+51
-81
lines changed

action/editcommit.php

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use dokuwiki\Search\Indexer;
4+
35
/**
46
* DokuWiki Plugin gitbacked (Action Component)
57
*
@@ -68,8 +70,8 @@ private function initRepo()
6870
Git::setBin(empty($repoWorkDir) ? Git::getBin()
6971
: Git::getBin() . ' --work-tree ' . escapeshellarg($repoWorkDir));
7072
$params = str_replace(
71-
array('%mail%', '%user%'),
72-
array($this->getAuthorMail(), $this->getAuthor()),
73+
['%mail%', '%user%'],
74+
[$this->getAuthorMail(), $this->getAuthor()],
7375
$this->getConf('addParams')
7476
);
7577
if ($params) {
@@ -131,7 +133,7 @@ private function computeLocalPath()
131133
global $conf;
132134
$repoPath = str_replace('\\', '/', realpath(GitBackedUtil::getEffectivePath($this->getConf('repoPath'))));
133135
$datadir = $conf['datadir']; // already normalized
134-
if (!(substr($datadir, 0, strlen($repoPath)) === $repoPath)) {
136+
if (substr($datadir, 0, strlen($repoPath)) !== $repoPath) {
135137
throw new Exception('Datadir not inside repoPath ??');
136138
}
137139
return substr($datadir, strlen($repoPath) + 1);
@@ -140,8 +142,8 @@ private function computeLocalPath()
140142
private function updatePage($page)
141143
{
142144

143-
if (is_callable('\\dokuwiki\\Search\\Indexer::getInstance')) {
144-
$Indexer = \dokuwiki\Search\Indexer::getInstance();
145+
if (is_callable(Indexer::class . '::getInstance')) {
146+
$Indexer = Indexer::getInstance();
145147
$success = $Indexer->addPage($page, false, false);
146148
} elseif (class_exists('Doku_Indexer')) {
147149
$success = idx_addPage($page, false, false);
@@ -226,8 +228,8 @@ public function handleMediaDeletion(Event &$event, $param)
226228
$mediaName = $event->data['name'];
227229

228230
$message = str_replace(
229-
array('%media%', '%user%'),
230-
array($mediaName, $this->getAuthor()),
231+
['%media%', '%user%'],
232+
[$mediaName, $this->getAuthor()],
231233
$this->getConf('commitMediaMsgDel')
232234
);
233235

@@ -241,8 +243,8 @@ public function handleMediaUpload(Event &$event, $param)
241243
$mediaName = $event->data[2];
242244

243245
$message = str_replace(
244-
array('%media%', '%user%'),
245-
array($mediaName, $this->getAuthor()),
246+
['%media%', '%user%'],
247+
[$mediaName, $this->getAuthor()],
246248
$this->getConf('commitMediaMsg')
247249
);
248250

@@ -282,8 +284,8 @@ public function handleIOWikiPageWrite(Event &$event, $param)
282284
}
283285

284286
$message = str_replace(
285-
array('%page%', '%summary%', '%user%'),
286-
array($pageName, $editSummary, $this->getAuthor()),
287+
['%page%', '%summary%', '%user%'],
288+
[$pageName, $editSummary, $this->getAuthor()],
287289
$msgTemplate
288290
);
289291

@@ -303,11 +305,7 @@ public function handleIOWikiPageWrite(Event &$event, $param)
303305
*/
304306
public function notifyCreateNewError($repo_path, $reference, $error_message)
305307
{
306-
$template_replacements = array(
307-
'GIT_REPO_PATH' => $repo_path,
308-
'GIT_REFERENCE' => (empty($reference) ? 'n/a' : $reference),
309-
'GIT_ERROR_MESSAGE' => $error_message
310-
);
308+
$template_replacements = ['GIT_REPO_PATH' => $repo_path, 'GIT_REFERENCE' => (empty($reference) ? 'n/a' : $reference), 'GIT_ERROR_MESSAGE' => $error_message];
311309
return $this->notifyByMail('mail_create_new_error_subject', 'mail_create_new_error', $template_replacements);
312310
}
313311

@@ -321,10 +319,7 @@ public function notifyCreateNewError($repo_path, $reference, $error_message)
321319
*/
322320
public function notifyRepoPathError($repo_path, $error_message)
323321
{
324-
$template_replacements = array(
325-
'GIT_REPO_PATH' => $repo_path,
326-
'GIT_ERROR_MESSAGE' => $error_message
327-
);
322+
$template_replacements = ['GIT_REPO_PATH' => $repo_path, 'GIT_ERROR_MESSAGE' => $error_message];
328323
return $this->notifyByMail('mail_repo_path_error_subject', 'mail_repo_path_error', $template_replacements);
329324
}
330325

@@ -341,13 +336,7 @@ public function notifyRepoPathError($repo_path, $error_message)
341336
*/
342337
public function notifyCommandError($repo_path, $cwd, $command, $status, $error_message)
343338
{
344-
$template_replacements = array(
345-
'GIT_REPO_PATH' => $repo_path,
346-
'GIT_CWD' => $cwd,
347-
'GIT_COMMAND' => $command,
348-
'GIT_COMMAND_EXITCODE' => $status,
349-
'GIT_ERROR_MESSAGE' => $error_message
350-
);
339+
$template_replacements = ['GIT_REPO_PATH' => $repo_path, 'GIT_CWD' => $cwd, 'GIT_COMMAND' => $command, 'GIT_COMMAND_EXITCODE' => $status, 'GIT_ERROR_MESSAGE' => $error_message];
351340
return $this->notifyByMail('mail_command_error_subject', 'mail_command_error', $template_replacements);
352341
}
353342

@@ -365,11 +354,7 @@ public function notifyCommandSuccess($repo_path, $cwd, $command)
365354
if (!$this->getConf('notifyByMailOnSuccess')) {
366355
return false;
367356
}
368-
$template_replacements = array(
369-
'GIT_REPO_PATH' => $repo_path,
370-
'GIT_CWD' => $cwd,
371-
'GIT_COMMAND' => $command
372-
);
357+
$template_replacements = ['GIT_REPO_PATH' => $repo_path, 'GIT_CWD' => $cwd, 'GIT_COMMAND' => $command];
373358
return $this->notifyByMail('mail_command_success_subject', 'mail_command_success', $template_replacements);
374359
}
375360

@@ -403,6 +388,7 @@ public function notifyByMail($subject_id, $template_id, $template_replacements)
403388
//dbglog("GitBacked - template html['".$template_id."']: ".$template_html);
404389
$mailer->subject($this->getLang($subject_id));
405390
$mailer->setBody($template_text, $template_replacements, null, $template_html);
391+
406392
$ret = $mailer->send();
407393

408394
return $ret;

classes/GitBackedUtil.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,15 @@ public static function createMessageFile($message)
137137
*/
138138
public static function getClosestAbsoluteRepoPath($path)
139139
{
140-
$descriptorspec = array(
141-
1 => array('pipe', 'w'),
142-
2 => array('pipe', 'w'),
143-
);
144-
$ret = '';
145-
$pipes = array();
140+
$descriptorspec = [1 => ['pipe', 'w'], 2 => ['pipe', 'w']];
141+
$pipes = [];
146142
// Using --git-dir rather than --absolute-git-dir for a wider git versions compatibility
147143
//$command = Git::getBin()." rev-parse --absolute-git-dir";
148144
$command = Git::getBin() . " rev-parse --git-dir";
149145
//dbglog("GitBacked - Command: ".$command);
150146
$resource = proc_open($command, $descriptorspec, $pipes, $path);
151147
$stdout = stream_get_contents($pipes[1]);
152-
$stderr = stream_get_contents($pipes[2]);
148+
stream_get_contents($pipes[2]);
153149
foreach ($pipes as $pipe) {
154150
fclose($pipe);
155151
}

classes/GitRepo.php

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ class GitRepo
2121
public const REGEX_GIT_URL_FILTER_PWD = "/^(.*)((http:)|(https:))([^:]+)(:[^@]*)?(.*)/im";
2222
public const REGEX_GIT_URL_FILTER_PWD_REPLACE_PATTERN = "$1$2$5$7";
2323

24-
protected $repo_path = null;
24+
protected $repo_path;
2525
protected $bare = false;
26-
protected $envopts = array();
26+
protected $envopts = [];
2727
// Fix for PHP <=7.3 compatibility: Type declarations for properties work since PHP >= 7.4 only.
2828
// protected ?\action_plugin_gitbacked_editcommit $plugin = null;
29-
protected $plugin = null;
29+
protected $plugin;
3030

3131
/**
3232
* Create a new git repository
@@ -131,43 +131,39 @@ public function setRepoPath($repo_path, $create_new = false, $_init = true)
131131
$this->repo_path = $repo_path;
132132
$this->bare = true;
133133
}
134-
} else {
135-
if ($create_new) {
136-
$this->repo_path = $repo_path;
137-
if ($_init) {
138-
$this->run('init');
139-
}
140-
} else {
141-
throw new \Exception($this->handleRepoPathError(
142-
$repo_path,
143-
'"' . $repo_path . '" is not a git repository'
144-
));
134+
} elseif ($create_new) {
135+
$this->repo_path = $repo_path;
136+
if ($_init) {
137+
$this->run('init');
145138
}
139+
} else {
140+
throw new \Exception($this->handleRepoPathError(
141+
$repo_path,
142+
'"' . $repo_path . '" is not a git repository'
143+
));
146144
}
147145
} else {
148146
throw new \Exception($this->handleRepoPathError(
149147
$repo_path,
150148
'"' . $repo_path . '" is not a directory'
151149
));
152150
}
153-
} else {
154-
if ($create_new) {
155-
if ($parent = realpath(dirname($repo_path))) {
156-
mkdir($repo_path);
157-
$this->repo_path = $repo_path;
158-
if ($_init) $this->run('init');
159-
} else {
160-
throw new \Exception($this->handleRepoPathError(
161-
$repo_path,
162-
'cannot create repository in non-existent directory'
163-
));
164-
}
151+
} elseif ($create_new) {
152+
if ($parent = realpath(dirname($repo_path))) {
153+
mkdir($repo_path);
154+
$this->repo_path = $repo_path;
155+
if ($_init) $this->run('init');
165156
} else {
166157
throw new \Exception($this->handleRepoPathError(
167158
$repo_path,
168-
'"' . $repo_path . '" does not exist'
159+
'cannot create repository in non-existent directory'
169160
));
170161
}
162+
} else {
163+
throw new \Exception($this->handleRepoPathError(
164+
$repo_path,
165+
'"' . $repo_path . '" does not exist'
166+
));
171167
}
172168
}
173169
}
@@ -191,15 +187,12 @@ public function gitDirectoryPath()
191187
*/
192188
public function testGit()
193189
{
194-
$descriptorspec = array(
195-
1 => array('pipe', 'w'),
196-
2 => array('pipe', 'w'),
197-
);
198-
$pipes = array();
190+
$descriptorspec = [1 => ['pipe', 'w'], 2 => ['pipe', 'w']];
191+
$pipes = [];
199192
$resource = proc_open(Git::getBin(), $descriptorspec, $pipes);
200193

201-
$stdout = stream_get_contents($pipes[1]);
202-
$stderr = stream_get_contents($pipes[2]);
194+
stream_get_contents($pipes[1]);
195+
stream_get_contents($pipes[2]);
203196
foreach ($pipes as $pipe) {
204197
fclose($pipe);
205198
}
@@ -220,11 +213,8 @@ public function testGit()
220213
protected function runCommand($command)
221214
{
222215
//dbglog("Git->runCommand(command=[".$command."])");
223-
$descriptorspec = array(
224-
1 => array('pipe', 'w'),
225-
2 => array('pipe', 'w'),
226-
);
227-
$pipes = array();
216+
$descriptorspec = [1 => ['pipe', 'w'], 2 => ['pipe', 'w']];
217+
$pipes = [];
228218
$cwd = $this->repo_path;
229219
//dbglog("GitBacked - cwd: [".$cwd."]");
230220
/* Provide any $this->envopts via putenv

loader.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
* @return void
1212
*/
1313
function ($class) {
14-
$namespaces = array(
15-
'woolfg\\dokuwiki\\plugin\\gitbacked\\' => __DIR__ . '/classes/'
16-
);
14+
$namespaces = ['woolfg\\dokuwiki\\plugin\\gitbacked\\' => __DIR__ . '/classes/'];
1715

1816
foreach ($namespaces as $prefix => $base_dir) {
1917
// does the class use the namespace prefix?

0 commit comments

Comments
 (0)