Stronger typing for NoticeListItem and so

This commit is contained in:
Mikael Nordfeldth 2014-06-02 00:20:27 +02:00
parent 49188e826c
commit d596513e39
11 changed files with 34 additions and 32 deletions

View File

@ -170,6 +170,9 @@ class NewnoticeAction extends FormAction
Event::handle('EndNoticeSaveWeb', array($this, $notice)); Event::handle('EndNoticeSaveWeb', array($this, $notice));
} }
assert($notice instanceof Notice);
Event::handle('EndSaveNewNoticeWeb', array($this, $user, &$content_shortened, &$options)); Event::handle('EndSaveNewNoticeWeb', array($this, $user, &$content_shortened, &$options));
if (StatusNet::isAjax()) { if (StatusNet::isAjax()) {
@ -345,7 +348,7 @@ class NewnoticeAction extends FormAction
* *
* @return void * @return void
*/ */
function showNotice($notice) function showNotice(Notice $notice)
{ {
$nli = new NoticeListItem($notice, $this); $nli = new NoticeListItem($notice, $this);
$nli->show(); $nli->show();

View File

@ -114,20 +114,19 @@ class ShownoticeAction extends Action
$id = $this->arg('notice'); $id = $this->arg('notice');
$notice = Notice::getKV('id', $id); $notice = Notice::getKV('id', $id);
if ($notice instanceof Notice) {
if (!$notice instanceof Notice) { // Alright, got it!
// Did we used to have it, and it got deleted? return $notice;
$deleted = Deleted_notice::getKV($id);
if ($deleted instanceof Deleted_notice) {
// TRANS: Client error displayed trying to show a deleted notice.
$this->clientError(_('Notice deleted.'), 410);
} else {
// TRANS: Client error displayed trying to show a non-existing notice.
$this->clientError(_('No such notice.'), 404);
}
return false;
} }
return $notice;
// Did we use to have it, and it got deleted?
$deleted = Deleted_notice::getKV('id', $id);
if ($deleted instanceof Deleted_notice) {
// TRANS: Client error displayed trying to show a deleted notice.
$this->clientError(_('Notice deleted.'), 410);
}
// TRANS: Client error displayed trying to show a non-existing notice.
$this->clientError(_('No such notice.'), 404);
} }
/** /**

View File

@ -58,7 +58,7 @@ class NoticeList extends Widget
* *
* @param Notice $notice stream of notices from DB_DataObject * @param Notice $notice stream of notices from DB_DataObject
*/ */
function __construct($notice, $out=null) function __construct(Notice $notice, $out=null)
{ {
parent::__construct($out); parent::__construct($out);
$this->notice = $notice; $this->notice = $notice;
@ -111,7 +111,7 @@ class NoticeList extends Widget
* *
* @return NoticeListItem a list item for displaying the notice * @return NoticeListItem a list item for displaying the notice
*/ */
function newListItem($notice) function newListItem(Notice $notice)
{ {
return new NoticeListItem($notice, $this->out); return new NoticeListItem($notice, $this->out);
} }

View File

@ -65,7 +65,7 @@ class NoticeListItem extends Widget
* *
* @param Notice $notice The notice we'll display * @param Notice $notice The notice we'll display
*/ */
function __construct($notice, $out=null) function __construct(Notice $notice, HTMLOutputter $out=null)
{ {
parent::__construct($out); parent::__construct($out);
if (!empty($notice->repeat_of)) { if (!empty($notice->repeat_of)) {

View File

@ -70,7 +70,7 @@ class NoticeSection extends Section
return null; return null;
} }
function showNotice($notice) function showNotice(Notice $notice)
{ {
$profile = $notice->getProfile(); $profile = $notice->getProfile();
if (empty($profile)) { if (empty($profile)) {

View File

@ -50,7 +50,7 @@ class ThreadedNoticeList extends NoticeList
{ {
protected $userProfile; protected $userProfile;
function __construct($notice, $out=null, $profile=-1) function __construct(Notice $notice, HTMLOutputter $out=null, $profile=-1)
{ {
parent::__construct($notice, $out); parent::__construct($notice, $out);
if (is_int($profile) && $profile == -1) { if (is_int($profile) && $profile == -1) {
@ -147,7 +147,7 @@ class ThreadedNoticeList extends NoticeList
* *
* @return NoticeListItem a list item for displaying the notice * @return NoticeListItem a list item for displaying the notice
*/ */
function newListItem($notice) function newListItem(Notice $notice)
{ {
return new ThreadedNoticeListItem($notice, $this->out, $this->userProfile); return new ThreadedNoticeListItem($notice, $this->out, $this->userProfile);
} }
@ -174,7 +174,7 @@ class ThreadedNoticeListItem extends NoticeListItem
{ {
protected $userProfile = null; protected $userProfile = null;
function __construct($notice, $out=null, $profile=null) function __construct(Notice $notice, HTMLOutputter $out=null, $profile=null)
{ {
parent::__construct($notice, $out); parent::__construct($notice, $out);
$this->userProfile = $profile; $this->userProfile = $profile;
@ -269,7 +269,7 @@ class ThreadedNoticeListSubItem extends NoticeListItem
{ {
protected $root = null; protected $root = null;
function __construct($notice, $root, $out) function __construct(Notice $notice, $root, $out)
{ {
$this->root = $root; $this->root = $root;
parent::__construct($notice, $out); parent::__construct($notice, $out);
@ -327,7 +327,7 @@ class ThreadedNoticeListMoreItem extends NoticeListItem
{ {
protected $cnt; protected $cnt;
function __construct($notice, $out, $cnt) function __construct(Notice $notice, HTMLOutputter $out, $cnt)
{ {
parent::__construct($notice, $out); parent::__construct($notice, $out);
$this->cnt = $cnt; $this->cnt = $cnt;

View File

@ -191,7 +191,7 @@ class NewbookmarkAction extends Action
* *
* @return void * @return void
*/ */
function showNotice($notice) function showNotice(Notice $notice)
{ {
class_exists('NoticeList'); // @fixme hack for autoloader class_exists('NoticeList'); // @fixme hack for autoloader
$nli = new NoticeListItem($notice, $this); $nli = new NoticeListItem($notice, $this);

View File

@ -320,7 +320,7 @@ class NeweventAction extends Action
* *
* @return void * @return void
*/ */
function showNotice($notice) function showNotice(Notice $notice)
{ {
$nli = new NoticeListItem($notice, $this); $nli = new NoticeListItem($notice, $this);
$nli->show(); $nli->show();

View File

@ -379,7 +379,7 @@ class PollPlugin extends MicroAppPlugin
* open here, but we probably shouldn't open it here. Check parent class * open here, but we probably shouldn't open it here. Check parent class
* and Bookmark plugin for if that's right. * and Bookmark plugin for if that's right.
*/ */
function showNotice($notice, $out) function showNotice(Notice $notice, $out)
{ {
switch ($notice->object_type) { switch ($notice->object_type) {
case self::POLL_OBJECT: case self::POLL_OBJECT:
@ -393,7 +393,7 @@ class PollPlugin extends MicroAppPlugin
} }
} }
function showNoticePoll($notice, $out) function showNoticePoll(Notice $notice, $out)
{ {
$user = common_current_user(); $user = common_current_user();
@ -425,7 +425,7 @@ class PollPlugin extends MicroAppPlugin
$out->elementStart('div', array('class' => 'entry-content')); $out->elementStart('div', array('class' => 'entry-content'));
} }
function showNoticePollResponse($notice, $out) function showNoticePollResponse(Notice $notice, $out)
{ {
$user = common_current_user(); $user = common_current_user();

View File

@ -181,7 +181,7 @@ class NewPollAction extends Action
* *
* @return void * @return void
*/ */
function showNotice($notice) function showNotice(Notice $notice)
{ {
class_exists('NoticeList'); // @fixme hack for autoloader class_exists('NoticeList'); // @fixme hack for autoloader
$nli = new NoticeListItem($notice, $this); $nli = new NoticeListItem($notice, $this);

View File

@ -319,7 +319,7 @@ class QnAPlugin extends MicroAppPlugin
* @param Notice $notice * @param Notice $notice
* @param HTMLOutputter $out * @param HTMLOutputter $out
*/ */
function showNotice($notice, $out) function showNotice(Notice $notice, $out)
{ {
switch ($notice->object_type) { switch ($notice->object_type) {
case QnA_Question::OBJECT_TYPE: case QnA_Question::OBJECT_TYPE:
@ -337,7 +337,7 @@ class QnAPlugin extends MicroAppPlugin
} }
} }
function showNoticeQuestion($notice, $out) function showNoticeQuestion(Notice $notice, $out)
{ {
$user = common_current_user(); $user = common_current_user();
@ -427,7 +427,7 @@ class QnAPlugin extends MicroAppPlugin
return false; return false;
} }
function showNoticeAnswer($notice, $out) function showNoticeAnswer(Notice $notice, $out)
{ {
$user = common_current_user(); $user = common_current_user();