YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/Dependencies/views/LibraryMoreInfo.php

Summary

Maintainability
B
5 hrs
Test Coverage
F
0%

Function process has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    public function process(App\Request $request)
    {
        $result = false;
        $fileContent = '';
        if ($request->isEmpty('type') || $request->isEmpty('libraryName')) {
Severity: Minor
Found in modules/Settings/Dependencies/views/LibraryMoreInfo.php - About 3 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

Method process has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process(App\Request $request)
    {
        $result = false;
        $fileContent = '';
        if ($request->isEmpty('type') || $request->isEmpty('libraryName')) {
Severity: Minor
Found in modules/Settings/Dependencies/views/LibraryMoreInfo.php - About 1 hr to fix

    Refactor this function to reduce its Cognitive Complexity from 23 to the 15 allowed.
    Open

        public function process(App\Request $request)

    Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

    See

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

            } else {
                if ('public' === $request->getByType('type', 1)) {
                    $dir = ROOT_DIRECTORY . DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR;
                    $libraryName = $request->getByType('libraryName', 'Text');
                    foreach ($this->packageFiles as $file) {

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

                        } else {
                            $result = false;
                        }

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

                } else {
                    $result = false;
                }

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

                    } else {
                        $result = false;
                    }

    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

    Define a constant instead of duplicating this literal "libraryName" 3 times.
    Open

            if ($request->isEmpty('type') || $request->isEmpty('libraryName')) {

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('QUALIFIED_MODULE', $qualifiedModuleName);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('RESULT', $result);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('FILE_CONTENT', $fileContent);

    Avoid excessively long class names like Settings_Dependencies_LibraryMoreInfo_View. Keep class name length under 40.
    Open

    class Settings_Dependencies_LibraryMoreInfo_View extends Settings_Vtiger_BasicModal_View
    {
        /**
         * Public libraries package files.
         *

    LongClassName

    Since: 2.9

    Detects when classes or interfaces are declared with excessively long names.

    Example

    class ATooLongClassNameThatHintsAtADesignProblem {
    
    }
    
    interface ATooLongInterfaceNameThatHintsAtADesignProblem {
    
    }

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

    Each class must be in a namespace of at least one level (a top-level vendor name)
    Open

    class Settings_Dependencies_LibraryMoreInfo_View extends Settings_Vtiger_BasicModal_View

    The class Settings_Dependencies_LibraryMoreInfo_View is not named in CamelCase.
    Open

    class Settings_Dependencies_LibraryMoreInfo_View extends Settings_Vtiger_BasicModal_View
    {
        /**
         * Public libraries package files.
         *

    CamelCaseClassName

    Since: 0.2

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

    Example

    class class_name {
    }

    Source

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public $packageFiles = ['package.json', 'composer.json', 'bower.json'];

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $fileContent = '';

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    foreach ($this->packageFiles as $file) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $viewer = $this->getViewer($request);

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->postProcess($request);

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function process(App\Request $request)

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $result = false;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    } else {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        $result = false;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->preProcess($request);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $viewer->view('LibraryMoreInfo.tpl', $qualifiedModuleName);

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /** {@inheritdoc} */

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $filePath = 'vendor' . DIRECTORY_SEPARATOR . $request->getByType('libraryName', 'Text') . DIRECTORY_SEPARATOR . 'composer.json';

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        if (file_exists($packageFile)) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        } else {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    if (file_exists($filePath)) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        $result = true;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            continue;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            $fileContent = file_get_contents($packageFile);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                } elseif ('vendor' === $request->getByType('type', 1)) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $qualifiedModuleName = $request->getModule(false);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            $result = false;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $viewer->assign('QUALIFIED_MODULE', $qualifiedModuleName);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                if ('public' === $request->getByType('type', 1)) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        $packageFile = $dir . $libraryName . DIRECTORY_SEPARATOR . $file;

    Line exceeds 120 characters; contains 134 characters
    Open

                    $dir = ROOT_DIRECTORY . DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $viewer->assign('RESULT', $result);

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $result = false;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if ($request->isEmpty('type') || $request->isEmpty('libraryName')) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $libraryName = $request->getByType('libraryName', 'Text');

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        $fileContent = file_get_contents($filePath);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @var string[]

    Spaces must be used to indent lines; tabs are not allowed
    Open

                } else {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $result = false;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $viewer->assign('FILE_CONTENT', $fileContent);

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Public libraries package files.

    Spaces must be used to indent lines; tabs are not allowed
    Open

            } else {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $dir = ROOT_DIRECTORY . DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        }

    Line exceeds 120 characters; contains 144 characters
    Open

                    $filePath = 'vendor' . DIRECTORY_SEPARATOR . $request->getByType('libraryName', 'Text') . DIRECTORY_SEPARATOR . 'composer.json';

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        if ($fileContent) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            $result = true;

    Class name "Settings_Dependencies_LibraryMoreInfo_View" is not in camel caps format
    Open

    class Settings_Dependencies_LibraryMoreInfo_View extends Settings_Vtiger_BasicModal_View

    There are no issues that match your filters.

    Category
    Status