Showing 1,008 of 1,021 total issues
Method getCpNavItem
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getCpNavItem(): ?array
{
$subNavs = [];
$navItem = parent::getCpNavItem();
$navItem['label'] = $this->getSettings()->pluginLabel;
Method getSitemapData
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getSitemapData($siteId, $type, $sectionId)
{
$settings = $this->getSettingsBySiteId($siteId);
$data = [];
switch ($type) {
Function _addElementsToSitemap
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private function _addElementsToSitemap($entries, $settings)
{
$data = [];
$data[] = '<?xml version="1.0" encoding="UTF-8"?>';
$data[] = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9">';
- 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
Method getSchema
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getSchema(Element $element = null)
{
if (!$element) {
return null;
}
Avoid excessively long variable names like $createRedirectForUriChange. Keep variable name length under 20. Open
public $createRedirectForUriChange = true;
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $defaultMetaDescription. Keep variable name length under 20. Open
public $defaultMetaDescription;
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $allowSitenameOverwrite. Keep variable name length under 20. Open
public $allowSitenameOverwrite = false;
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $shouldRenderCategories. Keep variable name length under 20. Open
$shouldRenderCategories = array_filter($sitemapSettings['category'], function($group) use ($sitemapSettings) {
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $shouldRenderCategories. Keep variable name length under 20. Open
$shouldRenderCategories = false;
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Method safeUp
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function safeUp()
{
$tablesCreated = false;
$tableSchema = Craft::$app->db->schema->getTableSchema(RedirectRecord::tableName());
if ($tableSchema === null) {
Method handleNotFound
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function handleNotFound(Request $request, Site $site)
{
try {
$notFoundRecord = NotFoundRecord::findOne(['fullUrl' => $request->getAbsoluteUrl(), 'urlPath' => $request->getUrl(), 'siteId' => $site->id]);
if ($notFoundRecord) {
The class SeoFieldModel has 16 fields. Consider redesigning SeoFieldModel to keep the number of fields under 15. Open
class SeoFieldModel extends Model
{
public $metaTitle;
public $metaDescription;
- Read upRead up
- Exclude checks
TooManyFields
Since: 0.1
Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.
Example
class Person {
protected $one;
private $two;
private $three;
[... many more fields ...]
}
Source https://phpmd.org/rules/codesize.html#toomanyfields
Method import
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function import($data, $settings)
{
App::maxPowerCaptain();
$patternCol = $settings['patternCol'];
$redirectCol = $settings['redirectCol'];
Method getSitemapIndex
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getSitemapIndex($data)
{
$currentSite = Craft::$app->getSites()->getCurrentSite();
$cacheDependency = new TagDependency([
'tags' => [
Method safeUp
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function safeUp()
{
$tablesCreated = false;
$tableSchema = Craft::$app->db->schema->getTableSchema(NotFoundRecord::tableName());
if ($tableSchema === null) {
Method addForeignKeys
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function addForeignKeys()
{
// $name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null)
$this->addForeignKey(
$this->db->getForeignKeyName(DefaultsRecord::tableName(), 'siteId'),
Method _registerUrlChangeListeners
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function _registerUrlChangeListeners()
{
if (self::getInstance()->getSettings()->createRedirectForUriChange) {
$beforeEvents = [
Elements::EVENT_BEFORE_SAVE_ELEMENT,
Method getMatchingRedirect
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getMatchingRedirect(NotFoundModel $model): RedirectRecord|array|bool
{
Craft::debug("Check if our 404 is matched to a redirect", SeoFields::class);
$parsedUrl = parse_url($model->urlPath);
Method _registerPermissions
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function _registerPermissions()
{
Event::on(
UserPermissions::class,
UserPermissions::EVENT_REGISTER_PERMISSIONS,
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;
}
}