Skip to content

Commit 40b272f

Browse files
committed
Addressing PHP8 incompatibilities - Miscellaneous
Summary: More perusing through Phabricator to find and address incompatibilities. Refs T13588 Test Plan: - Creating macros, changing their text. - Upload to use existing SSH key instead of generate one. - Modify alt text of an uploaded file. - Create phame post - Delete phriction document - Move tasks around on workboard, assign story points - Generate Diviner docs - Bulk modify tasks Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T13588 Differential Revision: https://secure.phabricator.com/D21869
1 parent dd94e2e commit 40b272f

29 files changed

+83
-66
lines changed

scripts/repository/commit_hook.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
exit($err);
120120
} else if ($repository->isGit() || $repository->isHg()) {
121121
$username = getenv(DiffusionCommitHookEngine::ENV_USER);
122-
if (!strlen($username)) {
122+
if ($username === null || !strlen($username)) {
123123
throw new Exception(
124124
pht(
125125
'No Direct Pushes: You are pushing directly to a hosted repository. '.
@@ -181,17 +181,17 @@
181181
$engine->setOriginalArgv(array_slice($argv, 2));
182182

183183
$remote_address = getenv(DiffusionCommitHookEngine::ENV_REMOTE_ADDRESS);
184-
if (strlen($remote_address)) {
184+
if ($remote_address !== false && strlen($remote_address)) {
185185
$engine->setRemoteAddress($remote_address);
186186
}
187187

188188
$remote_protocol = getenv(DiffusionCommitHookEngine::ENV_REMOTE_PROTOCOL);
189-
if (strlen($remote_protocol)) {
189+
if ($remote_protocol !== false && strlen($remote_protocol)) {
190190
$engine->setRemoteProtocol($remote_protocol);
191191
}
192192

193193
$request_identifier = getenv(DiffusionCommitHookEngine::ENV_REQUEST);
194-
if (strlen($request_identifier)) {
194+
if ($request_identifier !== false && strlen($request_identifier)) {
195195
$engine->setRequestIdentifier($request_identifier);
196196
}
197197

scripts/ssh/ssh-exec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
'--phabricator-ssh-device',
104104
$user_name,
105105
$device_name));
106-
} else if (strlen($user_name)) {
106+
} else if ($user_name !== null && strlen($user_name)) {
107107
$user = id(new PhabricatorPeopleQuery())
108108
->setViewer(PhabricatorUser::getOmnipotentUser())
109109
->withUsernames(array($user_name))
@@ -117,7 +117,7 @@
117117

118118
id(new PhabricatorAuthSessionEngine())
119119
->willServeRequestForUser($user);
120-
} else if (strlen($device_name)) {
120+
} else if ($device_name !== null && strlen($device_name)) {
121121
if (!$remote_address) {
122122
throw new Exception(
123123
pht(

src/aphront/response/AphrontAjaxResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function buildResponseString() {
6464
if ($viewer) {
6565
$postprocessor_key = $viewer->getUserSetting(
6666
PhabricatorAccessibilitySetting::SETTINGKEY);
67-
if (strlen($postprocessor_key)) {
67+
if ($postprocessor_key !== null && strlen($postprocessor_key)) {
6868
$response->setPostprocessorKey($postprocessor_key);
6969
}
7070
}

src/applications/auth/controller/PhabricatorAuthSSHKeyEditController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public function handleRequest(AphrontRequest $request) {
5454
$cancel_uri);
5555

5656
$v_name = $key->getName();
57-
$e_name = strlen($v_name) ? null : true;
57+
$e_name = $v_name !== null && strlen($v_name) ? null : true;
5858

5959
$v_key = $key->getEntireKey();
60-
$e_key = strlen($v_key) ? null : true;
60+
$e_key = $v_key !== null && strlen($v_key) ? null : true;
6161

6262
$validation_exception = null;
6363
if ($request->isFormPost()) {

src/applications/conduit/controller/PhabricatorConduitAPIController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ private function authenticateUser(
290290
}
291291

292292
$token_string = idx($metadata, 'token');
293-
if (strlen($token_string)) {
293+
if ($token_string !== null && strlen($token_string)) {
294294

295295
if (strlen($token_string) != 32) {
296296
return array(
@@ -683,7 +683,7 @@ private function decodeConduitParams(
683683
// Otherwise, look for a single parameter called 'params' which has the
684684
// entire param dictionary JSON encoded.
685685
$params_json = $request->getStr('params');
686-
if (strlen($params_json)) {
686+
if (phutil_nonempty_string($params_json)) {
687687
$params = null;
688688
try {
689689
$params = phutil_json_decode($params_json);

src/applications/diviner/atom/DivinerAtom.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,15 @@ public function getWarnings() {
8181
public function setDocblockRaw($docblock_raw) {
8282
$this->docblockRaw = $docblock_raw;
8383

84-
$parser = new PhutilDocblockParser();
85-
list($text, $meta) = $parser->parse($docblock_raw);
86-
$this->docblockText = $text;
87-
$this->docblockMeta = $meta;
84+
if ($docblock_raw !== null) {
85+
$parser = new PhutilDocblockParser();
86+
list($text, $meta) = $parser->parse($docblock_raw);
87+
$this->docblockText = $text;
88+
$this->docblockMeta = $meta;
89+
} else {
90+
$this->docblockText = null;
91+
$this->docblockMeta = null;
92+
}
8893

8994
return $this;
9095
}

src/applications/diviner/storage/DivinerLiveSymbol.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function getTitle() {
182182
public function setTitle($value) {
183183
$this->writeField('title', $value);
184184

185-
if (strlen($value)) {
185+
if ($value !== null && strlen($value)) {
186186
$slug = DivinerAtomRef::normalizeTitleString($value);
187187
$hash = PhabricatorHash::digestForIndex($slug);
188188
$this->titleSlugHash = $hash;

src/applications/diviner/workflow/DivinerGenerateWorkflow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private function generateBook($book, PhutilArgumentParser $args) {
194194

195195
$identifier = $args->getArg('repository');
196196
$repository = null;
197-
if (strlen($identifier)) {
197+
if ($identifier !== null && strlen($identifier)) {
198198
$repository = id(new PhabricatorRepositoryQuery())
199199
->setViewer(PhabricatorUser::getOmnipotentUser())
200200
->withIdentifiers(array($identifier))

src/applications/files/xaction/PhabricatorFileAltTextTransaction.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public function getTitle() {
2727
$old_value = $this->getOldValue();
2828
$new_value = $this->getNewValue();
2929

30-
if (!strlen($old_value)) {
30+
if ($old_value == null || !strlen($old_value)) {
3131
return pht(
3232
'%s set the alternate text for this file to %s.',
3333
$this->renderAuthor(),
3434
$this->renderNewValue());
35-
} else if (!strlen($new_value)) {
35+
} else if ($new_value === null || !strlen($new_value)) {
3636
return pht(
3737
'%s removed the alternate text for this file (was %s).',
3838
$this->renderAuthor(),
@@ -50,13 +50,13 @@ public function getTitleForFeed() {
5050
$old_value = $this->getOldValue();
5151
$new_value = $this->getNewValue();
5252

53-
if (!strlen($old_value)) {
53+
if ($old_value === null || !strlen($old_value)) {
5454
return pht(
5555
'%s set the alternate text for %s to %s.',
5656
$this->renderAuthor(),
5757
$this->renderObject(),
5858
$this->renderNewValue());
59-
} else if (!strlen($new_value)) {
59+
} else if ($new_value === null || !strlen($new_value)) {
6060
return pht(
6161
'%s removed the alternate text for %s (was %s).',
6262
$this->renderAuthor(),

src/applications/herald/typeahead/HeraldRuleDatasource.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ public function loadResults() {
2222
$query = id(new HeraldRuleQuery())
2323
->setViewer($viewer);
2424

25-
if (preg_match('/^[hH]\d+\z/', $raw_query)) {
26-
$id = trim($raw_query, 'hH');
27-
$id = (int)$id;
28-
$query->withIDs(array($id));
29-
} else {
30-
$query->withDatasourceQuery($raw_query);
25+
if ($raw_query !== null && strlen($raw_query)) {
26+
if (preg_match('/^[hH]\d+\z/', $raw_query)) {
27+
$id = trim($raw_query, 'hH');
28+
$id = (int)$id;
29+
$query->withIDs(array($id));
30+
} else {
31+
$query->withDatasourceQuery($raw_query);
32+
}
3133
}
3234

3335
$rules = $query->execute();

0 commit comments

Comments
 (0)