Author: Nikita Popov (nikic)
Date: 2021-04-11T20:46:25+02:00
Commit:
https://github.com/php/web-master/commit/031dbfdb8aaeb372c136a5187e7f52e2c3abf089
Raw diff:
https://github.com/php/web-master/commit/031dbfdb8aaeb372c136a5187e7f52e2c3abf089.diff
Minor code cleanups
Applying various minor improvements suggested by PhpStorm.
Changed paths:
M include/note-reasons.inc
M public/entry/user-note.php
M public/fetch/index.php
M public/forgot.php
M public/github-webhook.php
M public/manage/event.php
M public/manage/github.php
M public/manage/user-notes.php
M scripts/index.php
Diff:
diff --git a/include/note-reasons.inc b/include/note-reasons.inc
index 1eaaef1..5fd7b6c 100644
--- a/include/note-reasons.inc
+++ b/include/note-reasons.inc
@@ -1,5 +1,4 @@
<?php
-/* $Id: */
// stock reasons for deleting notes
$note_del_reasons = [
@@ -16,5 +15,4 @@ foreach ($note_del_reasons AS $r) {
$note_del_reasons_pad = $l;
}
}
-++$note_del_reasons_pad;
-?>
+++$note_del_reasons_pad;
\ No newline at end of file
diff --git a/public/entry/user-note.php b/public/entry/user-note.php
index d71540f..3bfcc32 100644
--- a/public/entry/user-note.php
+++ b/public/entry/user-note.php
@@ -152,11 +152,5 @@ function validateUser($user) {
die("failed to insert record");
}
-
-
-
-
//var_dump(is_spammer('127.0.0.1')); // false
-//var_dump(is_spammer('127.0.0.2')); // true
-
-?>
+//var_dump(is_spammer('127.0.0.2')); // true
\ No newline at end of file
diff --git a/public/fetch/index.php b/public/fetch/index.php
index 4b6dff4..27fbc67 100644
--- a/public/fetch/index.php
+++ b/public/fetch/index.php
@@ -1,3 +1,2 @@
<?php
-header("Location: https://php.net/");
-?>
+header("Location: https://php.net/");
\ No newline at end of file
diff --git a/public/forgot.php b/public/forgot.php
index 741ad91..380a985 100644
--- a/public/forgot.php
+++ b/public/forgot.php
@@ -3,11 +3,11 @@
require __DIR__ . "/../include/cvs-auth.inc";
require __DIR__ . "/../include/mailer.php";
-$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : false;
-$user = isset($_REQUEST['user']) ? $_REQUEST['user'] : false;
-$key = isset($_REQUEST['key']) ? $_REQUEST['key'] : false;
-$n1 = isset($_REQUEST['n1']) ? $_REQUEST['n1'] : false;
-$n2 = isset($_REQUEST['n2']) ? $_REQUEST['n2'] : false;
+$id = $_REQUEST['id'] ?? false;
+$user = $_REQUEST['user'] ?? false;
+$key = $_REQUEST['key'] ?? false;
+$n1 = $_REQUEST['n1'] ?? false;
+$n2 = $_REQUEST['n2'] ?? false;
$ts = $_SERVER["REQUEST_TIME"];
@@ -15,12 +15,6 @@ function random_password() {
return bin2hex(random_bytes(16));
}
-function username_from_forgotten($key, $id) {
- $res = db_query_safe("SELECT username FROM users WHERE userid=? AND
forgot=?", [$id, $key]);
- if ($res && ($row = mysql_fetch_array($res,MYSQL_ASSOC))) {
- return $row["username"];
- }
-}
head("forgotten password");
db_connect();
diff --git a/public/github-webhook.php b/public/github-webhook.php
index af721e9..d906a90 100644
--- a/public/github-webhook.php
+++ b/public/github-webhook.php
@@ -36,9 +36,7 @@ function prep_title($issue, $repoName) {
$title = $issue->title;
$type = is_pr($issue) ? 'PR' : 'Issue';
- $subject = sprintf('[%s][%s #%s] - %s', $repoName, $type, $issueNumber,
$title);
-
- return $subject;
+ return sprintf('[%s][%s #%s] - %s', $repoName, $type, $issueNumber,
$title);
}
function send_mail($to, $subject, $message, MailAddress $from, array $replyTos
= []) {
@@ -215,9 +213,9 @@ function handle_commit_mail(PDO $dbh, $mailingList,
$repoName, $ref, $pusherUser
throw $e;
}
- $authorUser = isset($commit->author->username) ? $commit->author->username
: null;
+ $authorUser = $commit->author->username ?? null;
$authorName = $commit->author->name;
- $committerUser = isset($commit->committer->username) ?
$commit->committer->username : null;
+ $committerUser = $commit->committer->username ?? null;
$committerName = $commit->committer->name;
$message = $commit->message;
$timestamp = $commit->timestamp;
diff --git a/public/manage/event.php b/public/manage/event.php
index 5c1b1ce..85fb1a2 100644
--- a/public/manage/event.php
+++ b/public/manage/event.php
@@ -28,15 +28,15 @@
head("event administration");
db_connect();
-$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : false;
-$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : false;
-$in = isset($_REQUEST['in']) ? $_REQUEST['in'] : false;
-$begin = isset($_REQUEST['begin']) ? $_REQUEST['begin'] : false;
-$max = isset($_REQUEST['max']) ? $_REQUEST['max'] : false;
-$search = isset($_REQUEST['search']) ? $_REQUEST['search'] : false;
-$order = isset($_REQUEST['order']) ? $_REQUEST['order'] : false;
-$full = isset($_REQUEST['full']) ? $_REQUEST['full'] : false;
-$unapproved = isset($_REQUEST['unapproved']) ? $_REQUEST['unapproved'] : false;
+$id = $_REQUEST['id'] ?? false;
+$action = $_REQUEST['action'] ?? false;
+$in = $_REQUEST['in'] ?? false;
+$begin = $_REQUEST['begin'] ?? false;
+$max = $_REQUEST['max'] ?? false;
+$search = $_REQUEST['search'] ?? false;
+$order = $_REQUEST['order'] ?? false;
+$full = $_REQUEST['full'] ?? false;
+$unapproved = $_REQUEST['unapproved'] ?? false;
if($id) $id = (int)$id;
@@ -237,7 +237,7 @@
<?php
$begin = $begin ? (int)$begin : 0;
-$full = $full ? 1 : (!$full && ($search || $unapproved) ? 1 : 0);
+$full = $full ? 1 : (($search || $unapproved) ? 1 : 0);
$max = $max ? (int)$max : 20;
$forward = filter_input(INPUT_GET, "forward", FILTER_VALIDATE_INT) ?: 0;
diff --git a/public/manage/github.php b/public/manage/github.php
index 5eb401d..69c6e28 100644
--- a/public/manage/github.php
+++ b/public/manage/github.php
@@ -29,8 +29,7 @@ function github_api($endpoint, $method = 'GET', $options = [])
die('Request to GitHub failed. Endpoint: '.$endpoint);
}
- $retval = json_decode($s);
- return $retval;
+ return json_decode($s);
}
function github_current_user($access_token = false)
diff --git a/public/manage/user-notes.php b/public/manage/user-notes.php
index a0234c2..2b5ec79 100644
--- a/public/manage/user-notes.php
+++ b/public/manage/user-notes.php
@@ -275,10 +275,10 @@
echo "<p>No results found...</p>";
continue;
}
- $id = isset($row['id']) ? $row['id'] : null;
+ $id = $row['id'] ?? null;
/* This div is only available in cases where the query includes the
voting info */
if (isset($row['up']) && isset($row['down'])) {
- $rating = isset($row['arating']) ? $row['arating'] : ($row['up'] -
$row['down']);
+ $rating = $row['arating'] ?? ($row['up'] - $row['down']);
if ($rating < 0) {
$rating = "<span style=\"color: red;\">$rating</span>";
} elseif ($rating > 0) {
@@ -576,7 +576,7 @@
case 'preview':
case 'edit':
if ($id) {
- $note = (isset($_POST['note']) ? $_POST['note'] : null);
+ $note = $_POST['note'] ?? null;
if (!isset($note) || $action == 'preview') {
head("user notes");
}
@@ -602,7 +602,7 @@
}
}
- $note = isset($note) ? $note : $row['note'];
+ $note = $note ?? $row['note'];
if ($action == "preview") {
echo "<p class=\"notepreview\">",clean_note($note),
@@ -814,13 +814,11 @@ function clean_note($text)
$text = highlight_php(trim($text), TRUE);
// Turn urls into links
- $text = preg_replace(
+ return preg_replace(
'!((mailto:|(http|ftp|nntp|news):\/\/).*?)(\s|<|\)|"|\\|\'|$)!',
'<a href="\1" target="_blank">\1</a>\4',
$text
);
-
- return $text;
}
// Highlight PHP code
@@ -940,7 +938,7 @@ function wildcard_ip($ip)
}
foreach ($start as $key => $part) {
if (!isset($end[$key])) {
- $end[$key] = $start[$key];
+ $end[$key] = $part;
}
}
ksort($end);
diff --git a/scripts/index.php b/scripts/index.php
index 4b6dff4..27fbc67 100644
--- a/scripts/index.php
+++ b/scripts/index.php
@@ -1,3 +1,2 @@
<?php
-header("Location: https://php.net/");
-?>
+header("Location: https://php.net/");
\ No newline at end of file
--
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php