Skip to content

Commit 0430041

Browse files
committed
PHP 8.4 fixes
- Replace Parsedown with CommonMark - Remove voku/anti-xss dependency - Automatic dark theme by default
1 parent 1ef8d7f commit 0430041

24 files changed

+2190
-553
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
strategy:
1010
matrix:
11-
php: ['8.0', '8.1', '8.2', '8.3', '8.4']
11+
php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
1212

1313
name: PHP ${{ matrix.php }}
1414

.phpcs.xml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<rule ref="PSR12">
1111
<!-- Backwards compatibilty exceptions -->
1212
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace"/>
13+
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/>
1314
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/>
1415
<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
1516
</rule>

app/controller.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected function _requireAdmin($rank = \Model\User::RANK_ADMIN)
6565
* @param array $hive
6666
* @param integer $ttl
6767
*/
68-
protected function _render($file, $mime = "text/html", array $hive = null, $ttl = 0)
68+
protected function _render($file, $mime = "text/html", ?array $hive = null, $ttl = 0)
6969
{
7070
echo \Helper\View::instance()->render($file, $mime, $hive, $ttl);
7171
}

app/controller/admin.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Controller;
44

5+
use League\CommonMark\GithubFlavoredMarkdownConverter;
6+
57
class Admin extends \Controller
68
{
79
protected $_userId;
@@ -99,10 +101,8 @@ public function releaseCheck()
99101
];
100102
if (!empty($release->body)) {
101103
// Render markdown description as HTML
102-
$parsedown = new \Parsedown();
103-
$parsedown->setUrlsLinked(false);
104-
$parsedown->setMarkupEscaped(true);
105-
$return['description_html'] = $parsedown->text($release->body);
104+
$md = new GithubFlavoredMarkdownConverter();
105+
$return['description_html'] = $md->convert($release->body);
106106
}
107107
echo json_encode($return, JSON_THROW_ON_ERROR);
108108
}
@@ -570,7 +570,7 @@ public function group_ajax(\Base $f3)
570570
$this->_printJson(["changed" => 1]);
571571
break;
572572
case "change_api_visibility":
573-
$group->api_visible = (int)!!$f3->get("POST.value");
573+
$group->api_visible = (int)((bool) $f3->get("POST.value"));
574574
$group->save();
575575
$this->_printJson(["changed" => 1]);
576576
break;

app/controller/api/user.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class User extends \Controller\Api
66
{
7-
protected function user_array(\Model\User $user)
7+
protected function user_array(\Model\User $user): array
88
{
99
$group_id = $user->id;
1010

@@ -25,7 +25,7 @@ protected function user_array(\Model\User $user)
2525
"email" => $user->email,
2626
];
2727

28-
return ($result);
28+
return $result;
2929
}
3030

3131
public function single_get($f3, $params)

app/controller/issues.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ protected function _saveNew()
748748
}
749749
}
750750

751-
$issue = \Model\Issue::create($data, !!$f3->get("POST.notify"));
751+
$issue = \Model\Issue::create($data, (bool) $f3->get("POST.notify"));
752752
if ($originalAuthor) {
753753
$issue->author_id = $originalAuthor;
754754
$issue->save(false);
@@ -829,7 +829,7 @@ public function single($f3, $params)
829829

830830
$watching = new \Model\Issue\Watcher();
831831
$watching->load(["issue_id = ? AND user_id = ?", $issue->id, $this->_userId]);
832-
$f3->set("watching", !!$watching->id);
832+
$f3->set("watching", (bool) $watching->id);
833833

834834
$f3->set("issue", $issue);
835835
$f3->set("ancestors", $issue->getAncestors());
@@ -1135,7 +1135,7 @@ public function comment_save($f3)
11351135
$issue->close();
11361136
}
11371137

1138-
$comment = \Model\Issue\Comment::create(["issue_id" => $post["issue_id"], "user_id" => $this->_userId, "text" => trim($post["text"])], !!$f3->get("POST.notify"));
1138+
$comment = \Model\Issue\Comment::create(["issue_id" => $post["issue_id"], "user_id" => $this->_userId, "text" => trim($post["text"])], (bool) $f3->get("POST.notify"));
11391139

