Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/typeahead/PhabricatorProjectDatasource.php
| Show First 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | foreach ($projs as $proj) { | ||||
| $closed = pht('Archived'); | $closed = pht('Archived'); | ||||
| } | } | ||||
| $all_strings = array(); | $all_strings = array(); | ||||
| // NOTE: We list the project's name first because results will be | // NOTE: We list the project's name first because results will be | ||||
| // sorted into prefix vs content phases incorrectly if we don't: it | // sorted into prefix vs content phases incorrectly if we don't: it | ||||
| // will look like "Parent (Milestone)" matched "Parent" as a prefix, | // will look like "Parent (Milestone)" matched "Parent" as a prefix, | ||||
| // but it did not. | // but it did not. | ||||
| $all_strings[] = $proj->getName(); | $all_strings[] = $proj->getName(); | ||||
| if ($proj->isMilestone()) { | if ($proj->isMilestone()) { | ||||
sergey: This is what the `mpull` is for. From it's documentation:
COUNTEREXAMPLE
$names =… | |||||
| $all_strings[] = $proj->getParentProject()->getName(); | $all_strings[] = $proj->getParentProject()->getName(); | ||||
| } | } | ||||
Done Inline ActionsThere are cheaper ways to check whether string is empty. sergey: There are cheaper ways to check whether string is empty. | |||||
Done Inline ActionsThere is no need for this. Just append $proj->getDisplayName() to the end of the array and run implode once, without any further exception code paths. You would then need need to rename variable to something like $project_name_path or something like this since it's no longer an ancestor. Also, should probably be pht(implode(...)) sergey: There is no need for this.
Just append `$proj->getDisplayName()` to the end of the array and… | |||||
| foreach ($proj->getSlugs() as $project_slug) { | foreach ($proj->getSlugs() as $project_slug) { | ||||
| $all_strings[] = $project_slug->getSlug(); | $all_strings[] = $project_slug->getSlug(); | ||||
| } | } | ||||
| $all_strings = implode("\n", $all_strings); | $all_strings = implode("\n", $all_strings); | ||||
| $proj_result = id(new PhabricatorTypeaheadResult()) | $proj_result = id(new PhabricatorTypeaheadResult()) | ||||
| ->setName($all_strings) | ->setName($all_strings) | ||||
| ->setDisplayName($proj->getDisplayName()) | ->setDisplayName($proj->getDisplayNameWithAncestorPath()) | ||||
| ->setDisplayType($proj->getDisplayIconName()) | ->setDisplayType($proj->getDisplayIconName()) | ||||
| ->setURI($proj->getURI()) | ->setURI($proj->getURI()) | ||||
| ->setPHID($phid) | ->setPHID($phid) | ||||
| ->setIcon($proj->getDisplayIconIcon()) | ->setIcon($proj->getDisplayIconIcon()) | ||||
| ->setColor($proj->getColor()) | ->setColor($proj->getColor()) | ||||
| ->setPriorityType('proj') | ->setPriorityType('proj') | ||||
| ->setClosed($closed); | ->setClosed($closed); | ||||
| Show All 23 Lines | |||||
This is what the mpull is for. From it's documentation:
$names = array(); foreach ($objects as $key => $object) { $names[$key] = $object->getName(); } You can express this more concisely with mpull(): $names = mpull($objects, 'getName');