YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/PublicHoliday/actions/Holiday.php

Summary

Maintainability
B
6 hrs
Test Coverage
F
0%

Method duplicate has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function duplicate(App\Request $request)
    {
        $response = new Vtiger_Response();
        $moduleName = $request->getModule(false);
        $result = true;
Severity: Minor
Found in modules/Settings/PublicHoliday/actions/Holiday.php - About 1 hr to fix

    Function duplicate has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        public function duplicate(App\Request $request)
        {
            $response = new Vtiger_Response();
            $moduleName = $request->getModule(false);
            $result = true;
    Severity: Minor
    Found in modules/Settings/PublicHoliday/actions/Holiday.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 save has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function save(App\Request $request)
        {
            $response = new Vtiger_Response();
            $moduleName = $request->getModule(false);
            $result = true;
    Severity: Minor
    Found in modules/Settings/PublicHoliday/actions/Holiday.php - About 1 hr to fix

      Method massDelete has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function massDelete(App\Request $request)
          {
              $response = new Vtiger_Response();
              $moduleName = $request->getModule(false);
              $result = true;
      Severity: Minor
      Found in modules/Settings/PublicHoliday/actions/Holiday.php - About 1 hr to fix

        Function save has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            public function save(App\Request $request)
            {
                $response = new Vtiger_Response();
                $moduleName = $request->getModule(false);
                $result = true;
        Severity: Minor
        Found in modules/Settings/PublicHoliday/actions/Holiday.php - About 45 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 save() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10.
        Open

            public function save(App\Request $request)
            {
                $response = new Vtiger_Response();
                $moduleName = $request->getModule(false);
                $result = true;

        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

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

            public function save(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

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

                $response = new Vtiger_Response();

        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 '72', column '19').
        Open

                $response = new Vtiger_Response();

        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 '123', column '19').
        Open

                $response = new Vtiger_Response();

        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 '156', column '19').
        Open

                $response = new Vtiger_Response();

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

                    } else {
                        $result = false;
                        $message = \App\Language::translate('LBL_FILL_FORM_ERROR', $moduleName);
                    }

        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 '\App\Language' in method 'save'.
        Open

                        $message = \App\Language::translate('LBL_FILL_FORM_ERROR', $moduleName);

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

                        } else {
                            $message = $holidayId ? \App\Language::translate('LBL_EDIT_DATE_NOTHINGTOUPDATE', $moduleName) : \App\Language::translate('LBL_NEW_DATE_ERROR', $moduleName);
                        }

        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 '\App\Language' in method 'massDelete'.
        Open

                                            \App\Language::translate('LBL_HOLIDAY_DELETE_SOMENOTDELETED', $moduleName);

        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 '\App\Language' in method 'duplicate'.
        Open

                        'message' => $message ?: \App\Language::translate('LBL_DUPLICATE_SUCCESS', $moduleName),

        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 '\App\Fields\Date' in method 'duplicate'.
        Open

                                $notDuplicated[] = \App\Fields\Date::formatToDisplay($sourceDate);

        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 '\App\Language' in method 'delete'.
        Open

                                            \App\Language::translate('LBL_HOLIDAY_DELETE_OK', $moduleName);

        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 '\App\Language' in method 'delete'.
        Open

                        $message = \App\Language::translate('LBL_HOLIDAY_DELETE_NOTHINGTODELETE', $moduleName);

        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 'Settings_PublicHoliday_Record_Model' in method 'save'.
        Open

                        $recordModel = $holidayId ? Settings_PublicHoliday_Record_Model::getInstanceById($holidayId) : Settings_PublicHoliday_Record_Model::getCleanInstance();

        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 'Settings_PublicHoliday_Record_Model' in method 'delete'.
        Open

                        $recordModel = Settings_PublicHoliday_Record_Model::getInstanceById((int) $id);

        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 'Settings_PublicHoliday_Record_Model' in method 'save'.
        Open

                        $recordModel = $holidayId ? Settings_PublicHoliday_Record_Model::getInstanceById($holidayId) : Settings_PublicHoliday_Record_Model::getCleanInstance();

        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 'Settings_PublicHoliday_Record_Model' in method 'duplicate'.
        Open

                            $sourceRecordModel = Settings_PublicHoliday_Record_Model::getInstanceById((int) $sourceId);

        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 '\App\Language' in method 'save'.
        Open

                            $message = $holidayId ? \App\Language::translate('LBL_EDIT_DATE_OK', $moduleName) : \App\Language::translate('LBL_NEW_DATE_OK', $moduleName);

        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 '\App\Language' in method 'save'.
        Open

                        'message' => $message ?: \App\Language::translate('LBL_EDIT_DATE_OK', $moduleName),

        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 'App\Fields\Date' in method 'save'.
        Open

                        $date = App\Fields\Date::formatToDB($date);

        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 '\App\Language' in method 'delete'.
        Open

                                            \App\Language::translate('LBL_HOLIDAY_DELETE_ALREADYDELETED', $moduleName) :

        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 '\App\Language' in method 'massDelete'.
        Open

                        $message = \App\Language::translate('LBL_HOLIDAY_DELETE_NOTHINGTODELETE', $moduleName);

        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 '\App\Language' in method 'save'.
        Open

                            $message = $holidayId ? \App\Language::translate('LBL_EDIT_DATE_OK', $moduleName) : \App\Language::translate('LBL_NEW_DATE_OK', $moduleName);

        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 '\App\Language' in method 'save'.
        Open

                            $message = $holidayId ? \App\Language::translate('LBL_EDIT_DATE_NOTHINGTOUPDATE', $moduleName) : \App\Language::translate('LBL_NEW_DATE_ERROR', $moduleName);

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

                    } else {
                        $result = false;
                        $message = \App\Language::translate('LBL_HOLIDAY_DELETE_NOTHINGTODELETE', $moduleName);
                    }

        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 'Settings_PublicHoliday_Record_Model' in method 'massDelete'.
        Open

                            $recordModel = Settings_PublicHoliday_Record_Model::getInstanceById((int) $id);

        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 '\App\Language' in method 'massDelete'.
        Open

                                            \App\Language::translate('LBL_HOLIDAY_DELETE_OK', $moduleName) :

        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 '\App\Language' in method 'save'.
        Open

                            $message = $holidayId ? \App\Language::translate('LBL_EDIT_DATE_NOTHINGTOUPDATE', $moduleName) : \App\Language::translate('LBL_NEW_DATE_ERROR', $moduleName);

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

                    } else {
                        $result = false;
                        $message = \App\Language::translate('LBL_HOLIDAY_DELETE_NOTHINGTODELETE', $moduleName);
                    }

        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 '\App\Language' in method 'save'.
        Open

                            $message = $request->getByType('holidayDate', 'Text') . '<br />' . \App\Language::translate('LBL_DATE_EXISTS', $moduleName);

        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 '\App\Language' in method 'duplicate'.
        Open

                            $message = \App\Language::translate('LBL_DUPLICATE_ERROR', $moduleName) . ' ' . $targetYear . '<br />' . implode(', ', $notDuplicated);

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

                    } else {
                        $result = false;
                        $message = \App\Language::translate('LBL_FILL_FORM_ERROR', $moduleName);
                    }

        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 '\App\Language' in method 'duplicate'.
        Open

                        $message = \App\Language::translate('LBL_FILL_FORM_ERROR', $moduleName);

        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 'Settings_PublicHoliday_Record_Model' in method 'duplicate'.
        Open

                            $targetRecordModel = Settings_PublicHoliday_Record_Model::getCleanInstance();

        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

        Define a constant instead of duplicating this literal "success" 4 times.
        Open

                        'success' => $result,

        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.

        Define a constant instead of duplicating this literal "message" 4 times.
        Open

                        'message' => $message ?: \App\Language::translate('LBL_EDIT_DATE_OK', $moduleName),

        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 with 0 arg(s) to \Settings_PublicHoliday_Holiday_Action::save() which requires 1 arg(s) defined at /code/modules/Settings/PublicHoliday/actions/Holiday.php:26
        Open

                            if ($targetRecordModel->isDuplicate() || !$targetRecordModel->save()) {

        Method \Settings_PublicHoliday_Holiday_Action::delete is declared to return \none but has no return value
        Open

            public function delete(App\Request $request)

        Return type of delete() is undeclared type \none
        Open

            public function delete(App\Request $request)

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

        class Settings_PublicHoliday_Holiday_Action extends Settings_Vtiger_Index_Action

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

                    $id = !$request->isEmpty('id') ? $request->getInteger('id') : 0;

        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

        The class Settings_PublicHoliday_Holiday_Action is not named in CamelCase.
        Open

        class Settings_PublicHoliday_Holiday_Action extends Settings_Vtiger_Index_Action
        {
            /** {@inheritdoc} */
            public function __construct()
            {

        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

                $this->exposeMethod('save');

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

                            $message = $holidayId ? \App\Language::translate('LBL_EDIT_DATE_NOTHINGTOUPDATE', $moduleName) : \App\Language::translate('LBL_NEW_DATE_ERROR', $moduleName);

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

                    $response->setError($e->getCode(), $e->getMessage());

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

             * @param \App\Request $request

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

                $response = new Vtiger_Response();

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

                            $recordModel = Settings_PublicHoliday_Record_Model::getInstanceById((int) $id);

        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->exposeMethod('delete');

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

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

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

                        $recordModel->set('holidaydate', $date)

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

             */

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

                $response = new Vtiger_Response();

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

                                'holidaytype' => $sourceRecordModel->getType(),

        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

                try {

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

             * Mass delete of holidays.

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

                        foreach ($records as $id) {

        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

                        'message' => $message ?: \App\Language::translate('LBL_EDIT_DATE_OK', $moduleName),

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

                    $response->setError($e->getCode(), $e->getMessage());

        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

                $response = new Vtiger_Response();

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

                    $response->setResult([

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

                } catch (Exception $e) {

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

                $this->exposeMethod('massDelete');

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

                try {

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

                            $message = $holidayId ? \App\Language::translate('LBL_EDIT_DATE_OK', $moduleName) : \App\Language::translate('LBL_NEW_DATE_OK', $moduleName);

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

                    $response->setResult([

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

                            $sourceDate = $sourceRecordModel->getDate();

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

                } catch (Throwable $e) {

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

             * @param \App\Request $request

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

                $message = '';

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

                    if ($id) {

        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 = true;

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

                    $response->setError($e->getCode(), $e->getMessage());

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

                parent::__construct();

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

             * @param \App\Request $request

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

            public function save(App\Request $request)

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

                            $message = $request->getByType('holidayDate', 'Text') . '<br />' . \App\Language::translate('LBL_DATE_EXISTS', $moduleName);

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

                    if ($sourceIds && $targetYear) {

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

                        foreach ($sourceIds as $sourceId) {

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

             */

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

                        $recordModel = Settings_PublicHoliday_Record_Model::getInstanceById((int) $id);

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

             */

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

                    $response->setResult([

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

            public function __construct()

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

            /**

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

                $response = new Vtiger_Response();

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

                        if ($recordModel->isDuplicate()) {

        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

                        }

        Line exceeds 120 characters; contains 155 characters
        Open

                            $message = \App\Language::translate('LBL_DUPLICATE_ERROR', $moduleName) . ' ' . $targetYear . '<br />' . implode(', ', $notDuplicated);

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

                        $message = \App\Language::translate('LBL_FILL_FORM_ERROR', $moduleName);

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

                $response->emit();

        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

                    } 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

                    $response->setResult([

        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

            public function delete(App\Request $request)

        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

                        'success' => $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

             *

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

                            ->set('holidayname', $name)

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

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

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

                try {

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

                                'holidaydate' => $targetDate,

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

                        }

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

                        if ($notDuplicated) {

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

             *

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

             * @return none

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

             *

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

                    if (\count($records)) {

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

                        $message = \App\Language::translate('LBL_HOLIDAY_DELETE_NOTHINGTODELETE', $moduleName);

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

                $message = '';

        Line exceeds 120 characters; contains 167 characters
        Open

                        $recordModel = $holidayId ? Settings_PublicHoliday_Record_Model::getInstanceById($holidayId) : Settings_PublicHoliday_Record_Model::getCleanInstance();

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

             *

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

                    $sourceIds = $request->getArray('holidayIds', \App\Purifier::INTEGER);

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

                            $targetRecordModel->setData([

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

                                $notDuplicated[] = \App\Fields\Date::formatToDisplay($sourceDate);

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

            }

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

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

        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->exposeMethod('duplicate');

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

             * Saves holiday.

        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 ($recordModel->save()) {

        Line exceeds 120 characters; contains 177 characters
        Open

                            $message = $holidayId ? \App\Language::translate('LBL_EDIT_DATE_NOTHINGTOUPDATE', $moduleName) : \App\Language::translate('LBL_NEW_DATE_ERROR', $moduleName);

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

                $message = '';

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

                        $notDuplicated = [];

        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

             * Deletes holiday.

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

                        'message' => $message,

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

                    $response->setError($e->getCode(), $e->getMessage());

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

            public function massDelete(App\Request $request)

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

                try {

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

                        'message' => $message,

        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 = true;

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

                    $date = $request->getByType('holidayDate', 'DateInUserFormat');

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

                    $type = $request->getByType('holidayType', \App\Purifier::TEXT);

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

                            $result = false;

        Line exceeds 120 characters; contains 161 characters
        Open

                            $message = $holidayId ? \App\Language::translate('LBL_EDIT_DATE_OK', $moduleName) : \App\Language::translate('LBL_NEW_DATE_OK', $moduleName);

        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 duplicate(App\Request $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

                    $targetYear = $request->getByType('targetYear', \App\Purifier::INTEGER);

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

                            $targetRecordModel = Settings_PublicHoliday_Record_Model::getCleanInstance();

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

                                            \App\Language::translate('LBL_HOLIDAY_DELETE_ALREADYDELETED', $moduleName) :

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

                                            \App\Language::translate('LBL_HOLIDAY_DELETE_OK', $moduleName);

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

                    ]);

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

                        'success' => $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

            /** {@inheritdoc} */

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

            {

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

                    $name = $request->getByType('holidayName', \App\Purifier::TEXT);

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

                    if ($date && $type && $name) {

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

                        $message = \App\Language::translate('LBL_FILL_FORM_ERROR', $moduleName);

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

                } catch (Throwable $e) {

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

                                'holidayname' => $sourceRecordModel->getName(),

        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

                    }

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

             *

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

                    $id = !$request->isEmpty('id') ? $request->getInteger('id') : 0;

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

                        $deleteResult = $recordModel->delete();

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

            {

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

                                            \App\Language::translate('LBL_HOLIDAY_DELETE_SOMENOTDELETED', $moduleName);

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

            }

        Line exceeds 120 characters; contains 144 characters
        Open

                            $message = $request->getByType('holidayDate', 'Text') . '<br />' . \App\Language::translate('LBL_DATE_EXISTS', $moduleName);

        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

                        'success' => $result,

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

                            $targetDate = date($targetYear . '-m-d', strtotime($sourceDate));

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

                            $message = \App\Language::translate('LBL_DUPLICATE_ERROR', $moduleName) . ' ' . $targetYear . '<br />' . implode(', ', $notDuplicated);

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

                        }

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

                        'message' => $message ?: \App\Language::translate('LBL_DUPLICATE_SUCCESS', $moduleName),

        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

                } catch (Throwable $e) {

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

            }

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

                            $deletedRecords += $recordModel->delete();

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

                        $message = $deletedRecords === \count($records) ?

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

                        $date = App\Fields\Date::formatToDB($date);

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

                $response->emit();

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

             * @param \App\Request $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

                $response->emit();

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

                        $message = 0 === $deleteResult ?

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

                    }

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

                $message = '';

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

                    $records = !$request->isEmpty('records') ? $request->getArray('records') : [];

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

                        $recordModel = $holidayId ? Settings_PublicHoliday_Record_Model::getInstanceById($holidayId) : Settings_PublicHoliday_Record_Model::getCleanInstance();

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

                            ->set('holidaytype', $type);

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

                            $sourceRecordModel = Settings_PublicHoliday_Record_Model::getInstanceById((int) $sourceId);

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

                        'success' => $result,

        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

                }

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

                $response->emit();

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

                    $holidayId = $request->isEmpty('holidayId', true) ? 0 : $request->getInteger('holidayId');

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

             * Duplicates holidays for year.

        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

                            if ($targetRecordModel->isDuplicate() || !$targetRecordModel->save()) {

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

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

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

                        $message = \App\Language::translate('LBL_HOLIDAY_DELETE_NOTHINGTODELETE', $moduleName);

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

                        $deletedRecords = 0;

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

                                            \App\Language::translate('LBL_HOLIDAY_DELETE_OK', $moduleName) :

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

        class Settings_PublicHoliday_Holiday_Action extends Settings_Vtiger_Index_Action

        There are no issues that match your filters.

        Category
        Status