Method actionRedirects
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function actionRedirects()
{
$sort = $this->request->getQueryParam('sort');
$search = $this->request->getQueryParam('search');
if (!$sort) {
Method actionNotFound
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function actionNotFound()
{
$sort = $this->request->getQueryParam('sort');
$search = $this->request->getQueryParam('search');
if (!$sort) {
Avoid unused local variables such as '$from'. Open
$from = ($page - 1) * $limit + 1;
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Saw an @param annotation for siteHandle,
but the param list of function actionNotFound() : \yii\web\Response
is empty Open
* @param null $siteHandle
- Exclude checks
Return type of actionNotFound()
is undeclared type \yii\web\Response
Open
public function actionNotFound()
- Exclude checks
Reference to undeclared property \studioespresso\seofields\controllers\CpApiController->request
(Did you mean $_REQUEST) Open
$page = $this->request->getQueryParam('page', 1);
- Exclude checks
Call to undeclared method \studioespresso\seofields\controllers\CpApiController::asJson
Open
return $this->asJson([
- Exclude checks
Call to method toDateTime
from undeclared class \craft\helpers\DateTimeHelper
Open
$lastHit = DateTimeHelper::toDateTime($row->dateLastHit);
- Exclude checks
Reference to constant LENGTH_SHORT
from undeclared class \craft\i18n\Locale
(Did you mean class \Locale) Open
'lastHit' => $lastHit ? $formatter->asDatetime($lastHit, Locale::LENGTH_SHORT) : "",
- Exclude checks
Class extends undeclared class \craft\web\Controller
Open
class CpApiController extends Controller
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$formatter = Craft::$app->getFormatter();
- Exclude checks
Reference to constant LENGTH_SHORT
from undeclared class \craft\i18n\Locale
(Did you mean class \Locale) Open
'lastHit' => $formatter->asDatetime($lastHit, Locale::LENGTH_SHORT),
- Exclude checks
Call to undeclared method \studioespresso\seofields\controllers\CpApiController::asJson
Open
return $this->asJson([
- Exclude checks
Static call to undeclared method \studioespresso\seofields\records\NotFoundRecord::find
Open
$query = NotFoundRecord::find();
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
'site' => Craft::$app->getSites()->getSiteById($row->siteId)->name,
- Exclude checks
Reference to undeclared property \studioespresso\seofields\controllers\CpApiController->request
(Did you mean $_REQUEST) Open
$search = $this->request->getQueryParam('search');
- Exclude checks
Call to method parseParam
from undeclared class \craft\helpers\Db
Open
$query->orWhere(Db::parseParam('siteId', $site->id));
- Exclude checks
Static call to undeclared method \studioespresso\seofields\records\RedirectRecord::find
Open
$query = RedirectRecord::find();
- Exclude checks
Reference to undeclared property \studioespresso\seofields\controllers\CpApiController->request
(Did you mean $_REQUEST) Open
$site = $this->request->getQueryParam('site');
- Exclude checks
Call to method toDateTime
from undeclared class \craft\helpers\DateTimeHelper
Open
$lastHit = DateTimeHelper::toDateTime($row->dateLastHit);
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$formatter = Craft::$app->getFormatter();
- Exclude checks
Reference to undeclared property \studioespresso\seofields\controllers\CpApiController->request
(Did you mean $_REQUEST) Open
$search = $this->request->getQueryParam('search');
- Exclude checks
Reference to undeclared property \studioespresso\seofields\controllers\CpApiController->request
(Did you mean $_REQUEST) Open
$site = $this->request->getQueryParam('site');
- Exclude checks
Reference to undeclared property \studioespresso\seofields\controllers\CpApiController->request
(Did you mean $_REQUEST) Open
$sort = $this->request->getQueryParam('sort');
- Exclude checks
Reference to undeclared property \studioespresso\seofields\controllers\CpApiController->request
(Did you mean $_REQUEST) Open
$page = $this->request->getQueryParam('page', 1);
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$site = Craft::$app->getSites()->getSiteByHandle($site);
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
'site' => !$row->siteId ? "All" : Craft::$app->getSites()->getSiteById($row->siteId)->name,
- Exclude checks
Reference to undeclared property \studioespresso\seofields\controllers\CpApiController->request
(Did you mean $_REQUEST) Open
$sort = $this->request->getQueryParam('sort');
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$site = Craft::$app->getSites()->getSiteByHandle($site);
- Exclude checks
Call to method cpUrl
from undeclared class \craft\helpers\UrlHelper
Open
'url' => UrlHelper::cpUrl("seo-fields/redirects/edit/{$row->id}"),
- Exclude checks
Call to method parseParam
from undeclared class \craft\helpers\Db
Open
$query->orWhere(Db::parseParam('siteId', $site->id));
- Exclude checks
Avoid using static access to class '\studioespresso\seofields\records\NotFoundRecord' in method 'actionNotFound'. Open
$query = NotFoundRecord::find();
- 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 'actionRedirects'. Open
'url' => UrlHelper::cpUrl("seo-fields/redirects/edit/{$row->id}"),
- 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\Db' in method 'actionNotFound'. Open
$query->orWhere(Db::parseParam('siteId', $site->id));
- 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\DateTimeHelper' in method 'actionNotFound'. Open
$lastHit = DateTimeHelper::toDateTime($row->dateLastHit);
- 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 '\studioespresso\seofields\records\RedirectRecord' in method 'actionRedirects'. Open
$query = RedirectRecord::find();
- 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\Db' in method 'actionRedirects'. Open
$query->orWhere(Db::parseParam('siteId', $site->id));
- 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\DateTimeHelper' in method 'actionRedirects'. Open
$lastHit = DateTimeHelper::toDateTime($row->dateLastHit);
- 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 "siteId" 3 times. Open
$query->orWhere(Db::parseParam('siteId', $site->id));
- 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.
Avoid variables with short names like $to. Configured minimum length is 3. Open
$to = (int)$page === $lastPage ? $total : ($page * $limit);
- 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 $to. Configured minimum length is 3. Open
$to = intval($page) === intval($lastPage) ? $total : ($page * $limit);
- 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;
}
}
}