felixarntz/plugin-lib

View on GitHub
src/service-instantiator.php

Summary

Maintainability
C
1 day
Test Coverage

Function fill_constructor_services has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

        private static function fill_constructor_services( $class_name, $prefix, $args ) {
            $service_definitions = call_user_func( array( $class_name, 'get_service_definitions' ) );

            $services_arg = array();
            foreach ( $args as $arg ) {
Severity: Minor
Found in src/service-instantiator.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 instantiate has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

        public static function instantiate( $class_name, $prefix ) {
            if ( ! class_exists( $class_name ) || ! is_subclass_of( $class_name, 'Leaves_And_Love\Plugin_Lib\Service' ) ) {
                return null;
            }

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

        private static function fill_constructor_args( $class_name, $args ) {
            $args_parsers = call_user_func( array( $class_name, 'get_args_parsers' ) );

            foreach ( $args as $arg ) {
                if ( ! is_array( $arg ) ) {
Severity: Minor
Found in src/service-instantiator.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 fill_constructor_translations has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

        private static function fill_constructor_translations( $class_name, $args ) {
            foreach ( $args as $arg ) {
                if ( is_object( $arg ) && is_a( $arg, 'Leaves_And_Love\Plugin_Lib\Translations\Translations' ) ) {
                    return $arg;
                }
Severity: Minor
Found in src/service-instantiator.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

Avoid too many return statements within this method.
Open

            return null;
Severity: Major
Found in src/service-instantiator.php - About 30 mins to fix

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

                $translations_class_name = $class_name_parts[0] . '\\' . $class_name_parts[1] . '\\Translations\\Translations_' . array_pop( $class_name_parts );
    Severity: Minor
    Found in src/service-instantiator.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

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

                $reflected_constructor = $reflected_class->getConstructor();
    Severity: Minor
    Found in src/service-instantiator.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

    There are no issues that match your filters.

    Category
    Status