[UserFlag] Increase strict typing of main file

Run php-cs-fixer
Correct case of class name onDeleteRelated event handlers
This commit is contained in:
Diogo Cordeiro 2020-07-21 12:43:46 +01:00 committed by Diogo Peralta Cordeiro
parent 235122280d
commit e046d4faa5
7 changed files with 158 additions and 138 deletions

View File

@ -21,12 +21,13 @@
*
* @category Plugin
* @package StatusNet
*
* @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*
* @see http://status.net/
*/
if (!defined('STATUSNET')) {
exit(1);
}
@ -36,9 +37,11 @@ if (!defined('STATUSNET')) {
*
* @category Plugin
* @package StatusNet
*
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*
* @see http://status.net/
*/
class UserFlagPlugin extends Plugin
{
@ -55,9 +58,9 @@ class UserFlagPlugin extends Plugin
* Ensures that the user_flag_profile table exists
* and has the right columns.
*
* @return boolean hook return
* @return bool hook return
*/
function onCheckSchema()
public function onCheckSchema(): bool
{
$schema = Schema::get();
@ -71,9 +74,9 @@ class UserFlagPlugin extends Plugin
*
* @param URLMapper $m URL mapper for this hit
*
* @return boolean hook return
* @return bool hook return
*/
public function onRouterInitialized(URLMapper $m)
public function onRouterInitialized(URLMapper $m): bool
{
$m->connect('main/flag/profile', ['action' => 'flagprofile']);
$m->connect('main/flag/clear', ['action' => 'clearflag']);
@ -87,13 +90,16 @@ class UserFlagPlugin extends Plugin
* @param Action $action The action being called
* @param Profile $profile Profile being shown
*
* @return boolean hook result
* @return bool hook result
*/
function onEndProfilePageActionsElements($action, $profile)
public function onEndProfilePageActionsElements(Action $action, Profile $profile): bool
{
$this->showFlagButton($action, $profile,
array('action' => 'showstream',
'nickname' => $profile->nickname));
$this->showFlagButton(
$action,
$profile,
['action' => 'showstream',
'nickname' => $profile->nickname, ]
);
return true;
}
@ -103,9 +109,9 @@ class UserFlagPlugin extends Plugin
*
* @param ProfileListItem $item item being shown
*
* @return boolean hook result
* @return bool hook result
*/
function onEndProfileListItemActionElements($item)
public function onEndProfileListItemActionElements(ProfileListItem $item): bool
{
list($action, $args) = $item->action->returnToArgs();
$args['action'] = $action;
@ -122,12 +128,11 @@ class UserFlagPlugin extends Plugin
* @param Profile $profile
* @param array $returnToArgs
*/
protected function showFlagButton($action, $profile, $returnToArgs)
protected function showFlagButton(Action $action, Profile $profile, array $returnToArgs): array
{
$user = common_current_user();
if (!empty($user) && ($user->id != $profile->id)) {
$action->elementStart('li', 'entity_flag');
if (User_flag_profile::exists($profile->id, $user->id)) {
@ -151,11 +156,11 @@ class UserFlagPlugin extends Plugin
*
* @param User $user User being checked
* @param string $right Right we're checking
* @param boolean &$result out, result of the check
* @param bool &$result out, result of the check
*
* @return boolean hook result
* @return bool hook result
*/
function onUserRightsCheck($user, $right, &$result)
public function onUserRightsCheck(User $user, string $right, bool &$result): bool
{
switch ($right) {
case self::REVIEWFLAGS:
@ -175,13 +180,14 @@ class UserFlagPlugin extends Plugin
* @param User $user User doing the block
* @param Profile $profile Profile being blocked
*
* @return boolean hook result
* @return bool hook result
*/
function onEndBlockProfile($user, $profile)
public function onEndBlockProfile(User $user, Profile $profile): bool
{
if ($this->flagOnBlock && !User_flag_profile::exists($profile->id,
$user->id)) {
if ($this->flagOnBlock && !User_flag_profile::exists(
$profile->id,
$user->id
)) {
User_flag_profile::create($user->id, $profile->id);
}
return true;
@ -196,11 +202,11 @@ class UserFlagPlugin extends Plugin
* @param array &$related list of related tables; entries
* with matching profile_id will be deleted.
*
* @return boolean hook result
* @return bool hook result
*/
function onProfileDeleteRelated($profile, &$related)
public function onProfileDeleteRelated(Profile $profile, array &$related): bool
{
$related[] = 'user_flag_profile';
$related[] = 'User_flag_profile';
return true;
}
@ -212,11 +218,11 @@ class UserFlagPlugin extends Plugin
* @param array &$related list of related tables; entries
* with matching user_id will be deleted.
*
* @return boolean hook result
* @return bool hook result
*/
function onUserDeleteRelated($user, &$related)
public function onUserDeleteRelated(User $user, array &$related): bool
{
$related[] = 'user_flag_profile';
$related[] = 'User_flag_profile';
return true;
}
@ -227,19 +233,18 @@ class UserFlagPlugin extends Plugin
*
* @param array &$versions array of version data arrays; see EVENTS.txt
*
* @return boolean hook value
* @return bool hook value
*/
public function onPluginVersion(array &$versions): bool
{
$url = GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/UserFlag';
$versions[] = array('name' => 'UserFlag',
$versions[] = ['name' => 'UserFlag',
'version' => self::PLUGIN_VERSION,
'author' => 'Evan Prodromou',
'homepage' => $url,
'rawdescription' =>
// TRANS: Plugin description.
_m('This plugin allows flagging of profiles for review and reviewing flagged profiles.'));
'rawdescription' => // TRANS: Plugin description.
_m('This plugin allows flagging of profiles for review and reviewing flagged profiles.'), ];
return true;
}

View File

@ -6,9 +6,11 @@
*
* @category Action
* @package StatusNet
*
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* @see http://status.net/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2009, StatusNet, Inc.
@ -26,7 +28,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('STATUSNET')) {
exit(1);
}
@ -36,23 +37,25 @@ if (!defined('STATUSNET')) {
*
* @category Action
* @package StatusNet
*
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* @see http://status.net/
*/
class AdminprofileflagAction extends Action
{
var $page = null;
var $profiles = null;
public $page;
public $profiles;
/**
* Take arguments for running
*
* @param array $args $_REQUEST args
*
* @return boolean success flag
* @return bool success flag
*/
function prepare(array $args = array())
public function prepare(array $args = [])
{
parent::prepare($args);
@ -77,7 +80,7 @@ class AdminprofileflagAction extends Action
// Cookie theft is too easy; we require automatic
// logins to re-authenticate before admining the site
common_set_returnto($this->selfUrl());
if (Event::handle('RedirectToLogin', array($this, $user))) {
if (Event::handle('RedirectToLogin', [$this, $user])) {
common_redirect(common_local_url('login'), 303);
}
}
@ -107,7 +110,7 @@ class AdminprofileflagAction extends Action
*
* @return void
*/
function handle()
public function handle()
{
parent::handle();
@ -119,7 +122,7 @@ class AdminprofileflagAction extends Action
*
* @return string Title of the page
*/
function title()
public function title()
{
// TRANS: Title for page with a list of profiles that were flagged for review.
return _m('Flagged profiles');
@ -130,7 +133,7 @@ class AdminprofileflagAction extends Action
*
* @return void
*/
function showContent()
public function showContent()
{
$pl = new FlaggedProfileList($this->profiles, $this);
@ -145,7 +148,7 @@ class AdminprofileflagAction extends Action
*
* @return Profile $profile Profile query results
*/
function getProfiles()
public function getProfiles()
{
$ufp = new User_flag_profile();
@ -158,12 +161,12 @@ class AdminprofileflagAction extends Action
$ufp->groupBy('profile_id');
$ufp->orderBy('flag_count DESC, profile_id DESC');
$offset = ($this->page-1) * PROFILES_PER_PAGE;
$offset = ($this->page - 1) * PROFILES_PER_PAGE;
$limit = PROFILES_PER_PAGE + 1;
$ufp->limit($offset, $limit);
$profiles = array();
$profiles = [];
if ($ufp->find()) {
while ($ufp->fetch()) {
@ -187,9 +190,11 @@ class AdminprofileflagAction extends Action
*
* @category Widget
* @package StatusNet
*
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* @see http://status.net/
*/
class FlaggedProfileList extends ProfileList
{
@ -200,7 +205,7 @@ class FlaggedProfileList extends ProfileList
*
* @return ProfileListItem newly-created item
*/
function newListItem(Profile $profile)
public function newListItem(Profile $profile)
{
return new FlaggedProfileListItem($profile, $this->action);
}
@ -211,23 +216,25 @@ class FlaggedProfileList extends ProfileList
*
* @category Widget
* @package StatusNet
*
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* @see http://status.net/
*/
class FlaggedProfileListItem extends ProfileListItem
{
const MAX_FLAGGERS = 5;
var $user = null;
var $r2args = null;
public $user;
public $r2args;
/**
* Overload parent's action list with our own moderation-oriented buttons
*
* @return void
*/
function showActions()
public function showActions()
{
$this->user = common_current_user();
@ -236,7 +243,7 @@ class FlaggedProfileListItem extends ProfileListItem
$this->r2args['action'] = $action;
$this->startActions();
if (Event::handle('StartProfileListItemActionElements', array($this))) {
if (Event::handle('StartProfileListItemActionElements', [$this])) {
$this->out->elementStart('li', 'entity_moderation');
// TRANS: Header for moderation menu with action buttons for flagged profiles (like 'sandbox', 'silence', ...).
$this->out->element('p', null, _m('Moderate'));
@ -247,7 +254,7 @@ class FlaggedProfileListItem extends ProfileListItem
$this->showClearButton();
$this->out->elementEnd('ul');
$this->out->elementEnd('li');
Event::handle('EndProfileListItemActionElements', array($this));
Event::handle('EndProfileListItemActionElements', [$this]);
}
$this->endActions();
}
@ -257,7 +264,7 @@ class FlaggedProfileListItem extends ProfileListItem
*
* @return void
*/
function showSandboxButton()
public function showSandboxButton()
{
if ($this->user->hasRight(Right::SANDBOXUSER)) {
$this->out->elementStart('li', 'entity_sandbox');
@ -277,7 +284,7 @@ class FlaggedProfileListItem extends ProfileListItem
*
* @return void
*/
function showSilenceButton()
public function showSilenceButton()
{
if ($this->user->hasRight(Right::SILENCEUSER)) {
$this->out->elementStart('li', 'entity_silence');
@ -297,9 +304,8 @@ class FlaggedProfileListItem extends ProfileListItem
*
* @return void
*/
function showDeleteButton()
public function showDeleteButton()
{
if ($this->user->hasRight(Right::DELETEUSER)) {
$this->out->elementStart('li', 'entity_delete');
$df = new DeleteUserForm($this->out, $this->profile, $this->r2args);
@ -313,7 +319,7 @@ class FlaggedProfileListItem extends ProfileListItem
*
* @return void
*/
function showClearButton()
public function showClearButton()
{
if ($this->user->hasRight(UserFlagPlugin::CLEARFLAGS)) {
$this->out->elementStart('li', 'entity_clear');
@ -328,7 +334,7 @@ class FlaggedProfileListItem extends ProfileListItem
*
* @return void
*/
function endProfile()
public function endProfile()
{
$this->showFlaggersList();
parent::endProfile();
@ -339,9 +345,9 @@ class FlaggedProfileListItem extends ProfileListItem
*
* @return void
*/
function showFlaggersList()
public function showFlaggersList()
{
$flaggers = array();
$flaggers = [];
$ufp = new User_flag_profile();
@ -354,7 +360,7 @@ class FlaggedProfileListItem extends ProfileListItem
while ($ufp->fetch()) {
$user = User::getKV('id', $ufp->user_id);
if (!empty($user)) { // XXX: this would also be unusual
$flaggers[] = clone($user);
$flaggers[] = clone $user;
}
}
}
@ -367,15 +373,14 @@ class FlaggedProfileListItem extends ProfileListItem
$others = $cnt - self::MAX_FLAGGERS;
}
$lnks = array();
$lnks = [];
foreach ($flaggers as $flagger) {
$url = common_local_url('showstream',
array('nickname' => $flagger->nickname));
['nickname' => $flagger->nickname]);
$lnks[] = XMLStringer::estring('a', array('href' => $url,
'class' => 'flagger'),
$lnks[] = XMLStringer::estring('a', ['href' => $url,
'class' => 'flagger', ],
$flagger->nickname);
}
@ -392,7 +397,7 @@ class FlaggedProfileListItem extends ProfileListItem
$text .= sprintf(_m('Flagged by %s'), $flagging_users);
}
$this->out->elementStart('p', array('class' => 'flaggers'));
$this->out->elementStart('p', ['class' => 'flaggers']);
$this->out->raw($text);
$this->out->elementEnd('p');
}

View File

@ -19,11 +19,11 @@
*
* @category Action
* @package GNUsocial
*
* @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
defined('GNUSOCIAL') || die();
/**
@ -31,6 +31,7 @@ defined('GNUSOCIAL') || die();
*
* @category Action
* @package GNUsocial
*
* @author Evan Prodromou <evan@status.net>
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
@ -41,7 +42,7 @@ class ClearflagAction extends ProfileFormAction
*
* @param array $args $_REQUEST args
*
* @return boolean success flag
* @return bool success flag
*/
public function prepare(array $args = [])
{

View File

@ -6,9 +6,11 @@
*
* @category Action
* @package StatusNet
*
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* @see http://status.net/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2009, StatusNet, Inc.
@ -26,7 +28,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('STATUSNET')) {
exit(1);
}
@ -36,9 +37,11 @@ if (!defined('STATUSNET')) {
*
* @category Action
* @package StatusNet
*
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* @see http://status.net/
*/
class FlagprofileAction extends ProfileFormAction
{
@ -47,9 +50,9 @@ class FlagprofileAction extends ProfileFormAction
*
* @param array $args $_REQUEST args
*
* @return boolean success flag
* @return bool success flag
*/
function prepare(array $args = array())
public function prepare(array $args = [])
{
if (!parent::prepare($args)) {
return false;
@ -73,7 +76,7 @@ class FlagprofileAction extends ProfileFormAction
*
* @return void
*/
function handle()
public function handle()
{
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$this->handlePost();
@ -88,7 +91,7 @@ class FlagprofileAction extends ProfileFormAction
*
* @return void
*/
function handlePost()
public function handlePost()
{
$user = common_current_user();
@ -115,7 +118,7 @@ class FlagprofileAction extends ProfileFormAction
*
* @return void
*/
function ajaxResults()
public function ajaxResults()
{
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');

View File

@ -19,11 +19,11 @@
*
* @category Data
* @package GNUsocial
*
* @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
defined('GNUSOCIAL') || die();
/**
@ -33,14 +33,15 @@ defined('GNUSOCIAL') || die();
*
* @category Action
* @package GNUsocial
*
* @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class User_flag_profile extends Managed_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
//##START_AUTOCODE
// the code below is auto generated do not remove the above tag
public $__table = 'user_flag_profile'; // table name
public $profile_id; // int(11) primary_key not_null
@ -49,39 +50,39 @@ class User_flag_profile extends Managed_DataObject
public $created; // datetime()
public $modified; // timestamp() not_null
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
// the code above is auto generated do not remove the tag below
//##END_AUTOCODE
public static function schemaDef()
{
return array(
'fields' => array(
'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'profile id flagged'),
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id of the actor'),
'cleared' => array('type' => 'datetime', 'description' => 'when flag was removed'),
'created' => array('type' => 'datetime', 'description' => 'date this record was created'),
'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
),
'primary key' => array('profile_id', 'user_id'),
'indexes' => array(
'user_flag_profile_cleared_idx' => array('cleared'),
'user_flag_profile_created_idx' => array('created'),
),
);
return [
'fields' => [
'profile_id' => ['type' => 'int', 'not null' => true, 'description' => 'profile id flagged'],
'user_id' => ['type' => 'int', 'not null' => true, 'description' => 'user id of the actor'],
'cleared' => ['type' => 'datetime', 'description' => 'when flag was removed'],
'created' => ['type' => 'datetime', 'description' => 'date this record was created'],
'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'],
],
'primary key' => ['profile_id', 'user_id'],
'indexes' => [
'user_flag_profile_cleared_idx' => ['cleared'],
'user_flag_profile_created_idx' => ['created'],
],
];
}
/**
* Check if a flag exists for given profile and user
*
* @param integer $profile_id Profile to check for
* @param integer $user_id User to check for
* @param int $profile_id Profile to check for
* @param int $user_id User to check for
*
* @return boolean true if exists, else false
* @return bool true if exists, else false
*/
public static function exists($profile_id, $user_id)
{
$ufp = User_flag_profile::pkeyGet(array('profile_id' => $profile_id,
'user_id' => $user_id));
$ufp = self::pkeyGet(['profile_id' => $profile_id,
'user_id' => $user_id, ]);
return !empty($ufp);
}
@ -89,14 +90,14 @@ class User_flag_profile extends Managed_DataObject
/**
* Create a new flag
*
* @param integer $user_id ID of user who's flagging
* @param integer $profile_id ID of profile being flagged
* @param int $user_id ID of user who's flagging
* @param int $profile_id ID of profile being flagged
*
* @return boolean success flag
* @return bool success flag
*/
public static function create($user_id, $profile_id)
{
$ufp = new User_flag_profile();
$ufp = new self();
$ufp->profile_id = $profile_id;
$ufp->user_id = $user_id;

View File

@ -21,12 +21,13 @@
*
* @category Form
* @package StatusNet
*
* @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*
* @see http://status.net/
*/
if (!defined('STATUSNET')) {
exit(1);
}
@ -38,9 +39,11 @@ require_once INSTALLDIR . '/lib/util/form.php';
*
* @category Form
* @package StatusNet
*
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*
* @see http://status.net/
*/
class ClearFlagForm extends ProfileActionForm
{
@ -50,7 +53,7 @@ class ClearFlagForm extends ProfileActionForm
*
* @return string class of the form
*/
function formClass()
public function formClass()
{
return 'form_user_clearflag';
}
@ -60,7 +63,7 @@ class ClearFlagForm extends ProfileActionForm
*
* @return string Name of the action, lowercased.
*/
function target()
public function target()
{
return 'clearflag';
}
@ -70,7 +73,7 @@ class ClearFlagForm extends ProfileActionForm
*
* @return string Title of the form, internationalized
*/
function title()
public function title()
{
// TRANS: Form title for action on a profile.
return _m('Clear');
@ -81,8 +84,7 @@ class ClearFlagForm extends ProfileActionForm
*
* @return string description of the form, internationalized
*/
function description()
public function description()
{
// TRANS: Form description for clearing flags from a profile.
return _m('Clear all flags');

View File

@ -21,12 +21,13 @@
*
* @category Form
* @package StatusNet
*
* @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*
* @see http://status.net/
*/
if (!defined('STATUSNET')) {
exit(1);
}
@ -40,9 +41,11 @@ require_once INSTALLDIR . '/lib/util/form.php';
*
* @category Form
* @package StatusNet
*
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*
* @see http://status.net/
*/
class FlagProfileForm extends ProfileActionForm
{
@ -52,7 +55,7 @@ class FlagProfileForm extends ProfileActionForm
*
* @return string class of the form
*/
function formClass()
public function formClass()
{
return 'form_entity_flag ajax';
}
@ -62,7 +65,7 @@ class FlagProfileForm extends ProfileActionForm
*
* @return string Name of the action, lowercased.
*/
function target()
public function target()
{
return 'flagprofile';
}
@ -72,7 +75,7 @@ class FlagProfileForm extends ProfileActionForm
*
* @return string Title of the form, internationalized
*/
function title()
public function title()
{
// TRANS: Form title for flagging a profile for review.
return _m('Flag');
@ -83,7 +86,7 @@ class FlagProfileForm extends ProfileActionForm
*
* @return string description of the form, internationalized
*/
function description()
public function description()
{
// TRANS: Form description.
return _m('Flag profile for review.');