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:
parent
66bd13b193
commit
9c684c80d6
5 changed files with 7 additions and 7 deletions
|
@ -14,7 +14,7 @@ final class PhutilBitbucketAuthAdapter extends PhutilOAuth1AuthAdapter {
|
|||
|
||||
public function getAccountURI() {
|
||||
$name = $this->getAccountID();
|
||||
if (strlen($name)) {
|
||||
if (phutil_nonempty_string($name)) {
|
||||
return 'https://bitbucket.org/'.$name;
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -31,7 +31,7 @@ final class PhutilGitHubAuthAdapter extends PhutilOAuthAuthAdapter {
|
|||
|
||||
public function getAccountURI() {
|
||||
$name = $this->getAccountName();
|
||||
if (strlen($name)) {
|
||||
if (phutil_nonempty_string($name)) {
|
||||
return 'https://github.com/'.$name;
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -17,7 +17,7 @@ final class PhutilTwitterAuthAdapter extends PhutilOAuth1AuthAdapter {
|
|||
|
||||
public function getAccountURI() {
|
||||
$name = $this->getAccountName();
|
||||
if (strlen($name)) {
|
||||
if (phutil_nonempty_string($name)) {
|
||||
return 'https://twitter.com/'.$name;
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -126,11 +126,11 @@ final class DiffusionLowLevelCommitQuery
|
|||
$head = $parts[6];
|
||||
$tail = $parts[7];
|
||||
|
||||
if (strlen($head) && strlen($tail)) {
|
||||
if (phutil_nonempty_string($head) && phutil_nonempty_string($tail)) {
|
||||
$body = $head."\n\n".$tail;
|
||||
} else if (strlen($head)) {
|
||||
} else if (phutil_nonempty_string($head)) {
|
||||
$body = $head;
|
||||
} else if (strlen($tail)) {
|
||||
} else if (phutil_nonempty_string($tail)) {
|
||||
$body = $tail;
|
||||
} else {
|
||||
$body = '';
|
||||
|
|
|
@ -22,7 +22,7 @@ final class PhabricatorKeyboardRemarkupRule extends PhutilRemarkupRule {
|
|||
foreach ($keys as $k => $v) {
|
||||
$v = trim($v, " \n");
|
||||
$v = preg_replace('/\\\\(.)/', '\\1', $v);
|
||||
if (!strlen($v)) {
|
||||
if ($v === '') {
|
||||
unset($keys[$k]);
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue