@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.

PHP 8.2: fixes for strlen() not accepting NULL anymore, part 1

Summary:
This change avoids some unnecessary uses of the strlen() function,
actually fixing some deprecation warnings in PHP 8.2.

In short, this is the suggested universal replace:

-if(strlen($v))
+if(phutil_nonempty_string($v))

And, if you know PHP, this is also another adoptable replace, but
only for cases where you are sure that the string "0" is not useful:

-if(strlen($v))
+if($v))

As usual the optimal solution depends on the contest.

Other similar patches will probably follow.

Closes T15222
Ref T15190

Test Plan:
- for the first time in my life, with this change, the unit tests are passed in PHP 8.2
- check with your big eyes that there are no obvious typos

Reviewers: O1 Blessed Committers, avivey

Reviewed By: O1 Blessed Committers, avivey

Subscribers: avivey, speck, tobiaswiese, Matthew, Cigaryno

Maniphest Tasks: T15199, T15190, T15222

Differential Revision: https://we.phorge.it/D25104

+28 -27
+4 -4
src/applications/config/check/PhabricatorStorageSetupCheck.php
··· 151 151 152 152 $how_many = 0; 153 153 154 - if (strlen($access_key)) { 154 + if (phutil_nonempty_string($access_key)) { 155 155 $how_many++; 156 156 } 157 157 158 - if (strlen($secret_key)) { 158 + if (phutil_nonempty_string($secret_key)) { 159 159 $how_many++; 160 160 } 161 161 162 - if (strlen($region)) { 162 + if (phutil_nonempty_string($region)) { 163 163 $how_many++; 164 164 } 165 165 166 - if (strlen($endpoint)) { 166 + if (phutil_nonempty_string($endpoint)) { 167 167 $how_many++; 168 168 } 169 169
+6 -6
src/applications/files/engine/PhabricatorS3FileStorageEngine.php
··· 31 31 $endpoint = PhabricatorEnv::getEnvConfig('amazon-s3.endpoint'); 32 32 $region = PhabricatorEnv::getEnvConfig('amazon-s3.region'); 33 33 34 - return (strlen($bucket) && 35 - strlen($access_key) && 36 - strlen($secret_key) && 37 - strlen($endpoint) && 38 - strlen($region)); 34 + return phutil_nonempty_string($bucket) && 35 + phutil_nonempty_string($access_key) && 36 + phutil_nonempty_string($secret_key) && 37 + phutil_nonempty_string($endpoint) && 38 + phutil_nonempty_string($region); 39 39 } 40 40 41 41 ··· 57 57 $parts[] = 'phabricator'; 58 58 59 59 $instance_name = PhabricatorEnv::getEnvConfig('cluster.instance'); 60 - if (strlen($instance_name)) { 60 + if (phutil_nonempty_string($instance_name)) { 61 61 $parts[] = $instance_name; 62 62 } 63 63
+2 -2
src/applications/files/storage/PhabricatorFile.php
··· 856 856 // instance identity in the path allows us to distinguish between requests 857 857 // originating from different instances but served through the same CDN. 858 858 $instance = PhabricatorEnv::getEnvConfig('cluster.instance'); 859 - if (strlen($instance)) { 859 + if (phutil_nonempty_string($instance)) { 860 860 $parts[] = '@'.$instance; 861 861 } 862 862 ··· 903 903 $parts[] = 'xform'; 904 904 905 905 $instance = PhabricatorEnv::getEnvConfig('cluster.instance'); 906 - if (strlen($instance)) { 906 + if (phutil_nonempty_string($instance)) { 907 907 $parts[] = '@'.$instance; 908 908 } 909 909
+2 -2
src/applications/metamta/engine/PhabricatorMailEmailEngine.php
··· 507 507 public function newDefaultEmailAddress() { 508 508 $raw_address = PhabricatorEnv::getEnvConfig('metamta.default-address'); 509 509 510 - if (!strlen($raw_address)) { 510 + if (!$raw_address) { 511 511 $domain = $this->newMailDomain(); 512 512 $raw_address = "noreply@{$domain}"; 513 513 } ··· 527 527 528 528 private function newMailDomain() { 529 529 $domain = PhabricatorEnv::getEnvConfig('metamta.reply-handler-domain'); 530 - if (strlen($domain)) { 530 + if ($domain) { 531 531 return $domain; 532 532 } 533 533
+1 -1
src/applications/notification/client/PhabricatorNotificationServerRef.php
··· 152 152 ->setPath($full_path); 153 153 154 154 $instance = PhabricatorEnv::getEnvConfig('cluster.instance'); 155 - if (strlen($instance)) { 155 + if (phutil_nonempty_string($instance)) { 156 156 $uri->replaceQueryParam('instance', $instance); 157 157 } 158 158
+1 -1
src/applications/repository/engine/PhabricatorRepositoryPullEngine.php
··· 238 238 $identifier = $repository->getPHID(); 239 239 240 240 $instance = PhabricatorEnv::getEnvConfig('cluster.instance'); 241 - if (strlen($instance)) { 241 + if (phutil_nonempty_string($instance)) { 242 242 $identifier = "{$identifier}:{$instance}"; 243 243 } 244 244
+2 -1
src/applications/repository/storage/PhabricatorRepository.php
··· 2480 2480 $has_https = false; 2481 2481 } 2482 2482 2483 - $has_ssh = (bool)strlen(PhabricatorEnv::getEnvConfig('phd.user')); 2483 + $phd_user = PhabricatorEnv::getEnvConfig('phd.user'); 2484 + $has_ssh = phutil_nonempty_string($phd_user); 2484 2485 2485 2486 $protocol_map = array( 2486 2487 PhabricatorRepositoryURI::BUILTIN_PROTOCOL_SSH => $has_ssh,
+1 -1
src/infrastructure/cluster/PhabricatorDatabaseRef.php
··· 229 229 $host = $this->getHost(); 230 230 231 231 $port = $this->getPort(); 232 - if (strlen($port)) { 232 + if ($port) { 233 233 return "{$host}:{$port}"; 234 234 } 235 235
+8 -8
src/infrastructure/env/PhabricatorEnv.php
··· 125 125 // If an instance identifier is defined, write it into the environment so 126 126 // it's available to subprocesses. 127 127 $instance = self::getEnvConfig('cluster.instance'); 128 - if (strlen($instance)) { 128 + if (phutil_nonempty_string($instance)) { 129 129 putenv('PHABRICATOR_INSTANCE='.$instance); 130 130 $_ENV['PHABRICATOR_INSTANCE'] = $instance; 131 131 } ··· 432 432 $uri = new PhutilURI($raw_uri); 433 433 434 434 $host = $uri->getDomain(); 435 - if (!strlen($host)) { 435 + if (!phutil_nonempty_string($host)) { 436 436 return false; 437 437 } 438 438 ··· 455 455 $self_map = array(); 456 456 foreach ($self_uris as $self_uri) { 457 457 $host = id(new PhutilURI($self_uri))->getDomain(); 458 - if (!strlen($host)) { 458 + if (!phutil_nonempty_string($host)) { 459 459 continue; 460 460 } 461 461 ··· 661 661 public static function isValidLocalURIForLink($uri) { 662 662 $uri = (string)$uri; 663 663 664 - if (!strlen($uri)) { 664 + if (!phutil_nonempty_string($uri)) { 665 665 return false; 666 666 } 667 667 ··· 726 726 $uri = new PhutilURI($raw_uri); 727 727 728 728 $proto = $uri->getProtocol(); 729 - if (!strlen($proto)) { 729 + if (!$proto) { 730 730 throw new Exception( 731 731 pht( 732 732 'URI "%s" is not a valid linkable resource. A valid linkable '. ··· 745 745 } 746 746 747 747 $domain = $uri->getDomain(); 748 - if (!strlen($domain)) { 748 + if (!$domain) { 749 749 throw new Exception( 750 750 pht( 751 751 'URI "%s" is not a valid linkable resource. A valid linkable '. ··· 793 793 $uri = new PhutilURI($raw_uri); 794 794 795 795 $proto = $uri->getProtocol(); 796 - if (!strlen($proto)) { 796 + if (!$proto) { 797 797 throw new Exception( 798 798 pht( 799 799 'URI "%s" is not a valid fetchable resource. A valid fetchable '. ··· 812 812 } 813 813 814 814 $domain = $uri->getDomain(); 815 - if (!strlen($domain)) { 815 + if (!$domain) { 816 816 throw new Exception( 817 817 pht( 818 818 'URI "%s" is not a valid fetchable resource. A valid fetchable '.
+1 -1
src/infrastructure/log/PhabricatorSSHLog.php
··· 24 24 ); 25 25 26 26 $sudo_user = PhabricatorEnv::getEnvConfig('phd.user'); 27 - if (strlen($sudo_user)) { 27 + if (phutil_nonempty_string($sudo_user)) { 28 28 $data['S'] = $sudo_user; 29 29 } 30 30