yiisoft/yii2

View on GitHub
framework/db/BaseActiveRecord.php

Summary

Maintainability
F
4 days
Test Coverage

Function unlink has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
Open

    public function unlink($name, $model, $delete = false)
    {
        /* @var $relation ActiveQueryInterface|ActiveQuery */
        $relation = $this->getRelation($name);

Severity: Minor
Found in framework/db/BaseActiveRecord.php - About 1 day to fix

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 link has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
Open

    public function link($name, $model, $extraColumns = [])
    {
        /* @var $relation ActiveQueryInterface|ActiveQuery */
        $relation = $this->getRelation($name);

Severity: Minor
Found in framework/db/BaseActiveRecord.php - About 6 hrs to fix

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 unlinkAll has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

    public function unlinkAll($name, $delete = false)
    {
        /* @var $relation ActiveQueryInterface|ActiveQuery */
        $relation = $this->getRelation($name);

Severity: Minor
Found in framework/db/BaseActiveRecord.php - About 5 hrs to fix

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 class BaseActiveRecord has 40 public methods. Consider refactoring BaseActiveRecord to keep number of public methods under 10.
Open

abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
{
    /**
     * @event Event an event that is triggered when the record is initialized via [[init()]].
     */
Severity: Minor
Found in framework/db/BaseActiveRecord.php by phpmd

TooManyPublicMethods

Since: 0.1

A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

Example

Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

The class BaseActiveRecord has 46 non-getter- and setter-methods. Consider refactoring BaseActiveRecord to keep number of methods under 25.
Open

abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
{
    /**
     * @event Event an event that is triggered when the record is initialized via [[init()]].
     */
Severity: Minor
Found in framework/db/BaseActiveRecord.php by phpmd

TooManyMethods

Since: 0.1

A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

The default was changed from 10 to 25 in PHPMD 2.3.

Example

Source https://phpmd.org/rules/codesize.html#toomanymethods

The class BaseActiveRecord has an overall complexity of 253 which is very high. The configured complexity threshold is 50.
Open

abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
{
    /**
     * @event Event an event that is triggered when the record is initialized via [[init()]].
     */
Severity: Minor
Found in framework/db/BaseActiveRecord.php by phpmd

Function getDirtyAttributes has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    public function getDirtyAttributes($names = null)
    {
        if ($names === null) {
            $names = $this->attributes();
        }
Severity: Minor
Found in framework/db/BaseActiveRecord.php - About 1 hr to fix

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 getAttributeHint has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    public function getAttributeHint($attribute)
    {
        $hints = $this->attributeHints();
        if (isset($hints[$attribute])) {
            return $hints[$attribute];
Severity: Minor
Found in framework/db/BaseActiveRecord.php - About 1 hr to fix

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 getAttributeLabel has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    public function getAttributeLabel($attribute)
    {
        $model = $this;
        $modelAttribute = $attribute;
        for (;;) {
Severity: Minor
Found in framework/db/BaseActiveRecord.php - About 1 hr to fix

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 getRelation has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    public function getRelation($name, $throwException = true)
    {
        $getter = 'get' . $name;
        try {
            // the relation could be defined in a behavior
Severity: Minor
Found in framework/db/BaseActiveRecord.php - About 1 hr to fix

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 class BaseActiveRecord has 61 public methods and attributes. Consider reducing the number of public items to less than 45.
Open

abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
{
    /**
     * @event Event an event that is triggered when the record is initialized via [[init()]].
     */
Severity: Minor
Found in framework/db/BaseActiveRecord.php by phpmd

ExcessivePublicCount

Since: 0.1

A large number of public methods and attributes declared in a class can indicate the class may need to be broken up as increased effort will be required to thoroughly test it.

Example

public class Foo {
    public $value;
    public $something;
    public $var;
    // [... more more public attributes ...]

    public function doWork() {}
    public function doMoreWork() {}
    public function doWorkAgain() {}
    // [... more more public methods ...]
}

Source https://phpmd.org/rules/codesize.html#excessivepubliccount

Function setRelationDependencies has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    private function setRelationDependencies($name, $relation, $viaRelationName = null)
    {
        if (empty($relation->via) && $relation->link) {
            foreach ($relation->link as $attribute) {
                $this->_relationsDependencies[$attribute][$name] = $name;
Severity: Minor
Found in framework/db/BaseActiveRecord.php - About 55 mins to fix

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 updateAttributes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public function updateAttributes($attributes)
    {
        $attrs = [];
        foreach ($attributes as $name => $value) {
            if (is_int($name)) {
Severity: Minor
Found in framework/db/BaseActiveRecord.php - About 35 mins to fix

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 updateCounters has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public function updateCounters($counters)
    {
        if (static::updateAllCounters($counters, $this->getOldPrimaryKey(true)) > 0) {
            foreach ($counters as $name => $value) {
                if (!isset($this->_attributes[$name])) {
Severity: Minor
Found in framework/db/BaseActiveRecord.php - About 35 mins to fix

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 updateInternal has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    protected function updateInternal($attributes = null)
    {
        if (!$this->beforeSave(false)) {
            return false;
        }
Severity: Minor
Found in framework/db/BaseActiveRecord.php - About 35 mins to fix

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 $value;
Severity: Major
Found in framework/db/BaseActiveRecord.php - About 30 mins to fix

    Function delete has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        public function delete()
        {
            $result = false;
            if ($this->beforeDelete()) {
                // we do not check the return value of deleteAll() because it's possible
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php - About 25 mins to fix

    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 __set has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        public function __set($name, $value)
        {
            if ($this->hasAttribute($name)) {
                if (
                    !empty($this->_relationsDependencies[$name])
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php - About 25 mins to fix

    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 bindModels has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        private function bindModels($link, $foreignModel, $primaryModel)
        {
            foreach ($link as $fk => $pk) {
                $value = $primaryModel->$pk;
                if ($value === null) {
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php - About 25 mins to fix

    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 setAttribute has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        public function setAttribute($name, $value)
        {
            if ($this->hasAttribute($name)) {
                if (
                    !empty($this->_relationsDependencies[$name])
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php - About 25 mins to fix

    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 link() has an NPath complexity of 755. The configured NPath complexity threshold is 200.
    Open

        public function link($name, $model, $extraColumns = [])
        {
            /* @var $relation ActiveQueryInterface|ActiveQuery */
            $relation = $this->getRelation($name);
    
    
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 class BaseActiveRecord has 1802 lines of code. Current threshold is 1000. Avoid really long classes.
    Open

    abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
    {
        /**
         * @event Event an event that is triggered when the record is initialized via [[init()]].
         */
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    The method unlink() has an NPath complexity of 1020. The configured NPath complexity threshold is 200.
    Open

        public function unlink($name, $model, $delete = false)
        {
            /* @var $relation ActiveQueryInterface|ActiveQuery */
            $relation = $this->getRelation($name);
    
    
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 unlinkAll() has a Cyclomatic Complexity of 18. The configured cyclomatic complexity threshold is 10.
    Open

        public function unlinkAll($name, $delete = false)
        {
            /* @var $relation ActiveQueryInterface|ActiveQuery */
            $relation = $this->getRelation($name);
    
    
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 unlink() has a Cyclomatic Complexity of 23. The configured cyclomatic complexity threshold is 10.
    Open

        public function unlink($name, $model, $delete = false)
        {
            /* @var $relation ActiveQueryInterface|ActiveQuery */
            $relation = $this->getRelation($name);
    
    
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 link() has a Cyclomatic Complexity of 20. The configured cyclomatic complexity threshold is 10.
    Open

        public function link($name, $model, $extraColumns = [])
        {
            /* @var $relation ActiveQueryInterface|ActiveQuery */
            $relation = $this->getRelation($name);
    
    
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 BaseActiveRecord has a coupling between objects value of 27. Consider to reduce the number of dependencies under 13.
    Open

    abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
    {
        /**
         * @event Event an event that is triggered when the record is initialized via [[init()]].
         */
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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

    The method canGetProperty has a boolean flag argument $checkBehaviors, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public function canGetProperty($name, $checkVars = true, $checkBehaviors = true)
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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

    Missing class import via use statement (line '1267', column '27').
    Open

                $method = new \ReflectionMethod($this, $getter);
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    The method loadRelations has a boolean flag argument $asArray, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public function loadRelations($relationNames, $asArray = false)
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 canSetProperty has a boolean flag argument $checkVars, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public function canSetProperty($name, $checkVars = true, $checkBehaviors = true)
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 canSetProperty has a boolean flag argument $checkBehaviors, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public function canSetProperty($name, $checkVars = true, $checkBehaviors = true)
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 isAttributeChanged has a boolean flag argument $identical, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public function isAttributeChanged($name, $identical = true)
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 loadRelationsFor has a boolean flag argument $asArray, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public static function loadRelationsFor(&$models, $relationNames, $asArray = false)
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 canGetProperty has a boolean flag argument $checkVars, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public function canGetProperty($name, $checkVars = true, $checkBehaviors = true)
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 getPrimaryKey has a boolean flag argument $asArray, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public function getPrimaryKey($asArray = false)
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 getOldPrimaryKey has a boolean flag argument $asArray, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public function getOldPrimaryKey($asArray = false)
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 unlink has a boolean flag argument $delete, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public function unlink($name, $model, $delete = false)
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 update has a boolean flag argument $runValidation, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public function update($runValidation = true, $attributeNames = null)
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 save has a boolean flag argument $runValidation, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public function save($runValidation = true, $attributeNames = null)
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 getRelation has a boolean flag argument $throwException, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public function getRelation($name, $throwException = true)
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 unlinkAll has a boolean flag argument $delete, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public function unlinkAll($name, $delete = false)
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 assigning values to variables in if clauses and the like (line '1458', column '30').
    Open

        public function unlink($name, $model, $delete = false)
        {
            /* @var $relation ActiveQueryInterface|ActiveQuery */
            $relation = $this->getRelation($name);
    
    
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 '1547', column '78').
    Open

        public function unlinkAll($name, $delete = false)
        {
            /* @var $relation ActiveQueryInterface|ActiveQuery */
            $relation = $this->getRelation($name);
    
    
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    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 unused parameters such as '$counters'.
    Open

        public static function updateAllCounters($counters, $condition = '')
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

    Avoid unused parameters such as '$condition'.
    Open

        public static function deleteAll($condition = null)
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

    Avoid unused parameters such as '$condition'.
    Open

        public static function updateAllCounters($counters, $condition = '')
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

    Avoid unused parameters such as '$condition'.
    Open

        public static function updateAll($attributes, $condition = '')
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

    Avoid unused parameters such as '$attributes'.
    Open

        public static function updateAll($attributes, $condition = '')
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

    Avoid unused parameters such as '$row'.
    Open

        public static function instantiate($row)
    Severity: Minor
    Found in framework/db/BaseActiveRecord.php by phpmd

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

                if (is_array($relation->via)) {
                    /* @var $viaClass ActiveRecordInterface */
                    if ($delete) {
                        $viaClass::deleteAll($condition);
                    } else {
    Severity: Major
    Found in framework/db/BaseActiveRecord.php and 1 other location - About 1 hr to fix
    framework/db/BaseActiveRecord.php on lines 1426..1442

    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 101.

    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

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

                if (is_array($relation->via)) {
                    /* @var $viaClass ActiveRecordInterface */
                    if ($delete) {
                        $viaClass::deleteAll($columns);
                    } else {
    Severity: Major
    Found in framework/db/BaseActiveRecord.php and 1 other location - About 1 hr to fix
    framework/db/BaseActiveRecord.php on lines 1527..1543

    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 101.

    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

    Further Reading

    There are no issues that match your filters.

    Category
    Status