From 4ea9d76f66f1efc4182a9e31809668e64642b816 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Tue, 5 May 2015 07:33:00 +1000 Subject: [PATCH] Add some missing type hints Summary: Add some typehints for Remarkup rules. Test Plan: Browsed around some Remarkup text. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D12694 --- .../PhabricatorCountdownRemarkupRule.php | 6 +++- .../PhabricatorDashboardRemarkupRule.php | 7 ++-- .../markup/DivinerSymbolRemarkupRule.php | 2 +- .../PhabricatorEmbedFileRemarkupRule.php | 6 +++- .../markup/PhabricatorEmojiRemarkupRule.php | 2 +- .../markup/PhabricatorIconRemarkupRule.php | 3 +- .../PhabricatorImageMacroRemarkupRule.php | 2 +- .../markup/PhabricatorMemeRemarkupRule.php | 2 +- .../remarkup/PhabricatorPasteRemarkupRule.php | 6 +++- .../markup/PhabricatorMentionRemarkupRule.php | 2 +- .../pholio/remarkup/PholioRemarkupRule.php | 12 +++++-- .../markup/PhrictionRemarkupRule.php | 3 +- .../project/remarkup/ProjectRemarkupRule.php | 7 +++- .../remarkup/SlowvoteRemarkupRule.php | 6 +++- .../PhabricatorNavigationRemarkupRule.php | 2 +- .../rule/PhabricatorObjectRemarkupRule.php | 34 +++++++++++++------ 16 files changed, 73 insertions(+), 29 deletions(-) diff --git a/src/applications/countdown/remarkup/PhabricatorCountdownRemarkupRule.php b/src/applications/countdown/remarkup/PhabricatorCountdownRemarkupRule.php index 51c3602a0d..7952ab6d7d 100644 --- a/src/applications/countdown/remarkup/PhabricatorCountdownRemarkupRule.php +++ b/src/applications/countdown/remarkup/PhabricatorCountdownRemarkupRule.php @@ -15,7 +15,11 @@ final class PhabricatorCountdownRemarkupRule ->execute(); } - protected function renderObjectEmbed($object, $handle, $options) { + protected function renderObjectEmbed( + $object, + PhabricatorObjectHandle $handle, + $options) { + $viewer = $this->getEngine()->getConfig('viewer'); return id(new PhabricatorCountdownView()) diff --git a/src/applications/dashboard/remarkup/PhabricatorDashboardRemarkupRule.php b/src/applications/dashboard/remarkup/PhabricatorDashboardRemarkupRule.php index 4ec24724fc..9870795f25 100644 --- a/src/applications/dashboard/remarkup/PhabricatorDashboardRemarkupRule.php +++ b/src/applications/dashboard/remarkup/PhabricatorDashboardRemarkupRule.php @@ -14,10 +14,13 @@ final class PhabricatorDashboardRemarkupRule ->setViewer($viewer) ->withIDs($ids) ->execute(); - } - protected function renderObjectEmbed($object, $handle, $options) { + protected function renderObjectEmbed( + $object, + PhabricatorObjectHandle $handle, + $options) { + $viewer = $this->getEngine()->getConfig('viewer'); return id(new PhabricatorDashboardPanelRenderingEngine()) diff --git a/src/applications/diviner/markup/DivinerSymbolRemarkupRule.php b/src/applications/diviner/markup/DivinerSymbolRemarkupRule.php index bb4fafd11e..7fdb4cb37e 100644 --- a/src/applications/diviner/markup/DivinerSymbolRemarkupRule.php +++ b/src/applications/diviner/markup/DivinerSymbolRemarkupRule.php @@ -33,7 +33,7 @@ final class DivinerSymbolRemarkupRule extends PhutilRemarkupRule { $text); } - public function markupSymbol($matches) { + public function markupSymbol(array $matches) { if (!$this->isFlatText($matches[0])) { return $matches[0]; } diff --git a/src/applications/files/markup/PhabricatorEmbedFileRemarkupRule.php b/src/applications/files/markup/PhabricatorEmbedFileRemarkupRule.php index 2572c440b7..fe0bb1da7a 100644 --- a/src/applications/files/markup/PhabricatorEmbedFileRemarkupRule.php +++ b/src/applications/files/markup/PhabricatorEmbedFileRemarkupRule.php @@ -28,7 +28,11 @@ final class PhabricatorEmbedFileRemarkupRule return $objects; } - protected function renderObjectEmbed($object, $handle, $options) { + protected function renderObjectEmbed( + $object, + PhabricatorObjectHandle $handle, + $options) { + $options = $this->getFileOptions($options) + array( 'name' => $object->getName(), ); diff --git a/src/applications/macro/markup/PhabricatorEmojiRemarkupRule.php b/src/applications/macro/markup/PhabricatorEmojiRemarkupRule.php index b1e24c23ff..9bb8d7f9f4 100644 --- a/src/applications/macro/markup/PhabricatorEmojiRemarkupRule.php +++ b/src/applications/macro/markup/PhabricatorEmojiRemarkupRule.php @@ -13,7 +13,7 @@ final class PhabricatorEmojiRemarkupRule extends PhutilRemarkupRule { $text); } - public function markupEmoji($matches) { + public function markupEmoji(array $matches) { if (!$this->isFlatText($matches[0])) { return $matches[0]; } diff --git a/src/applications/macro/markup/PhabricatorIconRemarkupRule.php b/src/applications/macro/markup/PhabricatorIconRemarkupRule.php index 9daf9b6f0c..ce1212b0fc 100644 --- a/src/applications/macro/markup/PhabricatorIconRemarkupRule.php +++ b/src/applications/macro/markup/PhabricatorIconRemarkupRule.php @@ -13,7 +13,7 @@ final class PhabricatorIconRemarkupRule extends PhutilRemarkupRule { $text); } - public function markupIcon($matches) { + public function markupIcon(array $matches) { $engine = $this->getEngine(); $text_mode = $engine->isTextMode(); $mail_mode = $engine->isHTMLMailMode(); @@ -73,7 +73,6 @@ final class PhabricatorIconRemarkupRule extends PhutilRemarkupRule { $icon_view = id(new PHUIIconView()) ->setIconFont('fa-'.$icon, $color); - return $this->getEngine()->storeText($icon_view); } diff --git a/src/applications/macro/markup/PhabricatorImageMacroRemarkupRule.php b/src/applications/macro/markup/PhabricatorImageMacroRemarkupRule.php index ec0ced4c1f..8911181a77 100644 --- a/src/applications/macro/markup/PhabricatorImageMacroRemarkupRule.php +++ b/src/applications/macro/markup/PhabricatorImageMacroRemarkupRule.php @@ -13,7 +13,7 @@ final class PhabricatorImageMacroRemarkupRule extends PhutilRemarkupRule { $text); } - public function markupImageMacro($matches) { + public function markupImageMacro(array $matches) { if ($this->macros === null) { $this->macros = array(); diff --git a/src/applications/macro/markup/PhabricatorMemeRemarkupRule.php b/src/applications/macro/markup/PhabricatorMemeRemarkupRule.php index df15548e54..0c949e130c 100644 --- a/src/applications/macro/markup/PhabricatorMemeRemarkupRule.php +++ b/src/applications/macro/markup/PhabricatorMemeRemarkupRule.php @@ -15,7 +15,7 @@ final class PhabricatorMemeRemarkupRule extends PhutilRemarkupRule { $text); } - public function markupMeme($matches) { + public function markupMeme(array $matches) { if (!$this->isFlatText($matches[0])) { return $matches[0]; } diff --git a/src/applications/paste/remarkup/PhabricatorPasteRemarkupRule.php b/src/applications/paste/remarkup/PhabricatorPasteRemarkupRule.php index 9e8822b175..e8e2624977 100644 --- a/src/applications/paste/remarkup/PhabricatorPasteRemarkupRule.php +++ b/src/applications/paste/remarkup/PhabricatorPasteRemarkupRule.php @@ -17,7 +17,11 @@ final class PhabricatorPasteRemarkupRule extends PhabricatorObjectRemarkupRule { } - protected function renderObjectEmbed($object, $handle, $options) { + protected function renderObjectEmbed( + $object, + PhabricatorObjectHandle $handle, + $options) { + $embed_paste = id(new PasteEmbedView()) ->setPaste($object) ->setHandle($handle); diff --git a/src/applications/people/markup/PhabricatorMentionRemarkupRule.php b/src/applications/people/markup/PhabricatorMentionRemarkupRule.php index 6750e34f0d..0451e29312 100644 --- a/src/applications/people/markup/PhabricatorMentionRemarkupRule.php +++ b/src/applications/people/markup/PhabricatorMentionRemarkupRule.php @@ -26,7 +26,7 @@ final class PhabricatorMentionRemarkupRule extends PhutilRemarkupRule { $text); } - protected function markupMention($matches) { + protected function markupMention(array $matches) { $engine = $this->getEngine(); if ($engine->isTextMode()) { diff --git a/src/applications/pholio/remarkup/PholioRemarkupRule.php b/src/applications/pholio/remarkup/PholioRemarkupRule.php index a28ef858d7..e8c8f00a17 100644 --- a/src/applications/pholio/remarkup/PholioRemarkupRule.php +++ b/src/applications/pholio/remarkup/PholioRemarkupRule.php @@ -12,7 +12,11 @@ final class PholioRemarkupRule extends PhabricatorObjectRemarkupRule { return '[1-9]\d*(?:/[1-9]\d*/?)?'; } - protected function getObjectHref($object, $handle, $id) { + protected function getObjectHref( + $object, + PhabricatorObjectHandle $handle, + $id) { + $href = $handle->getURI(); // If the ID has a `M123/456` component, link to that specific image. @@ -51,7 +55,11 @@ final class PholioRemarkupRule extends PhabricatorObjectRemarkupRule { return $results; } - protected function renderObjectEmbed($object, $handle, $options) { + protected function renderObjectEmbed( + $object, + PhabricatorObjectHandle $handle, + $options) { + $embed_mock = id(new PholioMockEmbedView()) ->setMock($object); diff --git a/src/applications/phriction/markup/PhrictionRemarkupRule.php b/src/applications/phriction/markup/PhrictionRemarkupRule.php index ba740e5f7b..6b66dd95d1 100644 --- a/src/applications/phriction/markup/PhrictionRemarkupRule.php +++ b/src/applications/phriction/markup/PhrictionRemarkupRule.php @@ -13,8 +13,7 @@ final class PhrictionRemarkupRule extends PhutilRemarkupRule { $text); } - public function markupDocumentLink($matches) { - + public function markupDocumentLink(array $matches) { $link = trim($matches[1]); $name = trim(idx($matches, 2, $link)); if (empty($matches[2])) { diff --git a/src/applications/project/remarkup/ProjectRemarkupRule.php b/src/applications/project/remarkup/ProjectRemarkupRule.php index fa0552593f..41ea2e026f 100644 --- a/src/applications/project/remarkup/ProjectRemarkupRule.php +++ b/src/applications/project/remarkup/ProjectRemarkupRule.php @@ -6,7 +6,12 @@ final class ProjectRemarkupRule extends PhabricatorObjectRemarkupRule { return '#'; } - protected function renderObjectRef($object, $handle, $anchor, $id) { + protected function renderObjectRef( + $object, + PhabricatorObjectHandle $handle, + $anchor, + $id) { + if ($this->getEngine()->isTextMode()) { return '#'.$id; } diff --git a/src/applications/slowvote/remarkup/SlowvoteRemarkupRule.php b/src/applications/slowvote/remarkup/SlowvoteRemarkupRule.php index 6f4c6b6a21..c93757315b 100644 --- a/src/applications/slowvote/remarkup/SlowvoteRemarkupRule.php +++ b/src/applications/slowvote/remarkup/SlowvoteRemarkupRule.php @@ -18,7 +18,11 @@ final class SlowvoteRemarkupRule extends PhabricatorObjectRemarkupRule { ->execute(); } - protected function renderObjectEmbed($object, $handle, $options) { + protected function renderObjectEmbed( + $object, + PhabricatorObjectHandle $handle, + $options) { + $viewer = $this->getEngine()->getConfig('viewer'); $embed = id(new SlowvoteEmbedView()) diff --git a/src/infrastructure/markup/rule/PhabricatorNavigationRemarkupRule.php b/src/infrastructure/markup/rule/PhabricatorNavigationRemarkupRule.php index 03c9b320a0..857a0c10bd 100644 --- a/src/infrastructure/markup/rule/PhabricatorNavigationRemarkupRule.php +++ b/src/infrastructure/markup/rule/PhabricatorNavigationRemarkupRule.php @@ -13,7 +13,7 @@ final class PhabricatorNavigationRemarkupRule extends PhutilRemarkupRule { $text); } - public function markupNavigation($matches) { + public function markupNavigation(array $matches) { if (!$this->isFlatText($matches[0])) { return $matches[0]; } diff --git a/src/infrastructure/markup/rule/PhabricatorObjectRemarkupRule.php b/src/infrastructure/markup/rule/PhabricatorObjectRemarkupRule.php index 7f211c3654..64f6684ce6 100644 --- a/src/infrastructure/markup/rule/PhabricatorObjectRemarkupRule.php +++ b/src/infrastructure/markup/rule/PhabricatorObjectRemarkupRule.php @@ -45,10 +45,11 @@ abstract class PhabricatorObjectRemarkupRule extends PhutilRemarkupRule { } protected function renderObjectRefForAnyMedia ( - $object, - $handle, - $anchor, - $id) { + $object, + PhabricatorObjectHandle $handle, + $anchor, + $id) { + $href = $this->getObjectHref($object, $handle, $id); $text = $this->getObjectNamePrefix().$id; @@ -68,7 +69,12 @@ abstract class PhabricatorObjectRemarkupRule extends PhutilRemarkupRule { } - protected function renderObjectRef($object, $handle, $anchor, $id) { + protected function renderObjectRef( + $object, + PhabricatorObjectHandle $handle, + $anchor, + $id) { + $href = $this->getObjectHref($object, $handle, $id); $text = $this->getObjectNamePrefix().$id; $status_closed = PhabricatorObjectHandleStatus::STATUS_CLOSED; @@ -86,7 +92,11 @@ abstract class PhabricatorObjectRemarkupRule extends PhutilRemarkupRule { return $this->renderHovertag($text, $href, $attr); } - protected function renderObjectEmbedForAnyMedia($object, $handle, $options) { + protected function renderObjectEmbedForAnyMedia( + $object, + PhabricatorObjectHandle $handle, + $options) { + $name = $handle->getFullName(); $href = $handle->getURI(); @@ -100,7 +110,11 @@ abstract class PhabricatorObjectRemarkupRule extends PhutilRemarkupRule { return $this->renderObjectEmbed($object, $handle, $options); } - protected function renderObjectEmbed($object, $handle, $options) { + protected function renderObjectEmbed( + $object, + PhabricatorObjectHandle $handle, + $options) { + $name = $handle->getFullName(); $href = $handle->getURI(); $status_closed = PhabricatorObjectHandleStatus::STATUS_CLOSED; @@ -115,7 +129,7 @@ abstract class PhabricatorObjectRemarkupRule extends PhutilRemarkupRule { protected function renderObjectTagForMail( $text, $href, - $handle) { + PhabricatorObjectHandle $handle) { $status_closed = PhabricatorObjectHandleStatus::STATUS_CLOSED; $strikethrough = $handle->getStatus() == $status_closed ? @@ -243,7 +257,7 @@ abstract class PhabricatorObjectRemarkupRule extends PhutilRemarkupRule { return $results; } - public function markupObjectEmbed($matches) { + public function markupObjectEmbed(array $matches) { if (!$this->isFlatText($matches[0])) { return $matches[0]; } @@ -256,7 +270,7 @@ abstract class PhabricatorObjectRemarkupRule extends PhutilRemarkupRule { )); } - public function markupObjectReference($matches) { + public function markupObjectReference(array $matches) { if (!$this->isFlatText($matches[0])) { return $matches[0]; }