File BlameableTrait.php
has 423 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* _ __ __ _____ _____ ___ ____ _____
* | | / // // ___//_ _// || __||_ _|
Method getContentRules
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getContentRules(): array
{
if (!$this->contentAttribute) {
return [];
}
Method getBlameableAttributeRules
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getBlameableAttributeRules()
{
$rules = [];
// 创建者和上次修改者由 BlameableBehavior 负责,因此标记为安全。
if (!is_string($this->createdByAttribute) || empty($this->createdByAttribute)) {
Function getContentRules
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function getContentRules(): array
{
if (!$this->contentAttribute) {
return [];
}
- 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 enabledFields
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function enabledFields(): array
{
$fields = parent::enabledFields();
if (is_string($this->createdByAttribute) && !empty($this->createdByAttribute)) {
$fields[] = $this->createdByAttribute;
- 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 too many return
statements within this method. Open
return false;
Function getBlameableAttributeRules
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getBlameableAttributeRules()
{
$rules = [];
// 创建者和上次修改者由 BlameableBehavior 负责,因此标记为安全。
if (!is_string($this->createdByAttribute) || empty($this->createdByAttribute)) {
- 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 setUpdater
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function setUpdater(mixed $updater): bool|string
{
if (!is_string($this->updatedByAttribute) || empty($this->updatedByAttribute)) {
return false;
}
- 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 enabledFields() has an NPath complexity of 384. The configured NPath complexity threshold is 200. Open
public function enabledFields(): array
{
$fields = parent::enabledFields();
if (is_string($this->createdByAttribute) && !empty($this->createdByAttribute)) {
$fields[] = $this->createdByAttribute;
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method enabledFields() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
public function enabledFields(): array
{
$fields = parent::enabledFields();
if (is_string($this->createdByAttribute) && !empty($this->createdByAttribute)) {
$fields[] = $this->createdByAttribute;
- 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 method on has a boolean flag argument $append, which is a certain sign of a Single Responsibility Principle violation. Open
public abstract function on($name, $handler, $data = null, $append = true);
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method findOneById has a boolean flag argument $throwException, which is a certain sign of a Single Responsibility Principle violation. Open
public static function findOneById(int|string|null $id, bool $throwException = true, mixed $identity = null): ?static
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Avoid using static access to class '\yii\caching\TagDependency' in method 'getBlameableRules'. Open
TagDependency::invalidate($cache, [$this->getEntityRulesCacheTag()]);
- 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 '\rhosocial\base\helpers\Number' in method 'setUpdater'. Open
return $this->{$this->updatedByAttribute} = Number::guid(false, false, $updater);
- 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 '\rhosocial\base\helpers\Number' in method 'setHost'. Open
return $this->{$this->createdByAttribute} = Number::guid(false, false, $host);
- 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\caching\TagDependency' in method 'getBlameableBehaviors'. Open
TagDependency::invalidate($cache, [$this->getEntityBehaviorsCacheTag()]);
- 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 short method names like BlameableTrait::on(). The configured minimum method name length is 3. Open
public abstract function on($name, $handler, $data = null, $append = true);
- Read upRead up
- Exclude checks
ShortMethodName
Since: 0.2
Detects when very short method names are used.
Example
class ShortMethod {
public function a( $index ) { // Violation
}
}
Source https://phpmd.org/rules/naming.html#shortmethodname
Avoid variables with short names like $id. Configured minimum length is 3. Open
public static function findOneById(int|string|null $id, bool $throwException = true, mixed $identity = null): ?static
- 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
Scope keyword "static" must be followed by a single space Open
public static function findOneById(int|string|null $id, bool $throwException = true, mixed $identity = null): ?static
- Exclude checks
The 'getContentCanBeEdited()' method which returns a boolean should be named 'is...()' or 'has...()' Open
public function getContentCanBeEdited()
{
if ($this->contentAttribute === false) {
return false;
}
- Read upRead up
- Exclude checks
BooleanGetMethodName
Since: 0.2
Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.
Example
class Foo {
/**
* @return boolean
*/
public function getFoo() {} // bad
/**
* @return bool
*/
public function isFoo(); // ok
/**
* @return boolean
*/
public function getFoo($bar); // ok, unless checkParameterizedMethods=true
}
Source https://phpmd.org/rules/naming.html#booleangetmethodname
Line exceeds 120 characters; contains 141 characters Open
if (is_string($this->updatedByAttribute) && $this->guidAttribute != $this->updatedByAttribute && !empty($this->updatedByAttribute)) {
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
public static function findAllByIdentityInBatch(string|int|null $pageSize = 'all', $currentPage = 0, $identity = null)
- Exclude checks
Line exceeds 120 characters; contains 136 characters Open
if (!empty($this->idAttribute) && $this->idCreatorCombinatedUnique && $this->idAttributeType !== static::$idTypeAutoIncrement) {
- Exclude checks
Line exceeds 120 characters; contains 121 characters Open
public static function findOneById(int|string|null $id, bool $throwException = true, mixed $identity = null): ?static
- Exclude checks