@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

Fix some potentially undefined variables

Summary:
Fix 17 trivial "Variable might not be defined" issues found by PHPStan static code analysis to have a little bit less noise (there are many more which makes it harder to find real problems). Defensive programming yadda yadda.

```
Line src/applications/people/controller/PhabricatorPeopleInviteSendController.php
136 Variable $actions might not be defined.
146 Variable $any_valid might not be defined.
Line src/applications/phid/query/PhabricatorObjectListQuery.php
203 Variable $suffix_map might not be defined.
Line src/applications/search/engine/PhabricatorProfileMenuEngine.php
420 Variable $builtins might not be defined.
Line support/startup/PhabricatorClientLimit.php
204 Variable $bucket might not be defined.
241 Variable $min might not be defined.
Line src/view/phui/PHUIRemarkupPreviewPanel.php
114 Variable $content might not be defined.
Line src/view/phui/PHUIInfoView.php
109 Variable $icon might not be defined.
Line src/view/phui/PHUICurtainObjectRefView.php
237 Variable $icon_view might not be defined.
Line src/applications/maniphest/conduit/ManiphestConduitAPIMethod.php
161 Variable $comments might not be defined.
Line src/applications/people/typeahead/PhabricatorPeopleDatasource.php
75 Variable $handles might not be defined.
Line src/applications/settings/controller/PhabricatorSettingsMainController.php
117 Variable $user might not be defined.
Line src/applications/files/engine/PhabricatorFileStorageEngine.php
327 Variable $engine might not be defined.
Line src/infrastructure/cache/PhutilAPCKeyValueCache.php
33 Variable $result might not be defined.
Line src/applications/config/engine/PhabricatorSetupEngine.php
50 Variable $issue might not be defined.
Line src/applications/diffusion/management/DiffusionRepositoryStorageManagementPanel.php
314 Variable $refs might not be defined.
Line src/applications/diffusion/DiffusionLintSaveRunner.php
123 Variable $all_files might not be defined.
```

Test Plan: Read the code; run static code analysis before and after.

Reviewers: O1 Blessed Committers, mainframe98

Reviewed By: O1 Blessed Committers, mainframe98

Subscribers: mainframe98, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

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

