1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 06:42:42 +01:00

Fix various potential PHP 8.1 "strlen(null)" exceptions

Summary:
`strlen()` was used in Phabricator to check if a generic value is a non-empty string.
This behavior is deprecated since PHP 8.1. Phorge adopts `phutil_nonempty_string()` as a replacement.

Note: this may highlight other absurd input values that might be worth correcting
instead of just ignoring. If phutil_nonempty_string() throws an exception in your
instance, report it to Phorge to evaluate and fix that specific corner case.

All lines changed in this patch had `Parameter #1 $string of function strlen expects string, string|null given` reported by PHPStan. Thus these should be safe to replace with `phutil_nonempty_string` as no calls care about the actual `strlen()` return value (length of a string).

Test Plan: Run static code analysis via `phpstan analyse -l 9`

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Differential Revision: https://we.phorge.it/D25778
This commit is contained in:
Andre Klapper 2024-08-14 21:52:57 +02:00
parent 66bd13b193
commit 9c684c80d6
5 changed files with 7 additions and 7 deletions

View file

@ -14,7 +14,7 @@ final class PhutilBitbucketAuthAdapter extends PhutilOAuth1AuthAdapter {
public function getAccountURI() { public function getAccountURI() {
$name = $this->getAccountID(); $name = $this->getAccountID();
if (strlen($name)) { if (phutil_nonempty_string($name)) {
return 'https://bitbucket.org/'.$name; return 'https://bitbucket.org/'.$name;
} }
return null; return null;

View file

@ -31,7 +31,7 @@ final class PhutilGitHubAuthAdapter extends PhutilOAuthAuthAdapter {
public function getAccountURI() { public function getAccountURI() {
$name = $this->getAccountName(); $name = $this->getAccountName();
if (strlen($name)) { if (phutil_nonempty_string($name)) {
return 'https://github.com/'.$name; return 'https://github.com/'.$name;
} }
return null; return null;

View file

@ -17,7 +17,7 @@ final class PhutilTwitterAuthAdapter extends PhutilOAuth1AuthAdapter {
public function getAccountURI() { public function getAccountURI() {
$name = $this->getAccountName(); $name = $this->getAccountName();
if (strlen($name)) { if (phutil_nonempty_string($name)) {
return 'https://twitter.com/'.$name; return 'https://twitter.com/'.$name;
} }
return null; return null;

View file

@ -126,11 +126,11 @@ final class DiffusionLowLevelCommitQuery
$head = $parts[6]; $head = $parts[6];
$tail = $parts[7]; $tail = $parts[7];
if (strlen($head) && strlen($tail)) { if (phutil_nonempty_string($head) && phutil_nonempty_string($tail)) {
$body = $head."\n\n".$tail; $body = $head."\n\n".$tail;
} else if (strlen($head)) { } else if (phutil_nonempty_string($head)) {
$body = $head; $body = $head;
} else if (strlen($tail)) { } else if (phutil_nonempty_string($tail)) {
$body = $tail; $body = $tail;
} else { } else {
$body = ''; $body = '';

View file

@ -22,7 +22,7 @@ final class PhabricatorKeyboardRemarkupRule extends PhutilRemarkupRule {
foreach ($keys as $k => $v) { foreach ($keys as $k => $v) {
$v = trim($v, " \n"); $v = trim($v, " \n");
$v = preg_replace('/\\\\(.)/', '\\1', $v); $v = preg_replace('/\\\\(.)/', '\\1', $v);
if (!strlen($v)) { if ($v === '') {
unset($keys[$k]); unset($keys[$k]);
continue; continue;
} }