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

Provide additional Arcanist PHP 8.1 fixes

Summary: Ref T13588. I pointed my local `php` at PHP 8.1 and this is what I've hit so far; all these cases seem very unlikely to have any subtle behavior.

Test Plan: Ran various `arc` workflows under PHP 8.1.

Maniphest Tasks: T13588

Differential Revision: https://secure.phabricator.com/D21742
This commit is contained in:
epriestley 2021-12-09 15:57:08 -08:00
parent 488f13a60e
commit b50a646a3f
21 changed files with 116 additions and 34 deletions

View file

@ -258,7 +258,7 @@ final class ArcanistConfigurationManager extends Phobject {
} }
public function getUserConfigurationFileLocation() { public function getUserConfigurationFileLocation() {
if (strlen($this->customArcrcFilename)) { if ($this->customArcrcFilename !== null) {
return $this->customArcrcFilename; return $this->customArcrcFilename;
} }

View file

@ -28,6 +28,8 @@ final class PhutilDirectoryFixture extends Phobject {
} }
public function getPath($to_file = null) { public function getPath($to_file = null) {
$to_file = phutil_string_cast($to_file);
return $this->path.'/'.ltrim($to_file, '/'); return $this->path.'/'.ltrim($to_file, '/');
} }

View file

@ -192,11 +192,18 @@ final class ExecFuture extends PhutilExecutableFuture {
* @task interact * @task interact
*/ */
public function read() { public function read() {
$stdout = $this->readStdout(); $stdout_value = $this->readStdout();
$stderr = $this->stderr;
if ($stderr === null) {
$stderr_value = '';
} else {
$stderr_value = substr($stderr, $this->stderrPos);
}
$result = array( $result = array(
$stdout, $stdout_value,
(string)substr($this->stderr, $this->stderrPos), $stderr_value,
); );
$this->stderrPos = $this->getStderrBufferLength(); $this->stderrPos = $this->getStderrBufferLength();
@ -209,7 +216,14 @@ final class ExecFuture extends PhutilExecutableFuture {
$this->updateFuture(); // Sync $this->updateFuture(); // Sync
} }
$result = (string)substr($this->stdout, $this->stdoutPos); $stdout = $this->stdout;
if ($stdout === null) {
$result = '';
} else {
$result = substr($stdout, $this->stdoutPos);
}
$this->stdoutPos = $this->getStdoutBufferLength(); $this->stdoutPos = $this->getStdoutBufferLength();
return $result; return $result;

View file

@ -27,7 +27,11 @@ final class ArcanistXMLLinter extends ArcanistLinter {
} }
public function getCacheVersion() { public function getCacheVersion() {
if (defined('LIBXML_VERSION')) {
return LIBXML_VERSION; return LIBXML_VERSION;
} else {
return 'unavailable';
}
} }
public function lintPath($path) { public function lintPath($path) {

View file

@ -51,6 +51,13 @@ abstract class ArcanistLinterTestCase extends PhutilTestCase {
private function lintFile($file, ArcanistLinter $linter) { private function lintFile($file, ArcanistLinter $linter) {
$linter = clone $linter; $linter = clone $linter;
if (!$linter->canRun()) {
$this->assertSkipped(
pht(
'Linter "%s" can not run.',
get_class($linter)));
}
$contents = Filesystem::readFile($file); $contents = Filesystem::readFile($file);
$contents = preg_split('/^~{4,}\n/m', $contents); $contents = preg_split('/^~{4,}\n/m', $contents);
if (count($contents) < 2) { if (count($contents) < 2) {
@ -283,9 +290,12 @@ abstract class ArcanistLinterTestCase extends PhutilTestCase {
} }
private function compareTransform($expected, $actual) { private function compareTransform($expected, $actual) {
$expected = phutil_string_cast($expected);
if (!strlen($expected)) { if (!strlen($expected)) {
return; return;
} }
$this->assertEqual( $this->assertEqual(
$expected, $expected,
$actual, $actual,

View file

@ -155,7 +155,9 @@ final class ArcanistPHPCompatibilityXHPASTLinterRule
if ($this->windowsVersion) { if ($this->windowsVersion) {
$windows = idx($compat_info['functions_windows'], $name); $windows = idx($compat_info['functions_windows'], $name);
if ($windows === false) { if ($windows === null) {
// This function has no special Windows considerations.
} else if ($windows === false) {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$node, $node,
pht( pht(

View file

@ -55,7 +55,12 @@ final class ArcanistParentMemberReferenceXHPASTLinterRule
} }
} }
if (version_compare($this->version, '5.4.0', '>=') || !$in_closure) { $version_target = $this->version;
if ($version_target === null) {
$version_target = phpversion();
}
if (version_compare($version_target, '5.4.0', '>=') || !$in_closure) {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$class_ref, $class_ref,
pht( pht(

View file

@ -42,7 +42,12 @@ final class ArcanistSelfMemberReferenceXHPASTLinterRule
} }
} }
if (version_compare($this->version, '5.4.0', '>=') || !$in_closure) { $version_target = $this->version;
if (!$version_target) {
$version_target = phpversion();
}
if (version_compare($version_target, '5.4.0', '>=') || !$in_closure) {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$class_ref, $class_ref,
pht( pht(

View file

@ -639,8 +639,7 @@ final class ArcanistBundle extends Phobject {
$old_path = $change->getOldPath(); $old_path = $change->getOldPath();
$type = $change->getType(); $type = $change->getType();
if (!strlen($old_path) || if ($old_path === '' || $type == ArcanistDiffChangeType::TYPE_ADD) {
$type == ArcanistDiffChangeType::TYPE_ADD) {
$old_path = null; $old_path = null;
} }
@ -1023,7 +1022,7 @@ final class ArcanistBundle extends Phobject {
if ($is_64bit) { if ($is_64bit) {
for ($count = 4; $count >= 0; $count--) { for ($count = 4; $count >= 0; $count--) {
$val = $accum % 85; $val = $accum % 85;
$accum = $accum / 85; $accum = (int)($accum / 85);
$slice .= $map[$val]; $slice .= $map[$val];
} }
} else { } else {

View file

@ -217,7 +217,7 @@ final class ArcanistDiffParser extends Phobject {
$line = $this->nextLine(); $line = $this->nextLine();
} }
if (strlen($message)) { if ($message !== null && strlen($message)) {
// If we found a message during pre-parse steps, add it to the resulting // If we found a message during pre-parse steps, add it to the resulting
// changes here. // changes here.
$change = $this->buildChange(null) $change = $this->buildChange(null)
@ -582,12 +582,15 @@ final class ArcanistDiffParser extends Phobject {
$ok = false; $ok = false;
$match = null; $match = null;
if ($line !== null) {
foreach ($patterns as $pattern) { foreach ($patterns as $pattern) {
$ok = preg_match('@^'.$pattern.'@', $line, $match); $ok = preg_match('@^'.$pattern.'@', $line, $match);
if ($ok) { if ($ok) {
break; break;
} }
} }
}
if (!$ok) { if (!$ok) {
if ($line === null || if ($line === null ||
@ -774,7 +777,7 @@ final class ArcanistDiffParser extends Phobject {
$this->nextLine(); $this->nextLine();
$this->parseGitBinaryPatch(); $this->parseGitBinaryPatch();
$line = $this->getLine(); $line = $this->getLine();
if (preg_match('/^literal/', $line)) { if ($line !== null && preg_match('/^literal/', $line)) {
// We may have old/new binaries (change) or just a new binary (hg add). // We may have old/new binaries (change) or just a new binary (hg add).
// If there are two blocks, parse both. // If there are two blocks, parse both.
$this->parseGitBinaryPatch(); $this->parseGitBinaryPatch();
@ -920,11 +923,11 @@ final class ArcanistDiffParser extends Phobject {
$hunk->setNewOffset($matches[3]); $hunk->setNewOffset($matches[3]);
// Cover for the cases where length wasn't present (implying one line). // Cover for the cases where length wasn't present (implying one line).
$old_len = idx($matches, 2); $old_len = idx($matches, 2, '');
if (!strlen($old_len)) { if (!strlen($old_len)) {
$old_len = 1; $old_len = 1;
} }
$new_len = idx($matches, 4); $new_len = idx($matches, 4, '');
if (!strlen($new_len)) { if (!strlen($new_len)) {
$new_len = 1; $new_len = 1;
} }
@ -1041,7 +1044,7 @@ final class ArcanistDiffParser extends Phobject {
$line = $this->nextNonemptyLine(); $line = $this->nextNonemptyLine();
} }
} while (preg_match('/^@@ /', $line)); } while (($line !== null) && preg_match('/^@@ /', $line));
} }
protected function buildChange($path = null) { protected function buildChange($path = null) {

View file

@ -85,7 +85,7 @@ final class PhutilBugtraqParser extends Phobject {
$captured_text = $capture['text']; $captured_text = $capture['text'];
$captured_offset = $capture['at']; $captured_offset = $capture['at'];
if (strlen($select_regexp)) { if ($select_regexp !== null) {
$selections = null; $selections = null;
preg_match_all( preg_match_all(
$select_regexp, $select_regexp,

View file

@ -13,6 +13,7 @@ final class PhutilEmailAddress extends Phobject {
private $domainName; private $domainName;
public function __construct($email_address = null) { public function __construct($email_address = null) {
$email_address = phutil_string_cast($email_address);
$email_address = trim($email_address); $email_address = trim($email_address);
$matches = null; $matches = null;
@ -89,7 +90,7 @@ final class PhutilEmailAddress extends Phobject {
public function getAddress() { public function getAddress() {
$address = $this->localPart; $address = $this->localPart;
if (strlen($this->domainName)) { if ($this->domainName !== null && strlen($this->domainName)) {
$address .= '@'.$this->domainName; $address .= '@'.$this->domainName;
} }
return $address; return $address;

View file

@ -171,14 +171,19 @@ final class PhutilURI extends Phobject {
} }
} }
if (strlen($protocol) || strlen($auth) || strlen($domain)) { $has_protocol = ($protocol !== null) && strlen($protocol);
$has_auth = ($auth !== null);
$has_domain = ($domain !== null) && strlen($domain);
$has_port = ($port !== null) && strlen($port);
if ($has_protocol || $has_auth || $has_domain) {
if ($this->isGitURI()) { if ($this->isGitURI()) {
$prefix = "{$auth}{$domain}"; $prefix = "{$auth}{$domain}";
} else { } else {
$prefix = "{$protocol}://{$auth}{$domain}"; $prefix = "{$protocol}://{$auth}{$domain}";
} }
if (strlen($port)) { if ($has_port) {
$prefix .= ':'.$port; $prefix .= ':'.$port;
} }
} }

View file

@ -80,6 +80,7 @@ final class AASTNodeList
/* -( Countable )---------------------------------------------------------- */ /* -( Countable )---------------------------------------------------------- */
#[\ReturnTypeWillChange]
public function count() { public function count() {
return count($this->ids); return count($this->ids);
} }
@ -87,22 +88,27 @@ final class AASTNodeList
/* -( Iterator )----------------------------------------------------------- */ /* -( Iterator )----------------------------------------------------------- */
#[\ReturnTypeWillChange]
public function current() { public function current() {
return $this->list[$this->key()]; return $this->list[$this->key()];
} }
#[\ReturnTypeWillChange]
public function key() { public function key() {
return $this->ids[$this->pos]; return $this->ids[$this->pos];
} }
#[\ReturnTypeWillChange]
public function next() { public function next() {
$this->pos++; $this->pos++;
} }
#[\ReturnTypeWillChange]
public function rewind() { public function rewind() {
$this->pos = 0; $this->pos = 0;
} }
#[\ReturnTypeWillChange]
public function valid() { public function valid() {
return $this->pos < count($this->ids); return $this->pos < count($this->ids);
} }

View file

@ -137,7 +137,7 @@ final class PhutilServiceProfiler extends Phobject {
$uri = phutil_censor_credentials($data['uri']); $uri = phutil_censor_credentials($data['uri']);
if (strlen($proxy)) { if ($proxy !== null) {
$desc = "{$proxy} >> {$uri}"; $desc = "{$proxy} >> {$uri}";
} else { } else {
$desc = $uri; $desc = $uri;
@ -203,6 +203,10 @@ final class PhutilServiceProfiler extends Phobject {
} }
private static function escapeProfilerStringForDisplay($string) { private static function escapeProfilerStringForDisplay($string) {
if ($string === null) {
return '';
}
// Convert tabs and newlines to spaces and collapse blocks of whitespace, // Convert tabs and newlines to spaces and collapse blocks of whitespace,
// most often formatting in queries. // most often formatting in queries.
$string = preg_replace('/\s{2,}/', ' ', $string); $string = preg_replace('/\s{2,}/', ' ', $string);

View file

@ -65,9 +65,10 @@ final class ArcanistUnitConsoleRenderer extends ArcanistUnitRenderer {
50 => "<fg:green>%s</fg><fg:yellow>{$star}</fg> ", 50 => "<fg:green>%s</fg><fg:yellow>{$star}</fg> ",
200 => '<fg:green>%s</fg> ', 200 => '<fg:green>%s</fg> ',
500 => '<fg:yellow>%s</fg> ', 500 => '<fg:yellow>%s</fg> ',
INF => '<fg:red>%s</fg> ',
); );
$least_acceptable = '<fg:red>%s</fg> ';
$milliseconds = $seconds * 1000; $milliseconds = $seconds * 1000;
$duration = $this->formatTime($seconds); $duration = $this->formatTime($seconds);
foreach ($acceptableness as $upper_bound => $formatting) { foreach ($acceptableness as $upper_bound => $formatting) {
@ -75,7 +76,8 @@ final class ArcanistUnitConsoleRenderer extends ArcanistUnitRenderer {
return phutil_console_format($formatting, $duration); return phutil_console_format($formatting, $duration);
} }
} }
return phutil_console_format(end($acceptableness), $duration);
return phutil_console_format($least_acceptable, $duration);
} }
private function formatTime($seconds) { private function formatTime($seconds) {

View file

@ -29,6 +29,7 @@ abstract class PhutilArray
/* -( Countable Interface )------------------------------------------------ */ /* -( Countable Interface )------------------------------------------------ */
#[\ReturnTypeWillChange]
public function count() { public function count() {
return count($this->data); return count($this->data);
} }
@ -37,22 +38,27 @@ abstract class PhutilArray
/* -( Iterator Interface )------------------------------------------------- */ /* -( Iterator Interface )------------------------------------------------- */
#[\ReturnTypeWillChange]
public function current() { public function current() {
return current($this->data); return current($this->data);
} }
#[\ReturnTypeWillChange]
public function key() { public function key() {
return key($this->data); return key($this->data);
} }
#[\ReturnTypeWillChange]
public function next() { public function next() {
return next($this->data); return next($this->data);
} }
#[\ReturnTypeWillChange]
public function rewind() { public function rewind() {
reset($this->data); reset($this->data);
} }
#[\ReturnTypeWillChange]
public function valid() { public function valid() {
return (key($this->data) !== null); return (key($this->data) !== null);
} }
@ -61,18 +67,22 @@ abstract class PhutilArray
/* -( ArrayAccess Interface )---------------------------------------------- */ /* -( ArrayAccess Interface )---------------------------------------------- */
#[\ReturnTypeWillChange]
public function offsetExists($key) { public function offsetExists($key) {
return array_key_exists($key, $this->data); return array_key_exists($key, $this->data);
} }
#[\ReturnTypeWillChange]
public function offsetGet($key) { public function offsetGet($key) {
return $this->data[$key]; return $this->data[$key];
} }
#[\ReturnTypeWillChange]
public function offsetSet($key, $value) { public function offsetSet($key, $value) {
$this->data[$key] = $value; $this->data[$key] = $value;
} }
#[\ReturnTypeWillChange]
public function offsetUnset($key) { public function offsetUnset($key) {
unset($this->data[$key]); unset($this->data[$key]);
} }

View file

@ -18,6 +18,7 @@ final class PhutilCallbackFilterIterator extends FilterIterator {
$this->callback = $callback; $this->callback = $callback;
} }
#[\ReturnTypeWillChange]
public function accept() { public function accept() {
return call_user_func($this->callback, $this->current()); return call_user_func($this->callback, $this->current());
} }

View file

@ -701,7 +701,7 @@ EOTEXT
$this->revisionID = $revision_id; $this->revisionID = $revision_id;
$revision['message'] = $this->getArgument('message'); $revision['message'] = $this->getArgument('message');
if (!strlen($revision['message'])) { if ($revision['message'] === null) {
$update_messages = $this->readScratchJSONFile('update-messages.json'); $update_messages = $this->readScratchJSONFile('update-messages.json');
$update_messages[$revision_id] = $this->getUpdateMessage( $update_messages[$revision_id] = $this->getUpdateMessage(
@ -1740,9 +1740,12 @@ EOTEXT
if ($template == '') { if ($template == '') {
$comments = $this->getDefaultUpdateMessage(); $comments = $this->getDefaultUpdateMessage();
$comments = phutil_string_cast($comments);
$comments = rtrim($comments);
$template = sprintf( $template = sprintf(
"%s\n\n# %s\n#\n# %s\n# %s\n#\n# %s\n# $ %s\n\n", "%s\n\n# %s\n#\n# %s\n# %s\n#\n# %s\n# $ %s\n\n",
rtrim($comments), $comments,
pht( pht(
'Updating %s: %s', 'Updating %s: %s',
"D{$fields['revisionID']}", "D{$fields['revisionID']}",
@ -2360,7 +2363,7 @@ EOTEXT
if (strlen($branch)) { if (strlen($branch)) {
$upstream_path = $api->getPathToUpstream($branch); $upstream_path = $api->getPathToUpstream($branch);
$remote_branch = $upstream_path->getRemoteBranchName(); $remote_branch = $upstream_path->getRemoteBranchName();
if (strlen($remote_branch)) { if ($remote_branch !== null) {
return array( return array(
array( array(
'type' => 'branch', 'type' => 'branch',
@ -2374,7 +2377,7 @@ EOTEXT
// If "arc.land.onto.default" is configured, use that. // If "arc.land.onto.default" is configured, use that.
$config_key = 'arc.land.onto.default'; $config_key = 'arc.land.onto.default';
$onto = $this->getConfigFromAnySource($config_key); $onto = $this->getConfigFromAnySource($config_key);
if (strlen($onto)) { if ($onto !== null) {
return array( return array(
array( array(
'type' => 'branch', 'type' => 'branch',

View file

@ -154,7 +154,7 @@ abstract class ArcanistWorkflow extends Phobject {
} }
$help = $information->getHelp(); $help = $information->getHelp();
if (strlen($help)) { if ($help !== null) {
// Unwrap linebreaks in the help text so we don't get weird formatting. // Unwrap linebreaks in the help text so we don't get weird formatting.
$help = preg_replace("/(?<=\S)\n(?=\S)/", ' ', $help); $help = preg_replace("/(?<=\S)\n(?=\S)/", ' ', $help);

View file

@ -219,7 +219,13 @@ foreach ($calls as $call) {
$symbol = array_shift($params); $symbol = array_shift($params);
$type = 'function'; $type = 'function';
$symbol_value = $symbol->getStringLiteralValue(); $symbol_value = $symbol->getStringLiteralValue();
if ($symbol_value !== null) {
$pos = strpos($symbol_value, '::'); $pos = strpos($symbol_value, '::');
} else {
$pos = false;
}
if ($pos) { if ($pos) {
$type = 'class'; $type = 'class';
$symbol_value = substr($symbol_value, 0, $pos); $symbol_value = substr($symbol_value, 0, $pos);