+24 -14
+1 -1
src/applications/config/engine/PhabricatorSetupEngine.php
··· 47 47 // because data may be at risk. 48 48 PhabricatorSetupCheck::resetSetupState(); 49 49 50 - return PhabricatorSetupCheck::newIssueResponse($issue); 50 + return PhabricatorSetupCheck::newIssueResponse($fatal_issue); 51 51 } 52 52 53 53 $issue_keys = PhabricatorSetupCheck::getUnignoredIssueKeys($issues);
+1
src/applications/diffusion/DiffusionLintSaveRunner.php
··· 91 91 $this->lintCommit = $this->branch->getLintCommit(); 92 92 } 93 93 94 + $all_files = array(); 94 95 if ($this->lintCommit) { 95 96 try { 96 97 $commit = $this->lintCommit;
+2 -1
src/applications/diffusion/management/DiffusionRepositoryStorageManagementPanel.php
··· 292 292 $viewer = $this->getViewer(); 293 293 294 294 $caught = null; 295 + $refs = array(); 296 + 295 297 try { 296 298 $refs = $repository->getAlmanacServiceRefs($viewer, $options); 297 299 } catch (Exception $ex) { ··· 302 304 303 305 $info_view = null; 304 306 if ($caught) { 305 - $refs = array(); 306 307 $info_view = id(new PHUIInfoView()) 307 308 ->setErrors( 308 309 array(
+1 -1
src/applications/files/engine/PhabricatorFileStorageEngine.php
··· 320 320 } 321 321 } 322 322 323 - if (!$min) { 323 + if (!$min || !isset($engine)) { 324 324 return null; 325 325 } 326 326
+2 -1
src/applications/maniphest/conduit/ManiphestConduitAPIMethod.php
··· 157 157 foreach ($changes as $type => $value) { 158 158 $transaction = clone $template; 159 159 $transaction->setTransactionType($type); 160 - if ($type == PhabricatorTransactions::TYPE_COMMENT) { 160 + if ($type == PhabricatorTransactions::TYPE_COMMENT && 161 + isset($comments)) { 161 162 $transaction->attachComment( 162 163 id(new ManiphestTransactionComment()) 163 164 ->setContent($comments));
+5 -2
src/applications/people/controller/PhabricatorPeopleInviteSendController.php
··· 17 17 $message = $request->getStr('message'); 18 18 $emails = $request->getStr('emails'); 19 19 $severity = PHUIInfoView::SEVERITY_ERROR; 20 + 21 + $any_valid = false; 22 + $all_valid = true; 23 + $actions = null; 24 + 20 25 if ($request->isFormPost()) { 21 26 // NOTE: We aren't using spaces as a delimiter here because email 22 27 // addresses with names often include spaces. ··· 42 47 $viewer, 43 48 $email_list); 44 49 45 - $any_valid = false; 46 - $all_valid = true; 47 50 foreach ($actions as $action) { 48 51 if ($action->willSend()) { 49 52 $any_valid = true;
+1
src/applications/people/typeahead/PhabricatorPeopleDatasource.php
··· 35 35 $users = $this->executeQuery($query); 36 36 37 37 $is_browse = $this->getIsBrowse(); 38 + $handles = array(); 38 39 39 40 if ($is_browse && $users) { 40 41 $phids = mpull($users, 'getPHID');
+1 -1
src/applications/phid/query/PhabricatorObjectListQuery.php
··· 100 100 // If we're parsing with suffixes, strip them off any tokens and keep 101 101 // track of them for later. 102 102 $suffixes = $this->getSuffixes(); 103 + $suffix_map = array(); 103 104 if ($suffixes) { 104 105 $suffixes = array_fuse($suffixes); 105 - $suffix_map = array(); 106 106 $stripped_map = array(); 107 107 foreach ($name_map as $key => $name) { 108 108 $found_suffixes = array();
+1 -1
src/applications/search/engine/PhabricatorProfileMenuEngine.php
··· 392 392 393 393 private function loadBuiltinProfileItems($mode) { 394 394 $object = $this->getProfileObject(); 395 + $builtins = array(); 395 396 396 397 switch ($mode) { 397 398 case self::MODE_GLOBAL: ··· 403 404 $this->getCustomPHID()); 404 405 break; 405 406 case self::MODE_COMBINED: 406 - $builtins = array(); 407 407 $builtins[] = $this->getBuiltinCustomProfileItems( 408 408 $object, 409 409 $this->getCustomPHID());
+1 -1
src/applications/settings/controller/PhabricatorSettingsMainController.php
··· 114 114 $crumbs->addTextCrumb($panel->getPanelName()); 115 115 $crumbs->setBorder(true); 116 116 117 - if ($this->user) { 117 + if (isset($user)) { 118 118 $header_text = pht('Edit Settings: %s', $user->getUserName()); 119 119 } else { 120 120 $header_text = pht('Edit Global Settings');
+3 -3
src/infrastructure/cache/PhutilAPCKeyValueCache.php
··· 25 25 $results = array(); 26 26 $fetched = false; 27 27 foreach ($keys as $key) { 28 - if ($is_apcu) { 29 - $result = apcu_fetch($key, $fetched); 28 + if (!$is_apcu) { 29 + continue; 30 30 } 31 - 31 + $result = apcu_fetch($key, $fetched); 32 32 if ($fetched) { 33 33 $results[$key] = $result; 34 34 }
+1
src/view/phui/PHUICurtainObjectRefView.php
··· 227 227 } 228 228 229 229 private function newIconView() { 230 + $icon_view = null; 230 231 $handle = $this->handle; 231 232 232 233 if ($handle) {
+1
src/view/phui/PHUIInfoView.php
··· 84 84 return $this->icon; 85 85 } 86 86 87 + $icon = null; 87 88 switch ($this->getSeverity()) { 88 89 case self::SEVERITY_ERROR: 89 90 $icon = 'fa-exclamation-circle';
+1
src/view/phui/PHUIRemarkupPreviewPanel.php
··· 89 89 ), 90 90 $loading); 91 91 92 + $content = null; 92 93 if (!$this->previewType) { 93 94 $header = null; 94 95 if ($this->header) {
+2 -2
support/startup/PhabricatorClientLimit.php
··· 201 201 $bucket = apcu_fetch($bucket_key); 202 202 } 203 203 204 - if (!is_array($bucket)) { 204 + if (!isset($bucket) || !is_array($bucket)) { 205 205 $bucket = array(); 206 206 } 207 207 ··· 238 238 // If we don't have any buckets stored yet, store the current bucket as 239 239 // the oldest bucket. 240 240 $cur = $this->getCurrentBucketID(); 241 - if (!$min) { 241 + if (!isset($min) || !$min) { 242 242 if ($is_apcu) { 243 243 @apcu_store($min_key, $cur); 244 244 }