11401140
if ($f3->get("AJAX")) {
11411141
$this->_printJson([
@@ -1209,7 +1209,7 @@ public function file_undelete($f3)
12091209
* @param string $q User query string
12101210
* @return array [string, keyword, ...]
12111211
*/
1212-
protected function _buildSearchWhere($q)
1212+
protected function _buildSearchWhere($q): array
12131213
{
12141214
if (!$q) {
12151215
return ["deleted_date IS NULL"];
@@ -1373,11 +1373,11 @@ function ($file) use ($f3, $orig_name, $user_id, $issue) {
13731373
$comment->created_date = $this->now();
13741374
$comment->file_id = $f3->get('file_id');
13751375
$comment->save();
1376-
if (!!$f3->get("POST.notify")) {
1376+
if ((bool) $f3->get("POST.notify")) {
13771377
$notification = \Helper\Notification::instance();
13781378
$notification->issue_comment($issue->id, $comment->id);
13791379
}
1380-
} elseif ($f3->get('file_id') && !!$f3->get("POST.notify")) {
1380+
} elseif ($f3->get('file_id') && (bool) $f3->get("POST.notify")) {
13811381
$notification = \Helper\Notification::instance();
13821382
$notification->issue_file($issue->id, $f3->get("file_id"));
13831383
}

app/controller/issues/project.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,8 @@ public function overview($f3, $params)
7070
"issue_type" => $f3->get("issue_type")
7171
];
7272
echo \Helper\View::instance()->render("issues/project/tree-item.html", "text/html", $hive);
73-
if ($children) {
74-
foreach ($children as $item) {
75-
$renderTree($item, $level + 1);
76-
}
73+
foreach ($children as $item) {
74+
$renderTree($item, $level + 1);
7775
}
7876
}
7977
};

app/controller/user.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function dashboardPost($f3)
114114
* Get array of theme names
115115
* @return array
116116
*/
117-
private function _loadThemes()
117+
private function _loadThemes(): array
118118
{
119119
$themes = ["bootstrap.min"];
120120
foreach (glob("css/bootstrap-*.css") as $file) {
@@ -354,7 +354,7 @@ public function single($f3, $params)
354354
* @param array $array Flat array of issues, including all parents needed
355355
* @return array Tree array where each issue contains its child issues
356356
*/
357-
protected function _buildTree($array)
357+
protected function _buildTree($array): array
358358
{
359359
$tree = [];
360360

app/helper/dashboard.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function projects()
8484
return $this->_projects;
8585
}
8686

87-
public function subprojects()
87+
public function subprojects(): array
8888
{
8989
if ($this->_projects === null) {
9090
$this->projects();
@@ -217,7 +217,7 @@ public function open_comments()
217217
* Get data for Issue Tree widget
218218
* @return array
219219
*/
220-
public function issue_tree()
220+
public function issue_tree(): array
221221
{
222222
$f3 = \Base::instance();
223223
$userId = $f3->get("this_user") ? $f3->get("this_user")->id : $f3->get("user.id");
@@ -284,7 +284,7 @@ public function issue_tree()
284284
* @param array $array Flat array of issues, including all parents needed
285285
* @return array Tree array where each issue contains its child issues
286286
*/
287-
protected function _buildTree($array)
287+
protected function _buildTree($array): array
288288
{
289289
$tree = [];
290290

app/helper/matrix.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Matrix extends \Matrix
1010
* @param array $arrays Array of sorted arrays to merge
1111
* @return array
1212
*/
13-
public function mergeSorted(array $arrays)
13+
public function mergeSorted(array $arrays): array
1414
{
1515
$lengths = [];
1616
foreach ($arrays as $k => $v) {

app/helper/notification.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,11 @@ protected function _issue_watchers($issue_id)
418418
* Render a view and return the result
419419
* @param string $file
420420
* @param string $mime
421-
* @param array $hive
421+
* @param array|null $hive
422422
* @param integer $ttl
423423
* @return string
424424
*/
425-
protected function _render($file, $mime = "text/html", array $hive = null, $ttl = 0)
425+
protected function _render($file, $mime = "text/html", ?array $hive = null, $ttl = 0)
426426
{
427427
return \Helper\View::instance()->render($file, $mime, $hive, $ttl);
428428
}

app/helper/plugin.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function addJsFile($file, $match = null)
8484
* @param string $location
8585
* @return array
8686
*/
87-
public function getNav($path = null, $location = "root")
87+
public function getNav($path = null, $location = "root"): array
8888
{
8989
$all = $this->_nav;
9090
$return = [];
@@ -116,7 +116,7 @@ public function getAllNavs($path = null)
116116
* @param string $path
117117
* @return array
118118
*/
119-
public function getJsFiles($path = null)
119+
public function getJsFiles($path = null): array
120120
{
121121
$return = [];
122122
foreach ($this->_jsFiles as $item) {
@@ -135,7 +135,7 @@ public function getJsFiles($path = null)
135135
* @param string $path
136136
* @return array
137137
*/
138-
public function getJsCode($path = null)
138+
public function getJsCode($path = null): array
139139
{
140140
$return = [];
141141
foreach ($this->_jsCode as $item) {

app/helper/security.php

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Helper;
44

5+
use Helper\Security\AntiXSS;
6+
57
class Security extends \Prefab
68
{
79
/**
@@ -156,4 +158,12 @@ public function hashEquals($str1, $str2)
156158
{
157159
return hash_equals($str1, $str2);
158160
}
161+
162+
/**
163+
* Clean a string to remove potential XSS attacks
164+
*/
165+
public function cleanXss(string $str): string
166+
{
167+
return (new AntiXSS())->xss_clean($str);
168+
}
159169
}

0 commit comments

Comments
 (0)