Function addOrCreateBlame
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function addOrCreateBlame(&$blame = null, $user = null)
{
if (!is_string($this->multiBlamesClass)) {
throw new InvalidConfigException('$multiBlamesClass must be specified if you want to use multiple blameable features.');
}
- 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 setBlameGuids has a boolean flag argument $checkValid, which is a certain sign of a Single Responsibility Principle violation. Open
public function setBlameGuids($guids = [], $checkValid = 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 getBlameGuids has a boolean flag argument $checkValid, which is a certain sign of a Single Responsibility Principle violation. Open
public function getBlameGuids($checkValid = false)
- 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 '\vistart\helpers\Number' in method 'unsetInvalidBlames'. Open
$checkedGuids = Number::unsetInvalidUuids($guids);
- 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 assigning values to variables in if clauses and the like (line '194', column '14'). Open
public function addOrCreateBlame(&$blame = null, $user = null)
{
if (!is_string($this->multiBlamesClass)) {
throw new InvalidConfigException('$multiBlamesClass must be specified if you want to use multiple blameable features.');
}
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid assigning values to variables in if clauses and the like (line '218', column '14'). Open
public function removeBlame($blame)
{
if (!is_string($this->multiBlamesAttribute)) {
return false;
}
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Line exceeds 120 characters; contains 132 characters Open
throw new InvalidConfigException('$multiBlamesClass must be specified if you want to use multiple blameable features.');
- Exclude checks
Line exceeds 120 characters; contains 125 characters Open
if (empty($self->multiBlamesClass) || !is_string($self->multiBlamesClass) || $self->multiBlamesAttribute === false) {
- Exclude checks
Whitespace found at end of line Open
* @param {$this->multiBlamesClass}|string|array $blame
- Exclude checks