Function getSitesMenu
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function getSitesMenu()
{
$sites = [
0 => Craft::t('seo-fields', 'All Sites'),
];
- 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
Function actionSave
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function actionSave()
{
$id = $this->request->getBodyParam('redirectId');
$record = $this->request->getBodyParam('record');
if ($id) {
- 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
Avoid using undefined variables such as '$variables' which will lead to PHP notices. Open
$variables['filename'] = $filePath;
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$variables' which will lead to PHP notices. Open
$variables['filename'] = $filePath;
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$variables' which will lead to PHP notices. Open
$variables['headers'] = $headers;
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$variables' which will lead to PHP notices. Open
$variables['sites'] = $this->getSitesMenu();
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$variables' which will lead to PHP notices. Open
$variables['headers'] = $headers;
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$variables' which will lead to PHP notices. Open
$variables['filename'] = $filePath;
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$variables' which will lead to PHP notices. Open
$this->renderTemplate('seo-fields/_redirect/_import', $variables);
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$variables' which will lead to PHP notices. Open
$variables['headers'] = $headers;
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using static access to class '\craft\helpers\App' in method 'actionRunImport'. Open
App::maxPowerCaptain();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\League\Csv\Reader' in method 'actionRunImport'. Open
$reader = Reader::createFromPath($filePath);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\craft\helpers\UrlHelper' in method 'actionUpload'. Open
$this->redirect(UrlHelper::cpUrl('seo-fields/redirects/import'));
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method actionSave uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$model = new RedirectModel();
}
- 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
Avoid using static access to class '\League\Csv\Reader' in method 'actionImport'. Open
$csv = Reader::createFromPath($filePath);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\yii\web\UploadedFile' in method 'actionUpload'. Open
$file = UploadedFile::getInstanceByName('file');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\League\Csv\Reader' in method 'actionUpload'. Open
$csv = Reader::createFromPath($file->tempName);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Craft' in method 'actionSave'. Open
Craft::$app->getSession()->setNotice(Craft::t('seo-fields', 'Redirect saved'));
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Craft' in method 'getSitesMenu'. Open
0 => Craft::t('seo-fields', 'All Sites'),
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Craft' in method 'actionSave'. Open
Craft::$app->getSession()->setError(Craft::t('app', 'Couldn’t save redirect.'));
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Craft' in method 'actionUpload'. Open
Craft::info(print_r($headers, true), __METHOD__);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\craft\helpers\UrlHelper' in method 'actionImport'. Open
return $this->redirect(UrlHelper::cpUrl('seo-fields/redirects'));
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Craft' in method 'actionDelete'. Open
Craft::$app->getSession()->setNotice(Craft::t('seo-fields', 'Redirect removed'));
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Define a constant instead of duplicating this literal "record" 3 times. Open
'record' => Craft::$app->getRequest()->getParam('record') ?? null,
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "seo-fields/_redirect/_entry" 3 times. Open
return $this->renderTemplate('seo-fields/_redirect/_entry', [
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "seo-fields" 3 times. Open
Craft::$app->getSession()->setNotice(Craft::t('seo-fields', 'Redirect saved'));
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "sites" 4 times. Open
'sites' => $this->getSitesMenu(),
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "method" 3 times. Open
if (!$data['pattern'] || $data['redirect'] || $data['method']) {
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "headers" 3 times. Open
$variables['headers'] = $headers;
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "pattern" 4 times. Open
'pattern' => Craft::$app->getRequest()->getParam('pattern') ?? null,
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "filename" 3 times. Open
$variables['filename'] = $filePath;
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Remove this commented out code. Open
//$headers = $reader->fetchOne(0);
- Read upRead up
- Exclude checks
Programmers should not comment out code as it bloats programs and reduces readability.
Unused code should be deleted and can be retrieved from source control history if required.
See
- MISRA C:2004, 2.4 - Sections of code should not be "commented out".
- MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
- MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
- MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"
Avoid using empty try-catch blocks in getRows. Open
} catch (\Throwable $e) {
}
- Read upRead up
- Exclude checks
EmptyCatchBlock
Since: 2.7.0
Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.
Example
class Foo {
public function bar()
{
try {
// ...
} catch (Exception $e) {} // empty catch block
}
}
Source https://phpmd.org/rules/design.html#emptycatchblock
Avoid using empty try-catch blocks in getRows. Open
} catch (\Throwable $e) {
}
- Read upRead up
- Exclude checks
EmptyCatchBlock
Since: 2.7.0
Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.
Example
class Foo {
public function bar()
{
try {
// ...
} catch (Exception $e) {} // empty catch block
}
}
Source https://phpmd.org/rules/design.html#emptycatchblock
Avoid using empty try-catch blocks in getHeaders. Open
} catch (\Throwable $e) {
}
- Read upRead up
- Exclude checks
EmptyCatchBlock
Since: 2.7.0
Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.
Example
class Foo {
public function bar()
{
try {
// ...
} catch (Exception $e) {} // empty catch block
}
}
Source https://phpmd.org/rules/design.html#emptycatchblock
Avoid using empty try-catch blocks in getHeaders. Open
} catch (\Throwable $e) {
}
- Read upRead up
- Exclude checks
EmptyCatchBlock
Since: 2.7.0
Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.
Example
class Foo {
public function bar()
{
try {
// ...
} catch (Exception $e) {} // empty catch block
}
}
Source https://phpmd.org/rules/design.html#emptycatchblock
Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::renderTemplate
Open
return $this->renderTemplate('seo-fields/_redirect/_entry', [
- Exclude checks
Call to method t
from undeclared class \Craft
Open
Craft::$app->getSession()->setError(Craft::t('app', 'Couldn’t save redirect.'));
- Exclude checks
Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::redirect
Open
$this->redirect(UrlHelper::cpUrl('seo-fields/redirects/import'));
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$filePath = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $filename;
- Exclude checks
Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::renderTemplate
Open
return $this->renderTemplate('seo-fields/_redirect/_import_results', $results);
- Exclude checks
Call to method t
from undeclared class \Craft
Open
Craft::$app->getSession()->setNotice(Craft::t('seo-fields', 'Redirect removed'));
- Exclude checks
Reference to undeclared property \studioespresso\seofields\controllers\RedirectsController->request
(Did you mean $_REQUEST) Open
$id = $this->request->getBodyParam('id');
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$model->setAttributes(Craft::$app->getRequest()->getBodyParam('fields'));
- Exclude checks
Call to method info
from undeclared class \Craft
Open
Craft::info(print_r($headers, true), __METHOD__);
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
if (Craft::$app->getIsMultiSite()) {
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$editableSites = Craft::$app->getSites()->getEditableSiteIds();
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$filePath = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $filename;
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
Craft::$app->getSession()->setNotice(Craft::t('seo-fields', 'Redirect removed'));
- Exclude checks
Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::renderTemplate
Open
return $this->renderTemplate('seo-fields/_redirect/_entry', [
- Exclude checks
Call to method t
from undeclared class \Craft
Open
Craft::$app->getSession()->setNotice(Craft::t('seo-fields', 'Redirect saved'));
- Exclude checks
Call to method createFromPath
from undeclared class \League\Csv\Reader
Open
$csv = Reader::createFromPath($file->tempName);
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$request = Craft::$app->getRequest();
- Exclude checks
Parameter $reader
has undeclared type \League\Csv\Reader
Open
private function getRows(Reader $reader)
- Exclude checks
Call to method getInstance
from undeclared class \studioespresso\seofields\SeoFields
Open
$redirect = SeoFields::getInstance()->redirectService->getRedirectById($id);
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$filePath = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $filename;
- Exclude checks
Call to method cpUrl
from undeclared class \craft\helpers\UrlHelper
Open
return $this->redirect(UrlHelper::cpUrl('seo-fields/redirects'));
- Exclude checks
Call to method getInstance
from undeclared class \studioespresso\seofields\SeoFields
Open
$results = SeoFields::getInstance()->redirectService->import($rows, $settings);
- Exclude checks
Call to undeclared method \studioespresso\seofields\models\RedirectModel::setAttributes
Open
$model->setAttributes(Craft::$app->getRequest()->getBodyParam('fields'));
- Exclude checks
Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::redirectToPostedUrl
Open
$this->redirectToPostedUrl();
- Exclude checks
Call to method t
from undeclared class \Craft
Open
0 => Craft::t('seo-fields', 'All Sites'),
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
'record' => Craft::$app->getRequest()->getParam('record') ?? null,
- Exclude checks
Call to method getInstance
from undeclared class \studioespresso\seofields\SeoFields
Open
$saved = SeoFields::getInstance()->redirectService->saveRedirect($model);
- Exclude checks
Call to method createFromPath
from undeclared class \League\Csv\Reader
Open
$csv = Reader::createFromPath($filePath);
- Exclude checks
Variable $variables
was undeclared, but array fields are being added to it. Open
$variables['headers'] = $headers;
- Exclude checks
Variable $variables
was undeclared, but array fields are being added to it. Open
$variables['headers'] = $headers;
- Exclude checks
Call to method getInstance
from undeclared class \studioespresso\seofields\SeoFields
Open
if (SeoFields::getInstance()->redirectService->deleteRedirectById($id)) {
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$groupSites = Craft::$app->getSites()->getSitesByGroupId($group->id);
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
Craft::$app->getSession()->setError(Craft::t('app', 'Couldn’t save redirect.'));
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
foreach (Craft::$app->getSites()->getAllGroups() as $group) {
- Exclude checks
Call to method getInstance
from undeclared class \studioespresso\seofields\SeoFields
Open
$redirects = SeoFields::getInstance()->redirectService->getAllRedirects($searchParam);
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
Craft::$app->getSession()->setNotice(Craft::t('seo-fields', 'Redirect saved'));
- Exclude checks
Variable $variables
was undeclared, but array fields are being added to it. Open
$variables['headers'] = $headers;
- Exclude checks
Call to method cpUrl
from undeclared class \craft\helpers\UrlHelper
Open
$this->redirect(UrlHelper::cpUrl('seo-fields/redirects/import'));
- Exclude checks
Call to method getIterator
from undeclared class \League\Csv\Reader
Open
return $reader->getIterator();
- Exclude checks
Call to method createFromPath
from undeclared class \League\Csv\Reader
Open
$reader = Reader::createFromPath($filePath);
- Exclude checks
Class extends undeclared class \craft\web\Controller
Open
class RedirectsController extends Controller
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
'pattern' => Craft::$app->getRequest()->getParam('pattern') ?? null,
- Exclude checks
Reference to undeclared property \studioespresso\seofields\controllers\RedirectsController->request
(Did you mean $_REQUEST) Open
$id = $this->request->getBodyParam('redirectId');
- Exclude checks
Call to method getInstance
from undeclared class \studioespresso\seofields\SeoFields
Open
SeoFields::getInstance()->notFoundService->markAsHandled($record);
- Exclude checks
Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::requirePostRequest
Open
$this->requirePostRequest();
- Exclude checks
Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::renderTemplate
Open
$this->renderTemplate('seo-fields/_redirect/_import', $variables);
- Exclude checks
Call to method maxPowerCaptain
from undeclared class \craft\helpers\App
Open
App::maxPowerCaptain();
- Exclude checks
Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::renderTemplate
Open
return $this->renderTemplate('seo-fields/_redirect/_index', ['redirects' => $redirects]);
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$searchParam = Craft::$app->getRequest()->getParam('search');
- Exclude checks
Call to method getInstance
from undeclared class \studioespresso\seofields\SeoFields
Open
$model = SeoFields::getInstance()->redirectService->getRedirectById($id);
- Exclude checks
Call to undeclared method \studioespresso\seofields\models\RedirectModel::validate
Open
if ($model->validate()) {
- Exclude checks
Reference to undeclared property \studioespresso\seofields\controllers\RedirectsController->request
(Did you mean $_REQUEST) Open
$record = $this->request->getBodyParam('record');
- Exclude checks
Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::renderTemplate
Open
return $this->renderTemplate('seo-fields/_redirect/_entry', [
- Exclude checks
Call to method getInstanceByName
from undeclared class \yii\web\UploadedFile
Open
$file = UploadedFile::getInstanceByName('file');
- Exclude checks
Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::asJson
Open
return $this->asJson(['success' => true]);
- Exclude checks
Call to undeclared method \studioespresso\seofields\controllers\RedirectsController::redirect
Open
return $this->redirect(UrlHelper::cpUrl('seo-fields/redirects'));
- Exclude checks
Call to method fetchAll
from undeclared class \League\Csv\Reader
Open
return $reader->fetchAll();
- Exclude checks
Either remove or fill this block of code. Open
} catch (\Throwable $e) {
}
- Read upRead up
- Exclude checks
Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.
Noncompliant Code Example
for ($i = 0; $i < 42; $i++){} // Empty on purpose or missing piece of code ?
Exceptions
When a block contains a comment, this block is not considered to be empty.
Either remove or fill this block of code. Open
if (!$data['pattern'] || $data['redirect'] || $data['method']) {
}
- Read upRead up
- Exclude checks
Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.
Noncompliant Code Example
for ($i = 0; $i < 42; $i++){} // Empty on purpose or missing piece of code ?
Exceptions
When a block contains a comment, this block is not considered to be empty.
Either remove or fill this block of code. Open
} catch (\Throwable $e) {
}
- Read upRead up
- Exclude checks
Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.
Noncompliant Code Example
for ($i = 0; $i < 42; $i++){} // Empty on purpose or missing piece of code ?
Exceptions
When a block contains a comment, this block is not considered to be empty.
Either remove or fill this block of code. Open
} catch (\Throwable $e) {
}
- Read upRead up
- Exclude checks
Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.
Noncompliant Code Example
for ($i = 0; $i < 42; $i++){} // Empty on purpose or missing piece of code ?
Exceptions
When a block contains a comment, this block is not considered to be empty.
Either remove or fill this block of code. Open
} catch (\Throwable $e) {
}
- Read upRead up
- Exclude checks
Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.
Noncompliant Code Example
for ($i = 0; $i < 42; $i++){} // Empty on purpose or missing piece of code ?
Exceptions
When a block contains a comment, this block is not considered to be empty.
Avoid variables with short names like $id. Configured minimum length is 3. Open
$id = $this->request->getBodyParam('redirectId');
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $id. Configured minimum length is 3. Open
public function actionEdit($id)
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $id. Configured minimum length is 3. Open
$id = $this->request->getBodyParam('id');
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}