actionLogin accesses the super-global variable $_POST. Open
public function actionLogin()
{
$model = new LoginForm();
if (\Yii::$app->request->isAjax) {
$model->load($_POST);
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
Method successOAuthCallback
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function successOAuthCallback($client)
{
// use BaseClient::normalizeUserAttributeMap to provide consistency for user attribute`s names
$attributes = $client->getUserAttributes();
$user = User::find()->where([
Function successOAuthCallback
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
public function successOAuthCallback($client)
{
// use BaseClient::normalizeUserAttributeMap to provide consistency for user attribute`s names
$attributes = $client->getUserAttributes();
$user = User::find()->where([
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
File SignInController.php
has 254 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/*
* This file is part of the HomeFinanceV2 project.
*
Method behaviors
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
Method actionSignup
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function actionSignup()
{
$model = new SignupForm();
if ($model->load(\Yii::$app->request->post())) {
$user = $model->signup();
Function actionSignup
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function actionSignup()
{
$model = new SignupForm();
if ($model->load(\Yii::$app->request->post())) {
$user = $model->signup();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
The class SignInController has a coupling between objects value of 17. Consider to reduce the number of dependencies under 13. Open
class SignInController extends \yii\web\Controller
{
/**
* @return array
*/
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
The method successOAuthCallback uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
// We already have a user with this email. Do what you want in such case
if ($user->email && User::find()->where(['email' => $user->email])->count()) {
\Yii::$app->session->setFlash(
'alert',
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method actionRequestPasswordReset uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
\Yii::$app->getSession()->setFlash('alert', [
'body' => \Yii::t('frontend', 'Sorry, we are unable to reset password for email provided.'),
'options'=>['class' => 'alert-danger']
]);
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method successOAuthCallback uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
throw new Exception('OAuth error');
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method successOAuthCallback uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
\Yii::$app->session->setFlash(
'alert',
[
'options' => ['class' => 'alert-danger'],
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method actionLogin uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return $this->render('login', [
'model' => $model
]);
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method actionSignup uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
\Yii::$app->getSession()->setFlash('alert', [
'body' => \Yii::t(
'frontend',
'Your account has been successfully created.'
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}