Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
phpcs and deprecation updates
Browse files Browse the repository at this point in the history
  • Loading branch information
burzum committed Jul 17, 2017
1 parent 0fc14a1 commit 5b21cf4
Show file tree
Hide file tree
Showing 16 changed files with 206 additions and 212 deletions.
3 changes: 2 additions & 1 deletion config/Migrations/20140902003044_initial.php
Expand Up @@ -9,7 +9,8 @@
*/
use Phinx\Migration\AbstractMigration;

class Initial extends AbstractMigration {
class Initial extends AbstractMigration
{

/**
* Migrate Up.
Expand Down
8 changes: 5 additions & 3 deletions src/Controller/Component/FlashAndRedirectTrait.php
Expand Up @@ -8,8 +8,10 @@
*/
namespace Burzum\UserTools\Controller\Component;

trait FlashAndRedirectTrait
{
/**
* FlashAndRedirectTrait
*/
trait FlashAndRedirectTrait {

/**
* Helper property to detect a redirect
Expand Down Expand Up @@ -41,7 +43,7 @@ public function handleFlashAndRedirect($type, $options) {
*/
protected function _handleRedirect($type, $options) {
if (isset($options[$type . 'RedirectUrl']) && $options[$type . 'RedirectUrl'] !== false) {
$controller = $this->_registry->getController();
$controller = $this->getController();
$result = $controller->redirect($options[$type . 'RedirectUrl']);
$this->_redirectResponse = $result;

Expand Down
6 changes: 4 additions & 2 deletions src/Mailer/UsersMailer.php
Expand Up @@ -3,8 +3,10 @@

use Cake\Mailer\Mailer;

class UsersMailer extends Mailer
{
/**
* Users Mailer
*/
class UsersMailer extends Mailer {

/**
* Sends the verification email to an user.
Expand Down
3 changes: 1 addition & 2 deletions src/Model/Behavior/UserBehavior.php
Expand Up @@ -29,8 +29,7 @@
/**
* User Behavior
*/
class UserBehavior extends Behavior
{
class UserBehavior extends Behavior {

use EventDispatcherTrait;
use MailerAwareTrait;
Expand Down
3 changes: 1 addition & 2 deletions src/Model/PasswordAndTokenTrait.php
Expand Up @@ -6,8 +6,7 @@
/**
* A trait to add methods to a class to generate a password and token.
*/
trait PasswordAndTokenTrait
{
trait PasswordAndTokenTrait {

/**
* Generates a random password that is more or less user friendly.
Expand Down
3 changes: 1 addition & 2 deletions src/Model/PasswordHasherTrait.php
Expand Up @@ -11,8 +11,7 @@
* @copyright 2013 - 2017 Florian Krämer
* @license MIT
*/
trait PasswordHasherTrait
{
trait PasswordHasherTrait {

/**
* AbstractPasswordHasher instance.
Expand Down
11 changes: 5 additions & 6 deletions src/Model/UserValidationTrait.php
Expand Up @@ -5,8 +5,7 @@
use Cake\Validation\Validator;
use RuntimeException;

trait UserValidationTrait
{
trait UserValidationTrait {

/**
* Validates the password reset.
Expand All @@ -31,7 +30,7 @@ public function validationPasswordReset(Validator $validator) {
* @return \Cake\Validation\Validator
*/
public function validationUserName(Validator $validator) {
$validator->provider('userTable', $this->_table);
$validator->setProvider('userTable', $this->_table);

$validator->add($this->_field('username'), [
'notBlank' => [
Expand Down Expand Up @@ -65,7 +64,7 @@ public function validationUserName(Validator $validator) {
* @return \Cake\Validation\Validator
*/
public function validationEmail(Validator $validator) {
$validator->provider('userTable', $this->_table);
$validator->setProvider('userTable', $this->_table);

$validator->add($this->_field('email'), [
'notBlank' => [
Expand Down Expand Up @@ -97,7 +96,7 @@ public function validationEmail(Validator $validator) {
* @return \Cake\Validation\Validator
*/
public function validationPassword(Validator $validator) {
$validator->provider('userTable', $this->_table);
$validator->setProvider('userTable', $this->_table);

$validator->add($this->_field('password'), [
'notBlank' => [
Expand Down Expand Up @@ -127,7 +126,7 @@ public function validationPassword(Validator $validator) {
* @return \Cake\Validation\Validator
*/
public function validationConfirmPassword(Validator $validator) {
$validator->provider('userBehavior', $this);
$validator->setProvider('userBehavior', $this);

$validator->add($this->_field('passwordCheck'), [
'notBlank' => [
Expand Down
9 changes: 5 additions & 4 deletions src/Shell/UserShell.php
Expand Up @@ -13,8 +13,7 @@
use Cake\ORM\TableRegistry;
use Cake\Datasource\ConnectionManager;

class UserShell extends Shell
{
class UserShell extends Shell {

/**
* Assign $this->connection to the active task if a connection param is set.
Expand Down Expand Up @@ -63,12 +62,14 @@ public function removeExpired() {
*/
public function setPassword() {
if (count($this->args) < 2) {
$this->error(__d('burzum/user_tools', 'You need to call this command with at least tow arguments.'));
$this->abort(__d('burzum/user_tools', 'You need to call this command with at least tow arguments.'));
}

$field = 'username';
if (count($this->args) >= 3) {
$field = $this->args[2];
}

$user = $this->UserTable->find()->where([$field => $this->args[0]])->first();
$user->password = $this->UserTable->hashPassword($this->args[1]);
if ($this->UserTable->save($user, ['validate' => false])) {
Expand All @@ -84,7 +85,7 @@ public function setPassword() {
public function getOptionParser() {
$parser = parent::getOptionParser();

$parser->description(
$parser->setDescription(
'Users utility shell'
)
->addOption('model', [
Expand Down
3 changes: 1 addition & 2 deletions src/Validation/UsersValidator.php
Expand Up @@ -10,8 +10,7 @@

use Cake\Validation\Validator;

class UsersValidator extends Validator
{
class UsersValidator extends Validator {

/**
* Constructor
Expand Down
131 changes: 64 additions & 67 deletions src/View/Helper/AuthHelper.php
Expand Up @@ -10,50 +10,48 @@

use Cake\Utility\Hash;
use Cake\View\Helper;
use Cake\View\View;
use InvalidArgumentException;

class AuthHelper extends Helper
{
class AuthHelper extends Helper {

/**
* Default settings
*
* @var array
*/
/**
* Default settings
*
* @var array
*/
protected $_defaultConfig = [
'session' => false,
'viewVar' => 'userData',
'viewVarException' => false,
'roleField' => 'role'
];

/**
* User data
*
* @array
*/
/**
* User data
*
* @array
*/
protected $_userData = [];

/**
* Constructor
*
* @param \Cake\View\View $View
* @param array $settings
* @throws RuntimeException
* @return AuthHelper
*/
/**
* Constructor
*
* @param \Cake\View\View $View View object
* @param array $settings Settings
* @throws RuntimeException
*/
public function __construct(\Cake\View\View $View, $settings = []) {
parent::__construct($View, $settings);

$this->_setupUserData();
}

/**
* Sets up the user data from session or view var
*
* @throws \RuntimeException
* @return void
*/
/**
* Sets up the user data from session or view var
*
* @throws \RuntimeException
* @return void
*/
protected function _setupUserData() {
if (is_string($this->_config['session'])) {
$this->_userData = $this->_View->request->session()->read($this->_config['session']);
Expand All @@ -70,14 +68,13 @@ protected function _setupUserData() {
}
}

/**
* Convenience method to the the user data in any case as array.
*
* This is mostly done because accessing the Entity object via Hash() caused an error when passing an object.
*
* @param bool $asArray Return as array, default true.
* @return array
*/
/**
* Convenience method to the the user data in any case as array.
* This is mostly done because accessing the Entity object via Hash() caused an error when passing an object.
*
* @param bool $asArray Return as array, default true.
* @return array
*/
protected function _userData($asArray = true) {
if ($asArray === true) {
if (is_a($this->_userData, '\Cake\ORM\Entity')) {
Expand All @@ -88,33 +85,33 @@ protected function _userData($asArray = true) {
return $this->_userData;
}

/**
* Checks if a user is logged in
*
* @return boolean
*/
/**
* Checks if a user is logged in
*
* @return bool
*/
public function isLoggedIn() {
return (!empty($this->_userData));
}

/**
* This check can be used to tell if a record that belongs to some user is the
* current logged in user
*
* @param int $userId
* @param string $field Name of the field in the user record to check against, id by default
* @return boolean
*/
/**
* This check can be used to tell if a record that belongs to some user is the
* current logged in user
*
* @param int $userId User Id
* @param string $field Name of the field in the user record to check against, id by default
* @return bool
*/
public function isMe($userId, $field = 'id') {
return ($userId === $this->user($field));
}

/**
* Method equal to the AuthComponent::user()
*
* @param string $key
* @return mixed
*/
/**
* Method equal to the AuthComponent::user()
*
* @param string $key Key to read from the user object
* @return mixed
*/
public function user($key = null) {
if ($key === null) {
return $this->_userData;
Expand All @@ -123,12 +120,12 @@ public function user($key = null) {
return Hash::get((array)$this->_userData(true), $key);
}

/**
* Role check.
*
* @param array|string Role string or set of role identifiers.
* @return boolean|null True if the role is in the set of roles for the active user data.
*/
/**
* Role check.
*
* @param array|string $requestedRole Role string or set of role identifiers.
* @return bool|null True if the role is in the set of roles for the active user data.
*/
public function hasRole($requestedRole) {
$roles = $this->user($this->config('roleField'));
if (is_null($roles)) {
Expand All @@ -138,13 +135,13 @@ public function hasRole($requestedRole) {
return $this->_checkRoles($requestedRole, $roles);
}

/**
* Checks the roles.
*
* @param string|array $requestedRole
* @param string|array $roles
* @return boolean
*/
/**
* Checks the roles.
*
* @param string|array $requestedRole Requested role
* @param string|array $roles List of roles
* @return bool
*/
protected function _checkRoles($requestedRole, $roles) {
if (is_string($roles)) {
$roles = [$roles];
Expand Down
3 changes: 2 additions & 1 deletion tests/Fixture/ProfileFixture.php
Expand Up @@ -10,7 +10,8 @@
* ]@copyright 2013 - 2017 Florian Krämer
* @license MIT
*/
class ProfileFixture extends TestFixture {
class ProfileFixture extends TestFixture
{

/**
* Fields
Expand Down

0 comments on commit 5b21cf4

Please sign in to comment.