hnhdigital-os/laravel-resources-loader

View on GitHub
src/Resource.php

Summary

Maintainability
C
7 hrs
Test Coverage

The class Resource has 18 public methods. Consider refactoring Resource to keep number of public methods under 10.
Open

class Resource
{
    private static $containers = [];

    /**
Severity: Minor
Found in src/Resource.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 Resource has an overall complexity of 52 which is very high. The configured complexity threshold is 50.
Open

class Resource
{
    private static $containers = [];

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

Function controller has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    public function controller($file_extensions, $file)
    {
        // Only look in a single file extension folder.
        if (!is_array($file_extensions)) {
            $file_extensions = [$file_extensions];
Severity: Minor
Found in src/Resource.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 loadFile has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    public function loadFile($file_name, $extension, $full_path = '')
    {
        if (array_has(config('rev-manifest', []), $file_name) || (!empty($full_path) && file_exists($full_path))) {
            if (env('APP_ASSET_INLINE', false)) {
                if (!isset($this->loaded_inline[$full_path])) {
Severity: Minor
Found in src/Resource.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

Method controller has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function controller($file_extensions, $file)
    {
        // Only look in a single file extension folder.
        if (!is_array($file_extensions)) {
            $file_extensions = [$file_extensions];
Severity: Minor
Found in src/Resource.php - About 1 hr to fix

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

        public function elixir($file)
        {
            if (substr($file, 0, 4) === 'http') {
                return $file;
            }
    Severity: Minor
    Found in src/Resource.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 '/assets/'.$file;
    Severity: Major
    Found in src/Resource.php - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

              return '';
      Severity: Major
      Found in src/Resource.php - About 30 mins to fix

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

            private static function loadContainer($class_settings, $config = [])
            {
                if (is_array($class_settings)) {
                    $asset_name = array_shift($class_settings);
                } else {
        Severity: Minor
        Found in src/Resource.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 controller() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
        Open

            public function controller($file_extensions, $file)
            {
                // Only look in a single file extension folder.
                if (!is_array($file_extensions)) {
                    $file_extensions = [$file_extensions];
        Severity: Minor
        Found in src/Resource.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

        Avoid using undefined variables such as '$scripts' which will lead to PHP notices.
        Open

                if (isset(Asset::$scripts[$params])) {
        Severity: Minor
        Found in src/Resource.php by phpmd

        UndefinedVariable

        Since: 2.8.0

        Detects when a variable is used that has not been defined before.

        Example

        class Foo
        {
            private function bar()
            {
                // $message is undefined
                echo $message;
            }
        }

        Source https://phpmd.org/rules/cleancode.html#undefinedvariable

        Avoid using undefined variables such as '$scripts' which will lead to PHP notices.
        Open

                    Asset::$scripts[$params] = array_reverse(Asset::$scripts[$params], true);
        Severity: Minor
        Found in src/Resource.php by phpmd

        UndefinedVariable

        Since: 2.8.0

        Detects when a variable is used that has not been defined before.

        Example

        class Foo
        {
            private function bar()
            {
                // $message is undefined
                echo $message;
            }
        }

        Source https://phpmd.org/rules/cleancode.html#undefinedvariable

        Avoid using undefined variables such as '$scripts' which will lead to PHP notices.
        Open

                    Asset::$scripts[$params] = array_reverse(Asset::$scripts[$params], true);
        Severity: Minor
        Found in src/Resource.php by phpmd

        UndefinedVariable

        Since: 2.8.0

        Detects when a variable is used that has not been defined before.

        Example

        class Foo
        {
            private function bar()
            {
                // $message is undefined
                echo $message;
            }
        }

        Source https://phpmd.org/rules/cleancode.html#undefinedvariable

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

            public function version($name, $version = false)
        Severity: Minor
        Found in src/Resource.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 addAfter has a boolean flag argument $onUnknownExtension, which is a certain sign of a Single Responsibility Principle violation.
        Open

            public function addAfter($file1, $file2, $params = 'footer', $onUnknownExtension = false)
        Severity: Minor
        Found in src/Resource.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 add has a boolean flag argument $onUnknownExtension, which is a certain sign of a Single Responsibility Principle violation.
        Open

            public function add($file, $params = 'footer', $onUnknownExtension = false)
        Severity: Minor
        Found in src/Resource.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 addFirst has a boolean flag argument $onUnknownExtension, which is a certain sign of a Single Responsibility Principle violation.
        Open

            public function addFirst($file, $params = 'footer', $onUnknownExtension = false)
        Severity: Minor
        Found in src/Resource.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 '219', column '13').
        Open

            private static function loadContainer($class_settings, $config = [])
            {
                if (is_array($class_settings)) {
                    $asset_name = array_shift($class_settings);
                } else {
        Severity: Minor
        Found in src/Resource.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

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

                } else {
                    $asset_name = $class_settings;
                    $class_settings = [];
                }
        Severity: Minor
        Found in src/Resource.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 loadFile uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                            } else {
                                $this->addStyle($contents);
                            }
        Severity: Minor
        Found in src/Resource.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 controller uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                        } else {
                            $full_path = public_path().'/assets/'.$file_name;
                        }
        Severity: Minor
        Found in src/Resource.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 loadFile uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                    } else {
                        $this->add($file_name, 'ready');
                    }
        Severity: Minor
        Found in src/Resource.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 short method names like Resource::js(). The configured minimum method name length is 3.
        Open

            public function js(...$arguments)
            {
                return Asset::js(...$arguments);
            }
        Severity: Minor
        Found in src/Resource.php by phpmd

        ShortMethodName

        Since: 0.2

        Detects when very short method names are used.

        Example

        class ShortMethod {
            public function a( $index ) { // Violation
            }
        }

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

        There are no issues that match your filters.

        Category
        Status