Fleshgrinder/php-assertion

View on GitHub

Showing 22 of 22 total issues

Variable has 47 functions (exceeds 20 allowed). Consider refactoring.
Open

abstract class Variable {

    const BC_MATH_DEFAULT_SCALE = 1000;

    /**
Severity: Minor
Found in src/Variable.php - About 6 hrs to fix

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

abstract class Variable {

    const BC_MATH_DEFAULT_SCALE = 1000;

    /**
Severity: Minor
Found in src/Variable.php by phpmd

The class Variable has 47 public methods and attributes. Consider reducing the number of public items to less than 45.
Open

abstract class Variable {

    const BC_MATH_DEFAULT_SCALE = 1000;

    /**
Severity: Minor
Found in src/Variable.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

Avoid variables with short names like $c. Configured minimum length is 3.
Open

            $c = count($var);
Severity: Minor
Found in src/Variable.php by phpmd

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

Function isStrictArray has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    final public static function isStrictArray($var) {
        if ($var instanceof \SplFixedArray) {
            return true;
        }

Severity: Minor
Found in src/Variable.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 isRealNumber has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    final public static function isRealNumber($var, $scale = self::BC_MATH_DEFAULT_SCALE) {
        assert(Variable::isScalarNaturalNumber($scale), 'BC Math scale must be a natural number (ℕ₀) of type int');

        if (is_numeric($var)) {
            if (filter_var($var, FILTER_VALIDATE_FLOAT) !== false) {
Severity: Minor
Found in src/Variable.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

Missing class import via use statement (line '648', column '57').
Open

        return (new \ReflectionClass($var))->isSubclassOf(new \ReflectionClass($class));
Severity: Minor
Found in src/Variable.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

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

    final public static function hasInstancesOfOnly($var, $class, $allow_string = true) {
        if (is_object($class)) {
            $class = get_class($class);
        }

Severity: Minor
Found in src/Variable.php and 1 other location - About 30 mins to fix
src/Variable.php on lines 421..429

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

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

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

    final public static function isInstanceOf($var, $class, $allow_string = true) {
Severity: Minor
Found in src/Variable.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 isSubclassOf has a boolean flag argument $allow_string, which is a certain sign of a Single Responsibility Principle violation.
Open

    final public static function isSubclassOf($var, $class, $allow_string = true) {
Severity: Minor
Found in src/Variable.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 hasSubclassesOfOnly has a boolean flag argument $allow_string, which is a certain sign of a Single Responsibility Principle violation.
Open

    final public static function hasSubclassesOfOnly($var, $class, $allow_string = true) {
Severity: Minor
Found in src/Variable.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 contains has a boolean flag argument $case_sensitive, which is a certain sign of a Single Responsibility Principle violation.
Open

    final public static function contains($var, $needle, $case_sensitive = false) {
Severity: Minor
Found in src/Variable.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

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

    final public static function hasSubclassesOfOnly($var, $class, $allow_string = true) {
        if (is_object($class)) {
            $class = get_class($class);
        }

Severity: Minor
Found in src/Variable.php and 1 other location - About 30 mins to fix
src/Variable.php on lines 161..169

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

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

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

    final public static function allContain($var, $needle, $case_sensitive = false) {
Severity: Minor
Found in src/Variable.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 hasInstancesOfOnly has a boolean flag argument $allow_string, which is a certain sign of a Single Responsibility Principle violation.
Open

    final public static function hasInstancesOfOnly($var, $class, $allow_string = true) {
Severity: Minor
Found in src/Variable.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 '648', column '15').
Open

        return (new \ReflectionClass($var))->isSubclassOf(new \ReflectionClass($class));
Severity: Minor
Found in src/Variable.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 applyCallback has a boolean flag argument $pass_delta, which is a certain sign of a Single Responsibility Principle violation.
Open

    final public static function applyCallback($var, callable $callback, $pass_delta = true) {
Severity: Minor
Found in src/Variable.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

Remove error control operator '@' on line 659.
Open

    final public static function isTraversable($var) {
        @trigger_error('Use is_iterable() instead.', E_USER_DEPRECATED);

        return is_iterable($var);
    }
Severity: Minor
Found in src/Variable.php by phpmd

ErrorControlOperator

Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

Example

function foo($filePath) {
    $file = @fopen($filPath); // hides exceptions
    $key = @$array[$notExistingKey]; // assigns null to $key
}

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

Remove error control operator '@' on line 440.
Open

    final public static function hasTraversablesOnly($var) {
        @trigger_error('Use Variable::hasIterablesOnly() instead.', E_USER_DEPRECATED);

        return static::applyCallback($var, [__CLASS__, 'isTraversable']);
    }
Severity: Minor
Found in src/Variable.php by phpmd

ErrorControlOperator

Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

Example

function foo($filePath) {
    $file = @fopen($filPath); // hides exceptions
    $key = @$array[$notExistingKey]; // assigns null to $key
}

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

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

    final public static function applyCallback($var, callable $callback, $pass_delta = true) {
        assert(is_bool($pass_delta), 'Third argument must be of type bool.');

        if (is_iterable($var)) {
            /** @noinspection ForeachSourceInspection */
Severity: Minor
Found in src/Variable.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

Severity
Category
Status
Source
Language