File SeoFields.php
has 394 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* SEO Fields plugin for Craft CMS 3.x
*
* Fields for your SEO & OG data
Function _registerUrlChangeListeners
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
private function _registerUrlChangeListeners()
{
if (self::getInstance()->getSettings()->createRedirectForUriChange) {
$beforeEvents = [
Elements::EVENT_BEFORE_SAVE_ELEMENT,
- 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 _registerCpListeners
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function _registerCpListeners()
{
Event::on(
Sites::class,
Sites::EVENT_AFTER_SAVE_SITE,
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 _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 _registerPermissions
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function _registerPermissions()
{
Event::on(
UserPermissions::class,
UserPermissions::EVENT_REGISTER_PERMISSIONS,
Method init
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function init()
{
parent::init();
self::$plugin = $this;
Function getCpNavItem
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getCpNavItem(): ?array
{
$subNavs = [];
$navItem = parent::getCpNavItem();
$navItem['label'] = $this->getSettings()->pluginLabel;
- 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 method _registerUrlChangeListeners() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
private function _registerUrlChangeListeners()
{
if (self::getInstance()->getSettings()->createRedirectForUriChange) {
$beforeEvents = [
Elements::EVENT_BEFORE_SAVE_ELEMENT,
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The class SeoFields has a coupling between objects value of 42. Consider to reduce the number of dependencies under 13. Open
class SeoFields extends Plugin
{
// Static Properties
// =========================================================================
- 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
Avoid using static access to class '\Craft' in method '_registerPermissions'. Open
$event->permissions[Craft::t('seo-fields', 'SEO Fields')] = $permissions;
- 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\base\Event' in method '_registerCpRoutes'. Open
Event::on(
UrlManager::class,
UrlManager::EVENT_REGISTER_CP_URL_RULES,
function(RegisterUrlRulesEvent $event) {
// Register our Control Panel routes
- 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 '_registerSiteListeners'. Open
Craft::error($e->getMessage(), __CLASS__);
- 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\base\Event' in method '_registerElementBehaviors'. Open
Event::on(Product::class, Product::EVENT_DEFINE_BEHAVIORS, function(DefineBehaviorsEvent $event) {
$event->behaviors[$this->id] = ElementSeoBehavior::class;
});
- 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 '_registerSiteListeners'. Open
Craft::debug("404 exception, processing...", __CLASS__);
- 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\ElementHelper' in method '_registerUrlChangeListeners'. Open
if (ElementHelper::isDraftOrRevision($event->element)) {
- 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 '_registerPermissions'. Open
'label' => Craft::t('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 '_registerPermissions'. Open
'label' => Craft::t('seo-fields', "Schema.org"),
- 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 '_registerPermissions'. Open
'label' => Craft::t('seo-fields', 'Sitemap'),
- 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 '_registerCpListeners'. Open
Craft::error($e->getMessage(), __CLASS__);
- 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\base\Event' in method '_registerSiteListeners'. Open
Event::on(
ErrorHandler::class,
ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION,
function(ExceptionEvent $event) {
try {
- 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\base\Event' in method '_registerElementBehaviors'. Open
Event::on(Entry::class, Entry::EVENT_DEFINE_BEHAVIORS, function(DefineBehaviorsEvent $event) {
$event->behaviors[$this->id] = ElementSeoBehavior::class;
});
- 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 '_registerPermissions'. Open
'label' => Craft::t('seo-fields', 'Meta'),
- 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 _registerFrontendRoutes uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$shouldRender = SeoFields::getInstance()->sitemapSerivce->shouldRenderBySiteId(Craft::$app->getSites()->getPrimarySite());
}
- 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 '\yii\base\Event' in method '_registerCpListeners'. Open
Event::on(
Sites::class,
Sites::EVENT_AFTER_SAVE_SITE,
function(SiteEvent $event) {
if ($event->isNew) {
- 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\base\Event' in method '_registerCpListeners'. Open
Event::on(
Elements::class,
Elements::EVENT_AFTER_SAVE_ELEMENT,
function(ElementEvent $event) {
SeoFields::$plugin->sitemapSerivce->clearCacheForElement($event->element);
- 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\base\Event' in method '_registerCpListeners'. Open
Event::on(Gc::class, Gc::EVENT_RUN, function() {
try {
$limit = SeoFields::$plugin->getSettings()->notFoundLimit;
if (!is_int($limit)) {
return;
- 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\NotFoundRecord' in method '_registerCpListeners'. 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 '\yii\base\Event' in method '_registerCustomElements'. Open
Event::on(SeoFields::class, SeoFields::EVENT_SEOFIELDS_REGISTER_ELEMENT,
function(RegisterSeoElementEvent $event) use ($elements) {
$event->elements = array_merge($event->elements, $elements);
}
);
- 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 '_registerPermissions'. Open
'label' => Craft::t('seo-fields', 'Robots'),
- 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\ElementHelper' in method '_registerUrlChangeListeners'. Open
if (ElementHelper::isDraftOrRevision($event->element)) {
- 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\base\Event' in method '_registerCacheOptions'. Open
Event::on(
ClearCaches::class,
ClearCaches::EVENT_REGISTER_CACHE_OPTIONS,
function(RegisterCacheOptionsEvent $event) {
// Register our Control Panel routes
- 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\base\Event' in method '_registerCpListeners'. Open
Event::on(
Sections::class,
Sections::EVENT_AFTER_DELETE_ENTRY_TYPE,
function(EntryTypeEvent $event) {
SeoFields::$plugin->sitemapSerivce->clearCaches();
- 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 '_registerPermissions'. Open
'label' => Craft::t('seo-fields', "404's"),
- 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\base\Event' in method '_registerCpListeners'. Open
Event::on(
Elements::class,
Elements::EVENT_AFTER_DELETE_ELEMENT,
function(ElementEvent $event) {
SeoFields::$plugin->sitemapSerivce->clearCacheForElement($event->element);
- 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\base\Event' in method '_registerCpListeners'. Open
Event::on(
Sections::class,
Sections::EVENT_AFTER_DELETE_SECTION,
function(SectionEvent $event) {
SeoFields::$plugin->sitemapSerivce->clearCaches();
- 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\base\Event' in method '_registerFrontendRoutes'. Open
Event::on(
UrlManager::class,
UrlManager::EVENT_REGISTER_SITE_URL_RULES,
function(RegisterUrlRulesEvent $event) {
$robots = SeoFields::$plugin->defaultsService->getRobotsForSite(Craft::$app->getSites()->getCurrentSite());
- 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\base\Event' in method '_registerUrlChangeListeners'. Open
Event::on(Elements::class, $event, function(ElementEvent $event) {
$shouldCheckSlug = true;
if (ElementHelper::isDraftOrRevision($event->element)) {
$shouldCheckSlug = false;
}
- 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 'afterInstall'. Open
Craft::$app->getResponse()->redirect(UrlHelper::cpUrl('seo-fields', ['showIntroduction' => true]))->send();
- 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\base\Event' in method '_registerField'. Open
Event::on(
Fields::class,
Fields::EVENT_REGISTER_FIELD_TYPES,
function(RegisterComponentTypesEvent $event) {
$event->types[] = SeoField::class;
- 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\base\Event' in method '_registerPermissions'. Open
Event::on(
UserPermissions::class,
UserPermissions::EVENT_REGISTER_PERMISSIONS,
function(RegisterUserPermissionsEvent $event) {
- 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 '_registerPermissions'. Open
"heading" => Craft::t('seo-fields', 'SEO Fields'),
- 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\base\Event' in method '_registerUrlChangeListeners'. Open
Event::on(Elements::class, $event, function(ElementEvent $event) {
$shouldCheckSlug = true;
if (ElementHelper::isDraftOrRevision($event->element)) {
$shouldCheckSlug = false;
}
- 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
syntax error, unexpected 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
Open
public string $schemaVersion = "4.0.0";
- Exclude checks
Similar blocks of code found in 2 locations. Consider refactoring. Open
foreach ($afterEvents as $event) {
Event::on(Elements::class, $event, function(ElementEvent $event) {
$shouldCheckSlug = true;
if (ElementHelper::isDraftOrRevision($event->element)) {
$shouldCheckSlug = false;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 102.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
foreach ($beforeEvents as $event) {
Event::on(Elements::class, $event, function(ElementEvent $event) {
$shouldCheckSlug = true;
if (ElementHelper::isDraftOrRevision($event->element)) {
$shouldCheckSlug = false;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 102.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Expected 1 space after FUNCTION keyword; 0 found Open
function(RegisterUserPermissionsEvent $event) {
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
function(RegisterUrlRulesEvent $event) {
- Exclude checks
Method name "_registerField" should not be prefixed with an underscore to indicate visibility Open
private function _registerField()
- Exclude checks
Method name "_registerCpRoutes" should not be prefixed with an underscore to indicate visibility Open
private function _registerCpRoutes()
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
function(SectionEvent $event) {
- Exclude checks
Method name "_registerUrlChangeListeners" should not be prefixed with an underscore to indicate visibility Open
private function _registerUrlChangeListeners()
- Exclude checks
Method name "_registerCpListeners" should not be prefixed with an underscore to indicate visibility Open
private function _registerCpListeners()
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
function(SiteEvent $event) {
- Exclude checks
Method name "_registerSiteListeners" should not be prefixed with an underscore to indicate visibility Open
private function _registerSiteListeners()
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
Event::on(Elements::class, $event, function(ElementEvent $event) {
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
function(ElementEvent $event) {
- Exclude checks
Method name "_registerCustomElements" should not be prefixed with an underscore to indicate visibility Open
private function _registerCustomElements()
- Exclude checks
Method name "_registerFrontendRoutes" should not be prefixed with an underscore to indicate visibility Open
private function _registerFrontendRoutes()
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
function(RegisterUrlRulesEvent $event) {
- Exclude checks
Method name "_registerElementBehaviors" should not be prefixed with an underscore to indicate visibility Open
private function _registerElementBehaviors(): void
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
Event::on(Elements::class, $event, function(ElementEvent $event) {
- Exclude checks
Method name "_registerCacheOptions" should not be prefixed with an underscore to indicate visibility Open
private function _registerCacheOptions()
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
function(EntryTypeEvent $event) {
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
Craft::$app->view->hook('seo-fields', function(array &$context) {
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
function(RegisterComponentTypesEvent $event) {
- Exclude checks
Method name "_registerPermissions" should not be prefixed with an underscore to indicate visibility Open
private function _registerPermissions()
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
Event::on(Gc::class, Gc::EVENT_RUN, function() {
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
function(ExceptionEvent $event) {
- Exclude checks
Method name "_registerTwigExtension" should not be prefixed with an underscore to indicate visibility Open
private function _registerTwigExtension()
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
function(ElementEvent $event) {
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
function(RegisterCacheOptionsEvent $event) {
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
Event::on(Entry::class, Entry::EVENT_DEFINE_BEHAVIORS, function(DefineBehaviorsEvent $event) {
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
function(RegisterSeoElementEvent $event) use ($elements) {
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
Event::on(Product::class, Product::EVENT_DEFINE_BEHAVIORS, function(DefineBehaviorsEvent $event) {
- Exclude checks
Only one argument is allowed per line in a multi-line function call Open
Event::on(SeoFields::class, SeoFields::EVENT_SEOFIELDS_REGISTER_ELEMENT,
- Exclude checks
Only one argument is allowed per line in a multi-line function call Open
$event->options, [
- Exclude checks
Line exceeds 120 characters; contains 124 characters Open
'seo-fields/<controller:(redirects|not-found)>/<action>/<id:\d+>' => 'seo-fields/<controller>/<action>',
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
$robots = SeoFields::$plugin->defaultsService->getRobotsForSite(Craft::$app->getSites()->getCurrentSite());
- Exclude checks
Line exceeds 120 characters; contains 142 characters Open
$shouldRender = SeoFields::getInstance()->sitemapSerivce->shouldRenderBySiteId(Craft::$app->getSites()->getCurrentSite());
- Exclude checks
Line exceeds 120 characters; contains 139 characters Open
'seo-fields/<controller:(defaults|robots|sitemap|schema)>/<siteHandle:{handle}>' => 'seo-fields/<controller>/settings',
- Exclude checks
Line exceeds 120 characters; contains 142 characters Open
$shouldRender = SeoFields::getInstance()->sitemapSerivce->shouldRenderBySiteId(Craft::$app->getSites()->getPrimarySite());
- Exclude checks
Line exceeds 120 characters; contains 159 characters Open
if ($event->exception instanceof HttpException && $event->exception->statusCode === 404 && Craft::$app->getRequest()->getIsSiteRequest()) {
- Exclude checks
Line exceeds 120 characters; contains 142 characters Open
'sitemap_<siteId:\d+>_<type:(entry|product|category)>_<sectionId:\d+>_<handle:.*>.xml' => 'seo-fields/sitemap/detail',
- Exclude checks
Line exceeds 120 characters; contains 134 characters Open
'seo-fields/<controller:(defaults|robots|sitemap|not-found|redirects|schema)>' => 'seo-fields/<controller>/index',
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
]);
- Exclude checks
Opening parenthesis of a multi-line function call must be the last content on the line Open
Event::on(SeoFields::class, SeoFields::EVENT_SEOFIELDS_REGISTER_ELEMENT,
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 16 Open
]);
- Exclude checks
The method _registerPermissions is not named in camelCase. Open
private function _registerPermissions()
{
Event::on(
UserPermissions::class,
UserPermissions::EVENT_REGISTER_PERMISSIONS,
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _registerTwigExtension is not named in camelCase. Open
private function _registerTwigExtension()
{
$request = Craft::$app->getRequest();
if (!$request->isConsoleRequest) {
Craft::$app->getView()->registerTwigExtension(new SeoFieldsExtension());
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _registerCpListeners is not named in camelCase. Open
private function _registerCpListeners()
{
Event::on(
Sites::class,
Sites::EVENT_AFTER_SAVE_SITE,
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _registerCacheOptions is not named in camelCase. Open
private function _registerCacheOptions()
{
Event::on(
ClearCaches::class,
ClearCaches::EVENT_REGISTER_CACHE_OPTIONS,
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _registerField is not named in camelCase. Open
private function _registerField()
{
Event::on(
Fields::class,
Fields::EVENT_REGISTER_FIELD_TYPES,
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _registerSiteListeners is not named in camelCase. Open
private function _registerSiteListeners()
{
Event::on(
ErrorHandler::class,
ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION,
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _registerUrlChangeListeners is not named in camelCase. Open
private function _registerUrlChangeListeners()
{
if (self::getInstance()->getSettings()->createRedirectForUriChange) {
$beforeEvents = [
Elements::EVENT_BEFORE_SAVE_ELEMENT,
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _registerCustomElements is not named in camelCase. Open
private function _registerCustomElements()
{
$elements = [];
if (Craft::$app->getPlugins()->isPluginEnabled('calendar')) {
/** @phpstan-ignore-next-line */
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _registerCpRoutes is not named in camelCase. Open
private function _registerCpRoutes()
{
Event::on(
UrlManager::class,
UrlManager::EVENT_REGISTER_CP_URL_RULES,
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _registerFrontendRoutes is not named in camelCase. Open
private function _registerFrontendRoutes()
{
Event::on(
UrlManager::class,
UrlManager::EVENT_REGISTER_SITE_URL_RULES,
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _registerElementBehaviors is not named in camelCase. Open
private function _registerElementBehaviors(): void
{
Event::on(Entry::class, Entry::EVENT_DEFINE_BEHAVIORS, function(DefineBehaviorsEvent $event) {
$event->behaviors[$this->id] = ElementSeoBehavior::class;
});
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}