@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+7 -7
+1 -1
src/applications/auth/adapter/PhutilBitbucketAuthAdapter.php
··· 14 14 15 15 public function getAccountURI() { 16 16 $name = $this->getAccountID(); 17 - if (strlen($name)) { 17 + if (phutil_nonempty_string($name)) { 18 18 return 'https://bitbucket.org/'.$name; 19 19 } 20 20 return null;
+1 -1
src/applications/auth/adapter/PhutilGitHubAuthAdapter.php
··· 31 31 32 32 public function getAccountURI() { 33 33 $name = $this->getAccountName(); 34 - if (strlen($name)) { 34 + if (phutil_nonempty_string($name)) { 35 35 return 'https://github.com/'.$name; 36 36 } 37 37 return null;
+1 -1
src/applications/auth/adapter/PhutilTwitterAuthAdapter.php
··· 17 17 18 18 public function getAccountURI() { 19 19 $name = $this->getAccountName(); 20 - if (strlen($name)) { 20 + if (phutil_nonempty_string($name)) { 21 21 return 'https://twitter.com/'.$name; 22 22 } 23 23 return null;
+3 -3
src/applications/diffusion/query/lowlevel/DiffusionLowLevelCommitQuery.php
··· 126 126 $head = $parts[6]; 127 127 $tail = $parts[7]; 128 128 129 - if (strlen($head) && strlen($tail)) { 129 + if (phutil_nonempty_string($head) && phutil_nonempty_string($tail)) { 130 130 $body = $head."\n\n".$tail; 131 - } else if (strlen($head)) { 131 + } else if (phutil_nonempty_string($head)) { 132 132 $body = $head; 133 - } else if (strlen($tail)) { 133 + } else if (phutil_nonempty_string($tail)) { 134 134 $body = $tail; 135 135 } else { 136 136 $body = '';
+1 -1
src/infrastructure/markup/rule/PhabricatorKeyboardRemarkupRule.php
··· 22 22 foreach ($keys as $k => $v) { 23 23 $v = trim($v, " \n"); 24 24 $v = preg_replace('/\\\\(.)/', '\\1', $v); 25 - if (!strlen($v)) { 25 + if ($v === '') { 26 26 unset($keys[$k]); 27 27 continue; 28 28 }