lib/Ajde/Object/Magic.php

Summary

Maintainability
A
3 hrs
Test Coverage

Function valuesAsSingleDimensionArray has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    final public function valuesAsSingleDimensionArray()
    {
        $array = [];
        foreach ($this->_data as $k => $item) {
            if (is_string($item)) {
Severity: Minor
Found in lib/Ajde/Object/Magic.php - About 2 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 __call has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    final public function __call($method, $arguments)
    {
        $prefix = strtolower(substr($method, 0, 3));
        $key = substr($method, 3);
        $key = strtolower(substr($key, 0, 1)).substr($key, 1);
Severity: Minor
Found in lib/Ajde/Object/Magic.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

Missing class import via use statement (line '18', column '35').
Open

                        throw new Ajde_Exception("Property '$key' not set in class ".get_class($this)." when calling get('$key')",
Severity: Minor
Found in lib/Ajde/Object/Magic.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 toCamelCase has a boolean flag argument $capitalise_first_char, which is a certain sign of a Single Responsibility Principle violation.
Open

    public static function toCamelCase($str, $capitalise_first_char = false)
Severity: Minor
Found in lib/Ajde/Object/Magic.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 '72', column '23').
Open

            throw new Ajde_Exception("Parameter '$key' not set in class ".get_class($this)." when calling get('$key')",
Severity: Minor
Found in lib/Ajde/Object/Magic.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

Missing class import via use statement (line '33', column '19').
Open

        throw new Ajde_Exception('Call to undefined method '.get_class($this)."::$method()", 90006);
Severity: Minor
Found in lib/Ajde/Object/Magic.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

Avoid using static access to class 'Ajde_Core_Array' in method 'has'.
Open

            $exist = !is_null(Ajde_Core_Array::get($this->_data, $key));
Severity: Minor
Found in lib/Ajde/Object/Magic.php by phpmd

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 'Ajde_Core_Array' in method '_set'.
Open

            Ajde_Core_Array::set($this->_data, $key, $value);
Severity: Minor
Found in lib/Ajde/Object/Magic.php by phpmd

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 valuesAsSingleDimensionArray uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

                    } else {
                        if (is_object($item)) {
                            $array[$k] = serialize($item);
                        }
                    }
Severity: Minor
Found in lib/Ajde/Object/Magic.php by phpmd

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

The method _set uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $this->_data[$key] = $value;
        }
Severity: Minor
Found in lib/Ajde/Object/Magic.php by phpmd

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

The method __call uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

                } else {
                    if (!method_exists($this, '__fallback')) {
                        throw new Ajde_Exception("Property '$key' not set in class ".get_class($this)." when calling get('$key')",
                            90007);
                    }
Severity: Minor
Found in lib/Ajde/Object/Magic.php by phpmd

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 'Ajde_Core_Array' in method 'merge'.
Open

        $this->set($key, Ajde_Core_Array::mergeRecursive($this->get($key), $value));
Severity: Minor
Found in lib/Ajde/Object/Magic.php by phpmd

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 valuesAsSingleDimensionArray uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

                } else {
                    if ($item instanceof self) {
                        $array[$k] = serialize($item->valuesAsSingleDimensionArray());
                    } else {
                        if (is_object($item)) {
Severity: Minor
Found in lib/Ajde/Object/Magic.php by phpmd

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

The method get uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            throw new Ajde_Exception("Parameter '$key' not set in class ".get_class($this)." when calling get('$key')",
                90007);
        }
Severity: Minor
Found in lib/Ajde/Object/Magic.php by phpmd

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 'Ajde_Core_Array' in method '_get'.
Open

            return Ajde_Core_Array::get($this->_data, $key);
Severity: Minor
Found in lib/Ajde/Object/Magic.php by phpmd

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 valuesAsSingleDimensionArray uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                if (is_array($item)) {
                    $array[$k] = serialize($item);
                } else {
                    if ($item instanceof self) {
Severity: Minor
Found in lib/Ajde/Object/Magic.php by phpmd

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

TODO found
Open

     * TODO.
Severity: Minor
Found in lib/Ajde/Object/Magic.php by fixme

TODO found
Open

     * TODO.
Severity: Minor
Found in lib/Ajde/Object/Magic.php by fixme

Avoid excessively long variable names like $capitalise_first_char. Keep variable name length under 20.
Open

    public static function toCamelCase($str, $capitalise_first_char = false)
Severity: Minor
Found in lib/Ajde/Object/Magic.php by phpmd

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

Source https://phpmd.org/rules/naming.html#longvariable

The class Ajde_Object_Magic is not named in CamelCase.
Open

abstract class Ajde_Object_Magic extends Ajde_Object
{
    protected $_data = [];

    final public function __call($method, $arguments)
Severity: Minor
Found in lib/Ajde/Object/Magic.php by phpmd

CamelCaseClassName

Since: 0.2

It is considered best practice to use the CamelCase notation to name classes.

Example

class class_name {
}

Source

The parameter $capitalise_first_char is not named in camelCase.
Open

    public static function toCamelCase($str, $capitalise_first_char = false)
    {
        if ($capitalise_first_char) {
            $str[0] = strtoupper($str[0]);
        }
Severity: Minor
Found in lib/Ajde/Object/Magic.php by phpmd

CamelCaseParameterName

Since: 0.2

It is considered best practice to use the camelCase notation to name parameters.

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

The property $_data is not named in camelCase.
Open

abstract class Ajde_Object_Magic extends Ajde_Object
{
    protected $_data = [];

    final public function __call($method, $arguments)
Severity: Minor
Found in lib/Ajde/Object/Magic.php by phpmd

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

The variable $capitalise_first_char is not named in camelCase.
Open

    public static function toCamelCase($str, $capitalise_first_char = false)
    {
        if ($capitalise_first_char) {
            $str[0] = strtoupper($str[0]);
        }
Severity: Minor
Found in lib/Ajde/Object/Magic.php by phpmd

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The method _set is not named in camelCase.
Open

    protected function _set($key, $value)
    {
        if (substr_count($key, '.')) {
            Ajde_Core_Array::set($this->_data, $key, $value);
        } else {
Severity: Minor
Found in lib/Ajde/Object/Magic.php by phpmd

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 _get is not named in camelCase.
Open

    protected function _get($key)
    {
        if (substr_count($key, '.')) {
            return Ajde_Core_Array::get($this->_data, $key);
        }
Severity: Minor
Found in lib/Ajde/Object/Magic.php by phpmd

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

There are no issues that match your filters.

Category
Status