Close #109 provide better error classes + phpdoc fixes
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
- Enh #100: Added pt-BR translation (gugoan)
|
||||
- Enh #105: Consolidate 2fa messages (maxxer)
|
||||
- Fix #108: Use main logger app (tonydspaniard)
|
||||
- Enh #109: Make use of better classes names (tonydspaniard)
|
||||
|
||||
## 1.1.0 - October 22, 2017
|
||||
- Enh #91: Documentation for Mail events (kartik-v)
|
||||
|
||||
@ -33,6 +33,8 @@ class Bootstrap implements BootstrapInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
*/
|
||||
public function bootstrap($app)
|
||||
{
|
||||
@ -279,6 +281,7 @@ class Bootstrap implements BootstrapInterface
|
||||
*
|
||||
* @param array $userClassMap user configuration on the module
|
||||
*
|
||||
* @throws Exception
|
||||
* @return array
|
||||
*/
|
||||
protected function buildClassMap(array $userClassMap)
|
||||
@ -352,7 +355,7 @@ class Bootstrap implements BootstrapInterface
|
||||
protected function getRoute(array $routes, $name)
|
||||
{
|
||||
foreach ($routes as $route => $names) {
|
||||
if (in_array($name, $names)) {
|
||||
if (in_array($name, $names, false)) {
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,6 +35,8 @@ class PermissionController extends AbstractAuthItemController
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
protected function getItem($name)
|
||||
{
|
||||
|
||||
@ -24,6 +24,8 @@ use Da\User\Service\ResetPasswordService;
|
||||
use Da\User\Traits\ContainerAwareTrait;
|
||||
use Da\User\Validator\AjaxRequestModelValidator;
|
||||
use Yii;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\base\InvalidParamException;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
@ -74,6 +76,8 @@ class RecoveryController extends Controller
|
||||
* Displays / handles user password recovery request.
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
* @throws InvalidConfigException
|
||||
* @throws InvalidParamException
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
@ -118,6 +122,8 @@ class RecoveryController extends Controller
|
||||
* @param $code
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
* @throws InvalidConfigException
|
||||
* @throws InvalidParamException
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
|
||||
@ -35,6 +35,8 @@ class RoleController extends AbstractAuthItemController
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
protected function getItem($name)
|
||||
{
|
||||
|
||||
@ -21,6 +21,8 @@ use Da\User\Service\SocialNetworkAuthenticateService;
|
||||
use Da\User\Traits\ContainerAwareTrait;
|
||||
use Yii;
|
||||
use yii\authclient\AuthAction;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\base\InvalidParamException;
|
||||
use yii\base\Module;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\filters\VerbFilter;
|
||||
@ -102,6 +104,8 @@ class SecurityController extends Controller
|
||||
/**
|
||||
* Controller action responsible for handling login page and actions.
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
* @throws InvalidParamException
|
||||
* @return array|string|Response
|
||||
*/
|
||||
public function actionLogin()
|
||||
|
||||
@ -179,7 +179,7 @@ class SettingsController extends Controller
|
||||
{
|
||||
$user = $this->userQuery->whereId($id)->one();
|
||||
|
||||
if ($user === null || $this->module->emailChangeStrategy == MailChangeStrategyInterface::TYPE_INSECURE) {
|
||||
if ($user === null || MailChangeStrategyInterface::TYPE_INSECURE === $this->module->emailChangeStrategy) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
$event = $this->make(UserEvent::class, [$user]);
|
||||
@ -210,7 +210,7 @@ class SettingsController extends Controller
|
||||
if ($account === null) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
if ($account->user_id != Yii::$app->user->id) {
|
||||
if ($account->user_id !== Yii::$app->user->id) {
|
||||
throw new ForbiddenHttpException();
|
||||
}
|
||||
$event = $this->make(SocialNetworkConnectEvent::class, [Yii::$app->user->identity, $account]);
|
||||
|
||||
@ -18,6 +18,7 @@ use Da\User\Strategy\InsecureEmailChangeStrategy;
|
||||
use Da\User\Strategy\SecureEmailChangeStrategy;
|
||||
use Exception;
|
||||
use Yii;
|
||||
use yii\base\InvalidParamException;
|
||||
|
||||
class EmailChangeStrategyFactory
|
||||
{
|
||||
@ -41,7 +42,7 @@ class EmailChangeStrategyFactory
|
||||
return Yii::$container->get(static::$map[$strategy], [$form]);
|
||||
}
|
||||
|
||||
throw new Exception('Unknown strategy type');
|
||||
throw new InvalidParamException('Unknown strategy type');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -25,6 +25,7 @@ class MailFactory
|
||||
* @param User $user
|
||||
* @param bool $showPassword
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
* @return MailService
|
||||
*/
|
||||
public static function makeWelcomeMailerService(User $user, $showPassword = false)
|
||||
@ -48,6 +49,7 @@ class MailFactory
|
||||
* @param string $email
|
||||
* @param Token $token
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
* @return MailService
|
||||
*/
|
||||
public static function makeRecoveryMailerService($email, Token $token = null)
|
||||
@ -69,6 +71,7 @@ class MailFactory
|
||||
* @param User $user
|
||||
* @param Token|null $token
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
* @return MailService
|
||||
*/
|
||||
public static function makeConfirmationMailerService(User $user, Token $token = null)
|
||||
@ -90,6 +93,7 @@ class MailFactory
|
||||
* @param User $user
|
||||
* @param Token $token
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
* @return MailService
|
||||
*/
|
||||
public static function makeReconfirmationMailerService(User $user, Token $token)
|
||||
|
||||
@ -13,12 +13,14 @@ namespace Da\User\Factory;
|
||||
|
||||
use Da\User\Model\Token;
|
||||
use Yii;
|
||||
use yii\base\InvalidConfigException;
|
||||
|
||||
class TokenFactory
|
||||
{
|
||||
/**
|
||||
* @param $userId
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
* @return Token
|
||||
*/
|
||||
public static function makeConfirmationToken($userId)
|
||||
@ -47,6 +49,7 @@ class TokenFactory
|
||||
/**
|
||||
* @param $userId
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
* @return Token
|
||||
*/
|
||||
public static function makeConfirmOldMailToken($userId)
|
||||
@ -61,6 +64,7 @@ class TokenFactory
|
||||
/**
|
||||
* @param $userId
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
* @return Token
|
||||
*/
|
||||
public static function makeRecoveryToken($userId)
|
||||
@ -76,7 +80,8 @@ class TokenFactory
|
||||
* @param $userId
|
||||
* @param $type
|
||||
*
|
||||
* @return Token
|
||||
* @throws InvalidConfigException
|
||||
* @return Token|\object
|
||||
*/
|
||||
protected static function make($userId, $type)
|
||||
{
|
||||
|
||||
@ -18,6 +18,7 @@ use Da\User\Query\UserQuery;
|
||||
use Da\User\Traits\ModuleAwareTrait;
|
||||
use Da\User\Validator\TwoFactorCodeValidator;
|
||||
use Yii;
|
||||
use yii\base\InvalidParamException;
|
||||
use yii\base\Model;
|
||||
|
||||
class LoginForm extends Model
|
||||
@ -140,6 +141,7 @@ class LoginForm extends Model
|
||||
/**
|
||||
* Validates form and logs the user in.
|
||||
*
|
||||
* @throws InvalidParamException
|
||||
* @return bool whether the user is logged in successfully
|
||||
*/
|
||||
public function login()
|
||||
|
||||
@ -18,7 +18,9 @@ use Da\User\Traits\ContainerAwareTrait;
|
||||
use Da\User\Traits\ModuleAwareTrait;
|
||||
use Yii;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\base\InvalidParamException;
|
||||
use yii\base\Model;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class SettingsForm extends Model
|
||||
{
|
||||
@ -49,19 +51,28 @@ class SettingsForm extends Model
|
||||
/** @var User */
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* SettingsForm constructor.
|
||||
*
|
||||
* @param SecurityHelper $securityHelper
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct(SecurityHelper $securityHelper, array $config = [])
|
||||
{
|
||||
$this->securityHelper = $securityHelper;
|
||||
$config = [
|
||||
$config = ArrayHelper::merge(
|
||||
[
|
||||
'username' => $this->getUser()->username,
|
||||
'email' => $this->getUser()->unconfirmed_email ?: $this->getUser()->email
|
||||
];
|
||||
],
|
||||
$config
|
||||
);
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidConfigException
|
||||
* @throws \Exception
|
||||
* @throws InvalidParamException
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
|
||||
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Da\User\Helper;
|
||||
|
||||
use yii\base\InvalidParamException;
|
||||
|
||||
class ClassMapHelper
|
||||
{
|
||||
protected $map = [];
|
||||
@ -37,7 +39,7 @@ class ClassMapHelper
|
||||
/**
|
||||
* @param $key
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws InvalidParamException
|
||||
* @return mixed
|
||||
*
|
||||
*/
|
||||
@ -46,6 +48,6 @@ class ClassMapHelper
|
||||
if (array_key_exists($key, $this->map)) {
|
||||
return $this->map[$key];
|
||||
}
|
||||
throw new \Exception('Unknown model map key: ' . $key);
|
||||
throw new InvalidParamException('Unknown model map key: ' . $key);
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ abstract class AbstractAuthItem extends Model
|
||||
}
|
||||
},
|
||||
'when' => function () {
|
||||
return $this->scenario == 'create' || $this->item->name != $this->name;
|
||||
return $this->scenario === 'create' || $this->item->name !== $this->name;
|
||||
},
|
||||
],
|
||||
['children', RbacItemsValidator::class],
|
||||
|
||||
@ -20,6 +20,7 @@ use DateTime;
|
||||
use DateTimeZone;
|
||||
use Exception;
|
||||
use Yii;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\base\InvalidParamException;
|
||||
use yii\db\ActiveRecord;
|
||||
|
||||
@ -44,6 +45,7 @@ class Profile extends ActiveRecord
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws InvalidParamException
|
||||
* @throws InvalidConfigException
|
||||
*/
|
||||
public function beforeSave($insert)
|
||||
{
|
||||
@ -67,6 +69,8 @@ class Profile extends ActiveRecord
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
@ -125,6 +129,8 @@ class Profile extends ActiveRecord
|
||||
* Set the User's timezone.
|
||||
*
|
||||
* @param DateTimeZone $timezone
|
||||
*
|
||||
* @throws InvalidParamException
|
||||
*/
|
||||
public function setTimeZone(DateTimeZone $timezone)
|
||||
{
|
||||
@ -144,6 +150,7 @@ class Profile extends ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidConfigException
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getUser()
|
||||
@ -154,6 +161,7 @@ class Profile extends ActiveRecord
|
||||
/**
|
||||
* @param int $size
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAvatarUrl($size = 200)
|
||||
|
||||
@ -15,6 +15,8 @@ use Da\User\Query\SocialNetworkAccountQuery;
|
||||
use Da\User\Traits\ContainerAwareTrait;
|
||||
use Da\User\Traits\ModuleAwareTrait;
|
||||
use Yii;
|
||||
use yii\base\Exception;
|
||||
use yii\base\InvalidParamException;
|
||||
use yii\db\ActiveRecord;
|
||||
use yii\helpers\Url;
|
||||
|
||||
@ -55,7 +57,7 @@ class SocialNetworkAccount extends ActiveRecord
|
||||
*/
|
||||
public function getIsConnected()
|
||||
{
|
||||
return $this->user_id != null;
|
||||
return null !== $this->user_id;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,6 +73,8 @@ class SocialNetworkAccount extends ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws InvalidParamException
|
||||
* @return string the connection url
|
||||
*/
|
||||
public function getConnectionUrl()
|
||||
|
||||
@ -16,6 +16,8 @@ use Da\User\Query\TokenQuery;
|
||||
use Da\User\Traits\ContainerAwareTrait;
|
||||
use Da\User\Traits\ModuleAwareTrait;
|
||||
use RuntimeException;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\base\InvalidParamException;
|
||||
use yii\db\ActiveRecord;
|
||||
use yii\helpers\Url;
|
||||
|
||||
@ -49,6 +51,9 @@ class Token extends ActiveRecord
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws InvalidParamException
|
||||
* @throws InvalidConfigException
|
||||
*/
|
||||
public function beforeSave($insert)
|
||||
{
|
||||
@ -86,6 +91,7 @@ class Token extends ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidParamException
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl()
|
||||
@ -94,16 +100,17 @@ class Token extends ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
* @return bool Whether token has expired
|
||||
*/
|
||||
public function getIsExpired()
|
||||
{
|
||||
if ($this->type == static::TYPE_RECOVERY) {
|
||||
if ($this->type === static::TYPE_RECOVERY) {
|
||||
$expirationTime = $this->getModule()->tokenRecoveryLifespan;
|
||||
} elseif ($this->type >= static::TYPE_CONFIRMATION && $this->type <= static::TYPE_CONFIRM_OLD_EMAIL) {
|
||||
$expirationTime = $this->getModule()->tokenConfirmationLifespan;
|
||||
} else {
|
||||
throw new RuntimeException();
|
||||
throw new RuntimeException('Unknown Token type.');
|
||||
}
|
||||
|
||||
return ($this->created_at + $expirationTime) < time();
|
||||
|
||||
@ -16,6 +16,8 @@ use Da\User\Query\UserQuery;
|
||||
use Da\User\Traits\ContainerAwareTrait;
|
||||
use Da\User\Traits\ModuleAwareTrait;
|
||||
use Yii;
|
||||
use yii\base\Exception;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\base\InvalidParamException;
|
||||
use yii\base\NotSupportedException;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
@ -74,6 +76,8 @@ class User extends ActiveRecord implements IdentityInterface
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws InvalidParamException
|
||||
* @throws InvalidConfigException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function beforeSave($insert)
|
||||
{
|
||||
@ -98,6 +102,8 @@ class User extends ActiveRecord implements IdentityInterface
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
*/
|
||||
public function afterSave($insert, $changedAttributes)
|
||||
{
|
||||
@ -242,6 +248,7 @@ class User extends ActiveRecord implements IdentityInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidConfigException
|
||||
* @return bool whether the user is an admin or not
|
||||
*/
|
||||
public function getIsAdmin()
|
||||
@ -271,6 +278,8 @@ class User extends ActiveRecord implements IdentityInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidConfigException
|
||||
* @throws InvalidParamException
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getProfile()
|
||||
@ -285,7 +294,7 @@ class User extends ActiveRecord implements IdentityInterface
|
||||
*/
|
||||
public function getSocialNetworkAccounts()
|
||||
{
|
||||
if ($this->connectedAccounts == null) {
|
||||
if (null === $this->connectedAccounts) {
|
||||
/** @var SocialNetworkAccount[] $accounts */
|
||||
$accounts = $this->hasMany(
|
||||
$this->getClassMap()
|
||||
|
||||
@ -13,6 +13,8 @@ namespace Da\User\Search;
|
||||
|
||||
use Da\User\Model\Rule;
|
||||
use Da\User\Traits\ContainerAwareTrait;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\base\InvalidParamException;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\db\Query;
|
||||
@ -47,6 +49,8 @@ class RuleSearch extends Rule
|
||||
/**
|
||||
* @param array $params
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
* @throws InvalidParamException
|
||||
* @return ActiveDataProvider
|
||||
*/
|
||||
public function search(array $params = [])
|
||||
|
||||
@ -13,6 +13,7 @@ namespace Da\User\Search;
|
||||
|
||||
use Da\User\Query\UserQuery;
|
||||
use Yii;
|
||||
use yii\base\InvalidParamException;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
|
||||
@ -83,6 +84,7 @@ class UserSearch extends Model
|
||||
/**
|
||||
* @param $params
|
||||
*
|
||||
* @throws InvalidParamException
|
||||
* @return ActiveDataProvider
|
||||
*/
|
||||
public function search($params)
|
||||
|
||||
@ -16,6 +16,7 @@ use Da\User\Model\User;
|
||||
use Da\User\Service\MailService;
|
||||
use Exception;
|
||||
use Yii;
|
||||
use yii\base\InvalidConfigException;
|
||||
|
||||
/**
|
||||
* @property MailService $mailService
|
||||
@ -29,6 +30,7 @@ trait MailAwareTrait
|
||||
*
|
||||
* @param User $user
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
* @return bool
|
||||
*/
|
||||
protected function sendMail(User $user)
|
||||
|
||||
@ -13,6 +13,7 @@ namespace Da\User\Validator;
|
||||
|
||||
use Da\User\Component\ReCaptchaComponent;
|
||||
use Yii;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\validators\Validator;
|
||||
|
||||
class ReCaptchaValidator extends Validator
|
||||
@ -52,6 +53,8 @@ class ReCaptchaValidator extends Validator
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
*/
|
||||
protected function validateValue($value)
|
||||
{
|
||||
|
||||
@ -24,6 +24,6 @@ class TimeZoneValidator implements ValidatorInterface
|
||||
|
||||
public function validate()
|
||||
{
|
||||
return in_array($this->timezone, timezone_identifiers_list());
|
||||
return in_array($this->timezone, timezone_identifiers_list(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,6 +51,7 @@ class AssignmentsWidget extends Widget
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws InvalidParamException
|
||||
* @throws InvalidConfigException
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
|
||||
@ -15,6 +15,7 @@ use Yii;
|
||||
use yii\authclient\ClientInterface;
|
||||
use yii\authclient\widgets\AuthChoice;
|
||||
use yii\authclient\widgets\AuthChoiceAsset;
|
||||
use yii\base\InvalidParamException;
|
||||
use yii\helpers\Html;
|
||||
use yii\helpers\Url;
|
||||
|
||||
@ -40,6 +41,8 @@ class ConnectWidget extends AuthChoice
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws InvalidParamException
|
||||
*/
|
||||
public function createClientUrl($provider)
|
||||
{
|
||||
@ -59,6 +62,6 @@ class ConnectWidget extends AuthChoice
|
||||
*/
|
||||
public function isConnected(ClientInterface $provider)
|
||||
{
|
||||
return $this->accounts != null && isset($this->accounts[$provider->getId()]);
|
||||
return null !== $this->accounts && isset($this->accounts[$provider->getId()]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,6 +49,8 @@ class ReCaptchaWidget extends InputWidget
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
@ -78,6 +80,7 @@ class ReCaptchaWidget extends InputWidget
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidConfigException
|
||||
* @return array the google recaptcha options.
|
||||
*/
|
||||
protected function getCaptchaOptions()
|
||||
@ -156,7 +159,7 @@ class ReCaptchaWidget extends InputWidget
|
||||
'pt-PT'
|
||||
];
|
||||
|
||||
return in_array($language, $except)
|
||||
return in_array($language, $except, false)
|
||||
? $language
|
||||
: substr($language, 0, strpos($language, '-'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user