Skip to content

Commit 7bdcbaf

Browse files
authored
PHPStan level 5 \o/
2 parents 9afaba5 + fd69f4d commit 7bdcbaf

12 files changed

Lines changed: 107 additions & 78 deletions

File tree

.dist/phpstan.neon.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ parameters:
4646
- BBCODE_DEFAULT_FONT_FAMILY
4747
- BBCODE_USE_WRAPPER
4848
- BBCODE_USE_FILEWRAPPER
49+
- SEARCHBOX_BIG
50+
- PLUGIN_TAG_BL
51+
- PLUGIN_TAG_NOCACHE
4952

5053
# Scan for type resolution, but do not analyze
5154
scanDirectories:

fp-plugins/bbcode/inc/stringparser.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ function _outputTree() {
410410
*
411411
* @access protected
412412
* @return bool
413+
* @phpstan-impure
413414
*/
414415
function _reparseAfterCurrentBlock() {
415416
// this should definitely not happen!
@@ -504,6 +505,7 @@ function _setStatus($status) {
504505
* @param string $needle
505506
* The needle that was found
506507
* @return bool
508+
* @phpstan-impure
507509
*/
508510
function _handleStatus($status, $needle) {
509511
$this->_appendText($needle);

fp-plugins/mastodon/regression-test/simulate_mastodon_plugin.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,15 +2371,12 @@ function simulate_run_emoticon_export_sync_case($force) {
23712371
'tag' => plugin_mastodon_enabled_plugin_state('tag'),
23722372
'emoticons' => plugin_mastodon_enabled_plugin_state('emoticons')
23732373
);
2374+
$enabledPluginChecksOk = !in_array(false, $enabledPluginChecks, true);
23742375
$allOk = test_result(
23752376
'Mastodon companion-plugin detection uses FlatPress central enabled-plugin state',
2376-
$enabledPluginChecks ['bbcode'] === true
2377-
&& $enabledPluginChecks ['photoswipe'] === true
2378-
&& $enabledPluginChecks ['audiovideo'] === true
2379-
&& $enabledPluginChecks ['tag'] === true
2380-
&& $enabledPluginChecks ['emoticons'] === true,
2377+
$enabledPluginChecksOk,
23812378
json_encode($enabledPluginChecks)
2382-
) && $allOk;
2379+
);
23832380

23842381
$originalEnabledPlugins = isset($GLOBALS ['fp_plugins']) && is_array($GLOBALS ['fp_plugins']) ? $GLOBALS ['fp_plugins'] : null;
23852382
if (is_array($originalEnabledPlugins)) {

fp-plugins/photoswipe/photoswipefunctions.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static function getImageHtml($action, $attr, $content, $params, $node_object) {
189189

190190
if ($imageIsLocal) {
191191
$imgsize = @getimagesize($imgPathRel);
192-
if (is_array($imgsize) && isset($imgsize [0], $imgsize [1])) {
192+
if ($imgsize !== false) {
193193
$w = (int)$imgsize [0];
194194
$h = (int)$imgsize [1];
195195
}

fp-plugins/seometataginfo/inc/class.iniparser.php

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -171,65 +171,64 @@ function set($section, $key, $value = NULL) {
171171

172172
/**
173173
* Saves the entire array to the INI file.
174+
*
175+
* @param string|null $filename
176+
* @return bool
174177
*/
175178
function save($filename = null) {
176-
if ($filename == null) {
179+
if ($filename === null || $filename === '') {
177180
$filename = $this->_iniFilename;
178181
}
179-
if (true) {
180-
$tmpFile = $filename . '.tmp.' . getmypid() . '.' . uniqid('', true);
181-
$dir = dirname($filename);
182-
if (!@is_dir($dir) || !@is_writable($dir)) {
183-
return false;
184-
}
185-
$lock = @fopen($filename . '.lock', 'c');
182+
$tmpFile = $filename . '.tmp.' . getmypid() . '.' . uniqid('', true);
183+
$dir = dirname($filename);
184+
if (!@is_dir($dir) || !@is_writable($dir)) {
185+
return false;
186+
}
187+
$lock = @fopen($filename . '.lock', 'c');
188+
if ($lock) {
189+
@flock($lock, LOCK_EX);
190+
}
191+
$SFfdescriptor = @fopen($tmpFile, "wb");
192+
if (!$SFfdescriptor) {
186193
if ($lock) {
187-
@flock($lock, LOCK_EX);
188-
}
189-
$SFfdescriptor = @fopen($tmpFile, "wb");
190-
if (!$SFfdescriptor) {
191-
if ($lock) {
192-
@flock($lock, LOCK_UN);
193-
fclose($lock);
194-
}
195-
return false;
196-
}
197-
// blocking exclusive lock
198-
if (!@flock($SFfdescriptor, LOCK_EX)) {
199-
fclose($SFfdescriptor);
200-
@unlink($tmpFile);
201-
return false;
202-
}
203-
foreach ($this->_iniParsedArray as $section => $array) {
204-
fwrite($SFfdescriptor, "[" . $section . "]\n");
205-
foreach ($array as $key => $value) {
206-
fwrite($SFfdescriptor, $key . ' = ' . $value . "\n");
207-
}
208-
fwrite($SFfdescriptor, "\n");
194+
@flock($lock, LOCK_UN);
195+
fclose($lock);
209196
}
210-
fflush($SFfdescriptor);
211-
@flock($SFfdescriptor, LOCK_UN);
197+
return false;
198+
}
199+
// blocking exclusive lock
200+
if (!@flock($SFfdescriptor, LOCK_EX)) {
212201
fclose($SFfdescriptor);
202+
@unlink($tmpFile);
203+
return false;
204+
}
205+
foreach ($this->_iniParsedArray as $section => $array) {
206+
fwrite($SFfdescriptor, "[" . $section . "]\n");
207+
foreach ($array as $key => $value) {
208+
fwrite($SFfdescriptor, $key . ' = ' . $value . "\n");
209+
}
210+
fwrite($SFfdescriptor, "\n");
211+
}
212+
fflush($SFfdescriptor);
213+
@flock($SFfdescriptor, LOCK_UN);
214+
fclose($SFfdescriptor);
213215

216+
$ok = @rename($tmpFile, $filename);
217+
if (!$ok) {
218+
@unlink($filename);
214219
$ok = @rename($tmpFile, $filename);
215-
if (!$ok) {
216-
@unlink($filename);
217-
$ok = @rename($tmpFile, $filename);
218-
}
219-
if (!$ok) {
220-
@unlink($tmpFile);
221-
return false;
222-
}
223-
@chmod($filename, FILE_PERMISSIONS);
224-
if ($lock) {
225-
@flock($lock, LOCK_UN);
226-
fclose($lock);
227-
}
228-
clearstatcache(true, $filename);
229-
return true;
230-
} else {
220+
}
221+
if (!$ok) {
222+
@unlink($tmpFile);
231223
return false;
232224
}
225+
@chmod($filename, FILE_PERMISSIONS);
226+
if ($lock) {
227+
@flock($lock, LOCK_UN);
228+
fclose($lock);
229+
}
230+
clearstatcache(true, $filename);
231+
return true;
233232
}
234233

235234
}

login.php

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,39 +94,40 @@ function login_main() {
9494
});
9595

9696
$content = (SHARED_TPLS . 'login.tpl');
97-
} elseif (user_loggedin()) {
97+
} else {
9898
add_filter('wp_head', function () {
9999
// Login redirects to Admin Area
100100
myredirect('admin.php');
101101
});
102102

103103
$content = (SHARED_TPLS . 'login_success.tpl');
104-
} else {
105-
utils_redirect();
106104
}
107-
} elseif (sess_remove('logout_done')) {
105+
} else {
106+
$logoutDone = (bool)sess_remove('logout_done');
107+
if ($logoutDone) {
108108
//add_filter('wp_head', function () {
109109
//myredirect('.');
110110
//});
111111

112-
$content = (SHARED_TPLS . 'login_success.tpl');
113-
} elseif (empty($_POST)) {
114-
$content = (SHARED_TPLS . 'login.tpl');
115-
} else {
116-
// CSRF token verification
117-
if (!isset($_POST ['csrf_token']) || $_POST ['csrf_token'] !== $_SESSION ['csrf_token']) {
112+
$content = (SHARED_TPLS . 'login_success.tpl');
113+
} elseif (empty($_POST)) {
118114
$content = (SHARED_TPLS . 'login.tpl');
119-
} elseif (login_validate()) {
120-
// Validate after a POST and reset CSRF token after successful verification
121-
unset($_SESSION ['csrf_token']);
122-
$_SESSION ['csrf_token'] = bin2hex(random_bytes(32));
123-
$smarty->assign('csrf_token', $_SESSION ['csrf_token']);
124-
utils_redirect('login.php');
125-
exit();
126115
} else {
127-
// Assign sanitized inputs here
128-
$smarty->assign('user', $_POST ['user'] ?? '');
129-
$content = (SHARED_TPLS . 'login.tpl');
116+
// CSRF token verification
117+
if (!isset($_POST ['csrf_token']) || $_POST ['csrf_token'] !== $_SESSION ['csrf_token']) {
118+
$content = (SHARED_TPLS . 'login.tpl');
119+
} elseif (login_validate()) {
120+
// Validate after a POST and reset CSRF token after successful verification
121+
unset($_SESSION ['csrf_token']);
122+
$_SESSION ['csrf_token'] = bin2hex(random_bytes(32));
123+
$smarty->assign('csrf_token', $_SESSION ['csrf_token']);
124+
utils_redirect('login.php');
125+
exit();
126+
} else {
127+
// Assign sanitized inputs here
128+
$smarty->assign('user', $_POST ['user'] ?? '');
129+
$content = (SHARED_TPLS . 'login.tpl');
130+
}
130131
}
131132
}
132133

setup/main.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,26 @@ function chmod_r($path, $filemode, $dirmode) {
7676
chmod_r(BASE_DIR, FILE_PERMISSIONS, DIR_PERMISSIONS);
7777

7878
// Sets the local language based on the browser
79-
$language = @$_POST ['language'] ? $_POST ['language'] : $browserLang;
79+
$browserLang = isset($browserLang) && is_string($browserLang) && $browserLang !== '' ? $browserLang : (defined('LANG_DEFAULT') ? (string)LANG_DEFAULT : 'en-us');
80+
$language = isset($_POST ['language']) && is_string($_POST ['language']) && $_POST ['language'] !== '' ? $_POST ['language'] : $browserLang;
8081

8182
$lf = 'lang.' . $language . '.php';
8283
if (!preg_match('|^lang\.[a-z]{2}-[a-z]{2}\.php$|', $lf)) {
8384
die ('Error with lang file');
8485
}
8586

8687
include __DIR__ . '/lang/' . $lf;
88+
$setupMainVars = get_defined_vars();
89+
$lang = isset($setupMainVars ['lang']) && is_array($setupMainVars ['lang']) ? $setupMainVars ['lang'] : array();
8790
include __DIR__ . '/lib/main.lib.php';
8891

8992
$step = null;
9093

9194
$id = getstep($step);
9295

96+
if (!isset($lang [$step]) || !is_array($lang [$step])) {
97+
$lang [$step] = array();
98+
}
9399
$l = &$lang [$step];
94100

95101
include __DIR__ . '/tpls/header.tpl.php';

setup/tpls/header.tpl.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
<?php
2+
$lang = isset($lang) && is_array($lang) ? $lang : array('setup' => array('setup' => 'Setup'));
3+
?>
14
<!DOCTYPE html>
25
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php echo LANG_DEFAULT; ?>">
36
<head>

setup/tpls/locked.tpl.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
<?php
2+
$l = isset($l) && is_array($l) ? $l : array('head' => '', 'descr' => '%s %s %s');
3+
?>
14
<h2><?php echo $l ['head']; ?></h2>
25
<div class="post">
36

@@ -16,4 +19,4 @@
1619
echo wpautop(sprintf($l ['descr'], LOCKFILE, $base, $base . 'setup.php'));
1720
?>
1821

19-
</div>
22+
</div>

setup/tpls/step1.tpl.php

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

3+
$l = isset($l) && is_array($l) ? $l : array('head' => '', 'descr' => '%s', 'descrw' => '%s');
4+
$setupid = isset($setupid) ? (string)$setupid : '';
5+
$err = isset($err) ? $err : array();
6+
$lang = isset($lang) && is_array($lang) ? $lang : array('buttonbar' => array('next' => 'Next'));
7+
38
$o = new fs_filelister('./setup/lang/');
49
$languages = $o->getList();
510

0 commit comments

Comments
 (0)