YetiForceCompany/YetiForceCRM

View on GitHub
app/Utils/ServiceContracts.php

Summary

Maintainability
F
3 days
Test Coverage
F
15%

Function getExpectedTimes has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

    private static function getExpectedTimes(int $id, \Vtiger_Record_Model $recordModel, array $type): array
    {
        $return = [];
        $date = new \DateTime();
        if ($id && ($rules = self::getRulesForServiceContracts($id, $recordModel)) || ($rules = self::getSlaPolicyRulesForModule($recordModel))) {
Severity: Minor
Found in app/Utils/ServiceContracts.php - About 5 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

File ServiceContracts.php has 408 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Service contracts utils file.
 *
 * @package App
Severity: Minor
Found in app/Utils/ServiceContracts.php - About 5 hrs to fix

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

    class ServiceContracts
    {
        /**
         * Fields map.
         *
    Severity: Minor
    Found in app/Utils/ServiceContracts.php by phpmd

    Function getRulesForServiceContracts has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function getRulesForServiceContracts(int $serviceContractId, \Vtiger_Record_Model $recordModel): array
        {
            $times = $businessHours = [];
            foreach (self::getSlaPolicyForServiceContracts($serviceContractId, $recordModel->getModule()->getId()) as $row) {
                switch ($row['policy_type']) {
    Severity: Minor
    Found in app/Utils/ServiceContracts.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

    ServiceContracts has 22 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ServiceContracts
    {
        /**
         * Fields map.
         *
    Severity: Minor
    Found in app/Utils/ServiceContracts.php - About 2 hrs to fix

      Method getExpectedTimes has 51 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private static function getExpectedTimes(int $id, \Vtiger_Record_Model $recordModel, array $type): array
          {
              $return = [];
              $date = new \DateTime();
              if ($id && ($rules = self::getRulesForServiceContracts($id, $recordModel)) || ($rules = self::getSlaPolicyRulesForModule($recordModel))) {
      Severity: Major
      Found in app/Utils/ServiceContracts.php - About 2 hrs to fix

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

            public static function getRulesForServiceContracts(int $serviceContractId, \Vtiger_Record_Model $recordModel): array
            {
                $times = $businessHours = [];
                foreach (self::getSlaPolicyForServiceContracts($serviceContractId, $recordModel->getModule()->getId()) as $row) {
                    switch ($row['policy_type']) {
        Severity: Minor
        Found in app/Utils/ServiceContracts.php - About 1 hr to fix

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

              public static function getSlaPolicyRulesForModule(\Vtiger_Record_Model $recordModel): array
              {
                  $times = $businessHours = [];
                  foreach (self::getSlaPolicyForModule($recordModel->getModule()->getId()) as $row) {
                      $conditions = \App\Json::decode($row['conditions']);
          Severity: Minor
          Found in app/Utils/ServiceContracts.php - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

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

              private static function parseBusinessHoursToDays(array $rows): array
              {
                  $days = $holidays = [];
                  foreach ($rows as $row) {
                      foreach (explode(',', $row['working_days']) as $day) {
          Severity: Minor
          Found in app/Utils/ServiceContracts.php - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function getNextBusinessDay has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              private static function getNextBusinessDay(\DateTime &$date, array $days): ?array
              {
                  $tempDay = (int) $date->format('N') + 1;
                  $counter = 1;
                  $result = null;
          Severity: Minor
          Found in app/Utils/ServiceContracts.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 businessTime has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function businessTime(string $start, string $end, string $startHour, string $endHour, array $days, bool $holidays): int
              {
                  $start = new \DateTime($start);
                  $end = new \DateTime($end);
                  $holidaysDates = $dates = [];
          Severity: Minor
          Found in app/Utils/ServiceContracts.php - About 1 hr to fix

            Method parseBusinessHoursToDays has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private static function parseBusinessHoursToDays(array $rows): array
                {
                    $days = $holidays = [];
                    foreach ($rows as $row) {
                        foreach (explode(',', $row['working_days']) as $day) {
            Severity: Minor
            Found in app/Utils/ServiceContracts.php - About 1 hr to fix

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

                  public static function getSlaPolicyForServiceContracts(int $serviceContractId, ?int $sourceModuleId = null): array
                  {
                      if (\App\Cache::has('UtilsServiceContracts::getSlaPolicyForServiceContracts', $serviceContractId)) {
                          $rows = \App\Cache::get('UtilsServiceContracts::getSlaPolicyForServiceContracts', $serviceContractId);
                      } else {
              Severity: Minor
              Found in app/Utils/ServiceContracts.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

              Method businessTime has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  public static function businessTime(string $start, string $end, string $startHour, string $endHour, array $days, bool $holidays): int
              Severity: Minor
              Found in app/Utils/ServiceContracts.php - About 45 mins to fix

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

                    public static function businessTime(string $start, string $end, string $startHour, string $endHour, array $days, bool $holidays): int
                    {
                        $start = new \DateTime($start);
                        $end = new \DateTime($end);
                        $holidaysDates = $dates = [];
                Severity: Minor
                Found in app/Utils/ServiceContracts.php - About 35 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

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

                    public static function getDiffFromServiceContracts(string $start, string $end, int $serviceContractId, \Vtiger_Record_Model $recordModel): int
                    {
                        if ($rules = self::getRulesForServiceContracts($serviceContractId, $recordModel)) {
                            if (isset($rules['id'])) {
                                return round(\App\Fields\DateTime::getDiff($start, $end, 'minutes'));
                Severity: Minor
                Found in app/Utils/ServiceContracts.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 getRulesForServiceContracts() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10.
                Open

                    public static function getRulesForServiceContracts(int $serviceContractId, \Vtiger_Record_Model $recordModel): array
                    {
                        $times = $businessHours = [];
                        foreach (self::getSlaPolicyForServiceContracts($serviceContractId, $recordModel->getModule()->getId()) as $row) {
                            switch ($row['policy_type']) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.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

                The method getSlaPolicyRulesForModule() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
                Open

                    public static function getSlaPolicyRulesForModule(\Vtiger_Record_Model $recordModel): array
                    {
                        $times = $businessHours = [];
                        foreach (self::getSlaPolicyForModule($recordModel->getModule()->getId()) as $row) {
                            $conditions = \App\Json::decode($row['conditions']);
                Severity: Minor
                Found in app/Utils/ServiceContracts.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

                The method businessTime() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
                Open

                    public static function businessTime(string $start, string $end, string $startHour, string $endHour, array $days, bool $holidays): int
                    {
                        $start = new \DateTime($start);
                        $end = new \DateTime($end);
                        $holidaysDates = $dates = [];
                Severity: Minor
                Found in app/Utils/ServiceContracts.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

                The method getExpectedTimes() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10.
                Open

                    private static function getExpectedTimes(int $id, \Vtiger_Record_Model $recordModel, array $type): array
                    {
                        $return = [];
                        $date = new \DateTime();
                        if ($id && ($rules = self::getRulesForServiceContracts($id, $recordModel)) || ($rules = self::getSlaPolicyRulesForModule($recordModel))) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.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

                The method parseBusinessHoursToDays() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
                Open

                    private static function parseBusinessHoursToDays(array $rows): array
                    {
                        $days = $holidays = [];
                        foreach ($rows as $row) {
                            foreach (explode(',', $row['working_days']) as $day) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.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

                Reduce the number of returns of this function 4, down to the maximum allowed 3.
                Open

                    public static function getRulesForServiceContracts(int $serviceContractId, \Vtiger_Record_Model $recordModel): array
                Severity: Major
                Found in app/Utils/ServiceContracts.php by sonar-php

                Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.

                Noncompliant Code Example

                With the default threshold of 3:

                function myFunction(){ // Noncompliant as there are 4 return statements
                  if (condition1) {
                    return true;
                  } else {
                    if (condition2) {
                      return false;
                    } else {
                      return true;
                    }
                  }
                  return false;
                }
                

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

                    private static function getExpectedTimes(int $id, \Vtiger_Record_Model $recordModel, array $type): array
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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

                Reduce the number of returns of this function 4, down to the maximum allowed 3.
                Open

                    private static function getExpectedTimes(int $id, \Vtiger_Record_Model $recordModel, array $type): array
                Severity: Major
                Found in app/Utils/ServiceContracts.php by sonar-php

                Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.

                Noncompliant Code Example

                With the default threshold of 3:

                function myFunction(){ // Noncompliant as there are 4 return statements
                  if (condition1) {
                    return true;
                  } else {
                    if (condition2) {
                      return false;
                    } else {
                      return true;
                    }
                  }
                  return false;
                }
                

                Class "ServiceContracts" has 22 methods, which is greater than 20 authorized. Split it into smaller classes.
                Open

                class ServiceContracts
                Severity: Major
                Found in app/Utils/ServiceContracts.php by sonar-php

                A class that grows too much tends to aggregate too many responsibilities and inevitably becomes harder to understand and therefore to maintain. Above a specific threshold, it is strongly advised to refactor the class into smaller ones which focus on well defined topics.

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

                    public static function getRulesForServiceContracts(int $serviceContractId, \Vtiger_Record_Model $recordModel): array
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 '45', column '14').
                Open

                        $end = new \DateTime($end);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                MissingImport

                Since: 2.7.0

                Importing all external classes in a file through use statements makes them clearly visible.

                Example

                function make() {
                    return new \stdClass();
                }

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

                Missing class import via use statement (line '150', column '16').
                Open

                        $rows = (new \App\Db\Query())->from('s_#__sla_policy')->where(['tabid' => $moduleId])->all(\App\Db::getInstance('admin'));
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                MissingImport

                Since: 2.7.0

                Importing all external classes in a file through use statements makes them clearly visible.

                Example

                function make() {
                    return new \stdClass();
                }

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

                Missing class import via use statement (line '116', column '16').
                Open

                        $rows = (new \App\Db\Query())->from('s_#__business_hours')->where(['id' => $ids])->all(\App\Db::getInstance('admin'));
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                MissingImport

                Since: 2.7.0

                Importing all external classes in a file through use statements makes them clearly visible.

                Example

                function make() {
                    return new \stdClass();
                }

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

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

                    public static function saveSlaPolicy(array $data, bool $delete = true)
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                BooleanArgumentFlag

                Since: 1.4.0

                A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

                Example

                class Foo {
                    public function bar($flag = true) {
                    }
                }

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

                Missing class import via use statement (line '83', column '16').
                Open

                        $rows = (new \App\Db\Query())->from('s_#__business_hours')->where(['default' => 1])->all(\App\Db::getInstance('admin'));
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                MissingImport

                Since: 2.7.0

                Importing all external classes in a file through use statements makes them clearly visible.

                Example

                function make() {
                    return new \stdClass();
                }

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

                Missing class import via use statement (line '98', column '16').
                Open

                        $rows = (new \App\Db\Query())->from('s_#__business_hours')->all(\App\Db::getInstance('admin'));
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                MissingImport

                Since: 2.7.0

                Importing all external classes in a file through use statements makes them clearly visible.

                Example

                function make() {
                    return new \stdClass();
                }

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

                Missing class import via use statement (line '44', column '16').
                Open

                        $start = new \DateTime($start);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                MissingImport

                Since: 2.7.0

                Importing all external classes in a file through use statements makes them clearly visible.

                Example

                function make() {
                    return new \stdClass();
                }

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

                Missing class import via use statement (line '133', column '15').
                Open

                        $row = (new \App\Db\Query())->from('s_#__sla_policy')->where(['id' => $id])->one(\App\Db::getInstance('admin'));
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                MissingImport

                Since: 2.7.0

                Importing all external classes in a file through use statements makes them clearly visible.

                Example

                function make() {
                    return new \stdClass();
                }

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

                Missing class import via use statement (line '168', column '17').
                Open

                            $rows = (new \App\Db\Query())->from('u_#__servicecontracts_sla_policy')->where(['crmid' => $serviceContractId])->all();
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                MissingImport

                Since: 2.7.0

                Importing all external classes in a file through use statements makes them clearly visible.

                Example

                function make() {
                    return new \stdClass();
                }

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

                Missing class import via use statement (line '320', column '17').
                Open

                            $rows = (new \App\Db\Query())->from('s_#__sla_policy')->where(['tabid' => $moduleId, 'available_for_record_time_count' => 1])->all(\App\Db::getInstance('admin'));
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                MissingImport

                Since: 2.7.0

                Importing all external classes in a file through use statements makes them clearly visible.

                Example

                function make() {
                    return new \stdClass();
                }

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

                Missing class import via use statement (line '517', column '15').
                Open

                        $date = new \DateTime();
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                MissingImport

                Since: 2.7.0

                Importing all external classes in a file through use statements makes them clearly visible.

                Example

                function make() {
                    return new \stdClass();
                }

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

                Avoid using static access to class '\App\Cache' in method 'getSlaPolicyById'.
                Open

                        \App\Cache::save('UtilsServiceContracts::getSlaPolicyById', $id, $row);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'getDefaultBusinessHours'.
                Open

                        if (\App\Cache::has('UtilsServiceContracts::getDefaultBusinessHours', '')) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'getSlaPolicyByModule'.
                Open

                            return \App\Cache::get('UtilsServiceContracts::getSlaPolicyByModule', $moduleId);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'getSlaPolicyForServiceContracts'.
                Open

                        if (\App\Cache::has('UtilsServiceContracts::getSlaPolicyForServiceContracts', $serviceContractId)) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'deleteSlaPolicy'.
                Open

                        \App\Cache::delete('UtilsServiceContracts::getSlaPolicyForServiceContracts', $crmId);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'getAllBusinessHours'.
                Open

                        if (\App\Cache::has('UtilsServiceContracts::getAllBusinessHours', '')) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'getSlaPolicyById'.
                Open

                            return \App\Cache::get('UtilsServiceContracts::getSlaPolicyById', $id);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'getSlaPolicyByModule'.
                Open

                        if (\App\Cache::has('UtilsServiceContracts::getSlaPolicyByModule', $moduleId)) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Condition' in method 'getSlaPolicyRulesForModule'.
                Open

                            if ($conditions && $row['business_hours'] && \App\Condition::checkConditions($conditions, $recordModel)) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Db' in method 'getBusinessHoursByIds'.
                Open

                        $rows = (new \App\Db\Query())->from('s_#__business_hours')->where(['id' => $ids])->all(\App\Db::getInstance('admin'));
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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 'businessTime'.
                Open

                            $holidaysDates = array_flip(array_keys(\App\Fields\Date::getHolidays($start->format('Y-m-d'), $end->format('Y-m-d'))));
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Db' in method 'getAllBusinessHours'.
                Open

                        $rows = (new \App\Db\Query())->from('s_#__business_hours')->all(\App\Db::getInstance('admin'));
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'getBusinessHoursByIds'.
                Open

                            return \App\Cache::get('UtilsServiceContracts::getBusinessHoursById', $cacheKey);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'getSlaPolicyById'.
                Open

                        if (\App\Cache::has('UtilsServiceContracts::getSlaPolicyById', $id)) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Db' in method 'getSlaPolicyByModule'.
                Open

                        $rows = (new \App\Db\Query())->from('s_#__sla_policy')->where(['tabid' => $moduleId])->all(\App\Db::getInstance('admin'));
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

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

                        } else {
                            $rows = (new \App\Db\Query())->from('u_#__servicecontracts_sla_policy')->where(['crmid' => $serviceContractId])->all();
                            \App\Cache::save('UtilsServiceContracts::getSlaPolicyForServiceContracts', $serviceContractId, $rows);
                        }
                Severity: Minor
                Found in app/Utils/ServiceContracts.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 static access to class '\App\Condition' in method 'getRulesForServiceContracts'.
                Open

                                    if ($conditions && $row['business_hours'] && \App\Condition::checkConditions($conditions, $recordModel)) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'getDefaultBusinessHours'.
                Open

                        \App\Cache::save('UtilsServiceContracts::getDefaultBusinessHours', '', $rows);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'getSlaPolicyForServiceContracts'.
                Open

                            \App\Cache::save('UtilsServiceContracts::getSlaPolicyForServiceContracts', $serviceContractId, $rows);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Json' in method 'getSlaPolicyRulesForModule'.
                Open

                            $conditions = \App\Json::decode($row['conditions']);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'getBusinessHoursByIds'.
                Open

                        if (\App\Cache::has('UtilsServiceContracts::getBusinessHoursById', $cacheKey)) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'getSlaPolicyForServiceContracts'.
                Open

                            $rows = \App\Cache::get('UtilsServiceContracts::getSlaPolicyForServiceContracts', $serviceContractId);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'getAllBusinessHours'.
                Open

                        \App\Cache::save('UtilsServiceContracts::getAllBusinessHours', '', $rows);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'getDefaultBusinessHours'.
                Open

                            return \App\Cache::get('UtilsServiceContracts::getDefaultBusinessHours', '');
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'getAllBusinessHours'.
                Open

                            return \App\Cache::get('UtilsServiceContracts::getAllBusinessHours', '');
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'getSlaPolicyByModule'.
                Open

                        \App\Cache::save('UtilsServiceContracts::getSlaPolicyByModule', $moduleId, $rows);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'getBusinessHoursByIds'.
                Open

                        \App\Cache::save('UtilsServiceContracts::getBusinessHoursById', $cacheKey, $rows);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Db' in method 'saveSlaPolicy'.
                Open

                        $db = \App\Db::getInstance();
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Json' in method 'getRulesForServiceContracts'.
                Open

                                    $conditions = \App\Json::decode($row['conditions']);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\TimePeriod' in method 'getRulesForServiceContracts'.
                Open

                                        if ((isset($times['reaction_time']) && \App\Fields\TimePeriod::convertToMinutes($row['reaction_time']) < \App\Fields\TimePeriod::convertToMinutes($times['reaction_time']))
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Json' in method 'getRulesForServiceContracts'.
                Open

                                    $conditions = \App\Json::decode($slaPolicy['conditions']);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\TimePeriod' in method 'getRulesForServiceContracts'.
                Open

                                        if ((isset($times['reaction_time']) && \App\Fields\TimePeriod::convertToMinutes($row['reaction_time']) < \App\Fields\TimePeriod::convertToMinutes($times['reaction_time']))
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Db' in method 'getDefaultBusinessHours'.
                Open

                        $rows = (new \App\Db\Query())->from('s_#__business_hours')->where(['default' => 1])->all(\App\Db::getInstance('admin'));
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Db' in method 'getSlaPolicyById'.
                Open

                        $row = (new \App\Db\Query())->from('s_#__sla_policy')->where(['id' => $id])->one(\App\Db::getInstance('admin'));
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Condition' in method 'getRulesForServiceContracts'.
                Open

                                    if ($conditions && \App\Condition::checkConditions($conditions, $recordModel)) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\DateTime' in method 'getDiff'.
                Open

                            $diff = \App\Fields\DateTime::getDiff($start, $end, 'minutes');
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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 assigning values to variables in if clauses and the like (line '438', column '9').
                Open

                    public static function getDiffFromServiceContracts(string $start, string $end, int $serviceContractId, \Vtiger_Record_Model $recordModel): int
                    {
                        if ($rules = self::getRulesForServiceContracts($serviceContractId, $recordModel)) {
                            if (isset($rules['id'])) {
                                return round(\App\Fields\DateTime::getDiff($start, $end, 'minutes'));
                Severity: Minor
                Found in app/Utils/ServiceContracts.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

                Avoid using static access to class '\App\Fields\DateTime' in method 'getDiffFromServiceContracts'.
                Open

                                return round(\App\Fields\DateTime::getDiff($start, $end, 'minutes'));
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\TimePeriod' in method 'getExpectedTimes'.
                Open

                                        $minutes = \App\Fields\TimePeriod::convertToMinutes($rules[$key]);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

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

                                    } else {
                                        $tmpDate = clone $date;
                                        $tmpInterval = $interval;
                                        while ($minutes > $tmpInterval) {
                                            $minutes -= $tmpInterval;
                Severity: Minor
                Found in app/Utils/ServiceContracts.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 static access to class '\App\Fields\TimePeriod' in method 'getSlaPolicyRulesForModule'.
                Open

                                if ((isset($times['reaction_time']) && \App\Fields\TimePeriod::convertToMinutes($row['reaction_time']) < \App\Fields\TimePeriod::convertToMinutes($times['reaction_time']))
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Db' in method 'getSlaPolicyForModule'.
                Open

                            $rows = (new \App\Db\Query())->from('s_#__sla_policy')->where(['tabid' => $moduleId, 'available_for_record_time_count' => 1])->all(\App\Db::getInstance('admin'));
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

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

                        } else {
                            $daySetting = $days['days'][$day];
                        }
                Severity: Minor
                Found in app/Utils/ServiceContracts.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 getExpectedTimes uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                Open

                        } else {
                            return [];
                        }
                Severity: Minor
                Found in app/Utils/ServiceContracts.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 static access to class '\App\Fields\TimePeriod' in method 'getExpectedTimes'.
                Open

                                    $minutes = \App\Fields\TimePeriod::convertToMinutes($daySetting[$key]);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

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

                            } else {
                                $result[$key] = ['working_days' => $day] + $value;
                            }
                Severity: Minor
                Found in app/Utils/ServiceContracts.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 assigning values to variables in if clauses and the like (line '410', column '9').
                Open

                    public static function getDiff(string $start, \Vtiger_Record_Model $recordModel, string $end = ''): int
                    {
                        if (!$end) {
                            $end = date('Y-m-d H:i:s');
                        }
                Severity: Minor
                Found in app/Utils/ServiceContracts.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

                Avoid using static access to class '\App\Cache' in method 'getSlaPolicyForModule'.
                Open

                            $rows = \App\Cache::get('UtilsServiceContracts::getSlaPolicyForModule', $moduleId);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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 assigning values to variables in if clauses and the like (line '407', column '15').
                Open

                    public static function getDiff(string $start, \Vtiger_Record_Model $recordModel, string $end = ''): int
                    {
                        if (!$end) {
                            $end = date('Y-m-d H:i:s');
                        }
                Severity: Minor
                Found in app/Utils/ServiceContracts.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

                Avoid assigning values to variables in if clauses and the like (line '518', column '15').
                Open

                    private static function getExpectedTimes(int $id, \Vtiger_Record_Model $recordModel, array $type): array
                    {
                        $return = [];
                        $date = new \DateTime();
                        if ($id && ($rules = self::getRulesForServiceContracts($id, $recordModel)) || ($rules = self::getSlaPolicyRulesForModule($recordModel))) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.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

                Avoid assigning values to variables in if clauses and the like (line '518', column '82').
                Open

                    private static function getExpectedTimes(int $id, \Vtiger_Record_Model $recordModel, array $type): array
                    {
                        $return = [];
                        $date = new \DateTime();
                        if ($id && ($rules = self::getRulesForServiceContracts($id, $recordModel)) || ($rules = self::getSlaPolicyRulesForModule($recordModel))) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.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

                Avoid assigning values to variables in if clauses and the like (line '529', column '13').
                Open

                    private static function getExpectedTimes(int $id, \Vtiger_Record_Model $recordModel, array $type): array
                    {
                        $return = [];
                        $date = new \DateTime();
                        if ($id && ($rules = self::getRulesForServiceContracts($id, $recordModel)) || ($rules = self::getSlaPolicyRulesForModule($recordModel))) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.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

                Avoid using static access to class '\App\Field' in method 'getModules'.
                Open

                        foreach (\App\Field::getRelatedFieldForModule(false, 'ServiceContracts') as $moduleName => $value) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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 assigning values to variables in if clauses and the like (line '404', column '23').
                Open

                    public static function getDiff(string $start, \Vtiger_Record_Model $recordModel, string $end = ''): int
                    {
                        if (!$end) {
                            $end = date('Y-m-d H:i:s');
                        }
                Severity: Minor
                Found in app/Utils/ServiceContracts.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

                Avoid using static access to class '\App\Cache' in method 'getSlaPolicyForModule'.
                Open

                        if (\App\Cache::has('UtilsServiceContracts::getSlaPolicyForModule', $moduleId)) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Cache' in method 'getSlaPolicyForModule'.
                Open

                            \App\Cache::save('UtilsServiceContracts::getSlaPolicyForModule', $moduleId, $rows);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\DateTime' in method 'getExpectedTimes'.
                Open

                                            $tmpInterval = \App\Fields\DateTime::getDiff($tmpDate->format('Y-m-d') . ' ' . $tmpDaySetting['working_hours_to'], $tmpDate->format('Y-m-d H:i:s'), 'minutes');
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\RecordStatus' in method 'getModules'.
                Open

                            if (\App\RecordStatus::getFieldName($moduleName)) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\Field' in method 'updateExpectedTimes'.
                Open

                        $field = \App\Field::getRelatedFieldForModule($recordModel->getModuleName(), 'ServiceContracts');
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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 assigning values to variables in if clauses and the like (line '428', column '7').
                Open

                    public static function getDiffFromServiceContracts(string $start, string $end, int $serviceContractId, \Vtiger_Record_Model $recordModel): int
                    {
                        if ($rules = self::getRulesForServiceContracts($serviceContractId, $recordModel)) {
                            if (isset($rules['id'])) {
                                return round(\App\Fields\DateTime::getDiff($start, $end, 'minutes'));
                Severity: Minor
                Found in app/Utils/ServiceContracts.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

                Avoid using static access to class '\App\Fields\DateTime' in method 'getDiffFromServiceContracts'.
                Open

                            $diff = round(\App\Fields\DateTime::getDiff($start, $end, 'minutes'));
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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 'getNextBusinessDay'.
                Open

                            if (\App\Fields\Date::getHolidays($date->format('Y-m-d'), $date->format('Y-m-d'))) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\TimePeriod' in method 'getSlaPolicyRulesForModule'.
                Open

                                if ((isset($times['reaction_time']) && \App\Fields\TimePeriod::convertToMinutes($row['reaction_time']) < \App\Fields\TimePeriod::convertToMinutes($times['reaction_time']))
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

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

                        } else {
                            $rows = (new \App\Db\Query())->from('s_#__sla_policy')->where(['tabid' => $moduleId, 'available_for_record_time_count' => 1])->all(\App\Db::getInstance('admin'));
                            \App\Cache::save('UtilsServiceContracts::getSlaPolicyForModule', $moduleId, $rows);
                        }
                Severity: Minor
                Found in app/Utils/ServiceContracts.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 assigning values to variables in if clauses and the like (line '455', column '7').
                Open

                    public static function getDiffFromSlaPolicy(string $start, string $end, \Vtiger_Record_Model $recordModel): ?int
                    {
                        if ($rules = self::getSlaPolicyRulesForModule($recordModel)) {
                            $time = 0;
                            foreach ($rules as $row) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.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

                Avoid using static access to class '\App\Fields\Date' in method 'getExpectedTimes'.
                Open

                        if (\App\Fields\Date::getHolidays($date->format('Y-m-d'), $date->format('Y-m-d'))) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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\DateTime' in method 'getExpectedTimes'.
                Open

                            $interval = \App\Fields\DateTime::getDiff($date->format('Y-m-d') . ' ' . $daySetting['working_hours_to'], $date->format('Y-m-d H:i:s'), 'minutes');
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                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 "UtilsServiceContracts::getSlaPolicyByModule" 3 times.
                Open

                        if (\App\Cache::has('UtilsServiceContracts::getSlaPolicyByModule', $moduleId)) {
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "UtilsServiceContracts::getSlaPolicyForModule" 3 times.
                Open

                        if (\App\Cache::has('UtilsServiceContracts::getSlaPolicyForModule', $moduleId)) {
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "u_#__servicecontracts_sla_policy" 3 times.
                Open

                            $rows = (new \App\Db\Query())->from('u_#__servicecontracts_sla_policy')->where(['crmid' => $serviceContractId])->all();
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "working_hours_to" 11 times.
                Open

                                        'working_hours_to' => $row['working_hours_to'],
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "admin" 6 times.
                Open

                        $rows = (new \App\Db\Query())->from('s_#__business_hours')->where(['default' => 1])->all(\App\Db::getInstance('admin'));
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "ServiceContracts" 3 times.
                Open

                        $fieldModel = current($recordModel->getModule()->getReferenceFieldsForModule('ServiceContracts'));
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "tabid" 5 times.
                Open

                        $rows = (new \App\Db\Query())->from('s_#__sla_policy')->where(['tabid' => $moduleId])->all(\App\Db::getInstance('admin'));
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "Y-m-d H:i:s" 6 times.
                Open

                            $end = date('Y-m-d H:i:s');
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "UtilsServiceContracts::getSlaPolicyForServiceContracts" 4 times.
                Open

                        if (\App\Cache::has('UtilsServiceContracts::getSlaPolicyForServiceContracts', $serviceContractId)) {
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "start" 4 times.
                Open

                                    'start' => clone $date,
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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.

                Add a "case default" clause to this "switch" statement.
                Open

                            switch ($row['policy_type']) {
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                The requirement for a final case default clause is defensive programming. The clause should either take appropriate action, or contain a suitable comment as to why no action is taken. Even when the switch covers all current values of an enum, a default case should still be used because there is no guarantee that the enum won't be extended.

                Noncompliant Code Example

                switch ($param) {  //missing default clause
                  case 0:
                    do_something();
                    break;
                  case 1:
                    do_something_else();
                    break;
                }
                
                switch ($param) {
                  default: // default clause should be the last one
                    error();
                    break;
                  case 0:
                    do_something();
                    break;
                  case 1:
                    do_something_else();
                    break;
                }
                

                Compliant Solution

                switch ($param) {
                  case 0:
                    do_something();
                    break;
                  case 1:
                    do_something_else();
                    break;
                  default:
                    error();
                    break;
                }
                

                See

                • MISRA C:2004, 15.0 - The MISRA C switch syntax shall be used.
                • MISRA C:2004, 15.3 - The final clause of a switch statement shall be the default clause
                • MISRA C++:2008, 6-4-3 - A switch statement shall be a well-formed switch statement.
                • MISRA C++:2008, 6-4-6 - The final clause of a switch statement shall be the default-clause
                • MISRA C:2012, 16.1 - All switch statements shall be well-formed
                • MISRA C:2012, 16.4 - Every switch statement shall have a default label
                • MISRA C:2012, 16.5 - A default label shall appear as either the first or the last switch label of a switch statement
                • MITRE, CWE-478 - Missing Default Case in Switch Statement
                • CERT, MSC01-C. - Strive for logical completeness
                • CERT, MSC01-CPP. - Strive for logical completeness

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

                            $rows = (new \App\Db\Query())->from('u_#__servicecontracts_sla_policy')->where(['crmid' => $serviceContractId])->all();
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "working_days" 8 times.
                Open

                            foreach (explode(',', $row['working_days']) as $day) {
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "holidays" 9 times.
                Open

                            if (!empty($row['holidays']) && ((isset($holidays['working_hours_from']) && (int) $row['working_hours_from'] < (int) $holidays['working_hours_from'])
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "business_hours" 6 times.
                Open

                                        if ($slaPolicy['business_hours']) {
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "UtilsServiceContracts::getSlaPolicyById" 3 times.
                Open

                        if (\App\Cache::has('UtilsServiceContracts::getSlaPolicyById', $id)) {
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "resolve_time" 9 times.
                Open

                        'resolve_time' => 'solution',
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "working_hours_from" 18 times.
                Open

                                if ((isset($days[$day]['working_hours_from']) && (int) $row['working_hours_from'] < (int) $days[$day]['working_hours_from'])
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "idle_time" 9 times.
                Open

                        'idle_time' => 'idle',
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "UtilsServiceContracts::getAllBusinessHours" 3 times.
                Open

                        if (\App\Cache::has('UtilsServiceContracts::getAllBusinessHours', '')) {
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "minutes" 5 times.
                Open

                            $diff = \App\Fields\DateTime::getDiff($start, $end, 'minutes');
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "s_#__sla_policy" 3 times.
                Open

                        $row = (new \App\Db\Query())->from('s_#__sla_policy')->where(['id' => $id])->one(\App\Db::getInstance('admin'));
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "UtilsServiceContracts::getDefaultBusinessHours" 3 times.
                Open

                        if (\App\Cache::has('UtilsServiceContracts::getDefaultBusinessHours', '')) {
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "Y-m-d" 9 times.
                Open

                            $holidaysDates = array_flip(array_keys(\App\Fields\Date::getHolidays($start->format('Y-m-d'), $end->format('Y-m-d'))));
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "conditions" 3 times.
                Open

                                    $conditions = \App\Json::decode($slaPolicy['conditions']);
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "reaction_time" 17 times.
                Open

                        'reaction_time' => 'response',
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "s_#__business_hours" 3 times.
                Open

                        $rows = (new \App\Db\Query())->from('s_#__business_hours')->where(['default' => 1])->all(\App\Db::getInstance('admin'));
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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 "UtilsServiceContracts::getBusinessHoursById" 3 times.
                Open

                        if (\App\Cache::has('UtilsServiceContracts::getBusinessHoursById', $cacheKey)) {
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by sonar-php

                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.

                Avoid unused local variables such as '$value'.
                Open

                        foreach (\App\Field::getRelatedFieldForModule(false, 'ServiceContracts') as $moduleName => $value) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                UnusedLocalVariable

                Since: 0.2

                Detects when a local variable is declared and/or assigned, but not used.

                Example

                class Foo {
                    public function doSomething()
                    {
                        $i = 5; // Unused
                    }
                }

                Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

                Call to undeclared method \App\Db\Query::from
                Open

                        $rows = (new \App\Db\Query())->from('s_#__business_hours')->where(['default' => 1])->all(\App\Db::getInstance('admin'));
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by phan

                Call to undeclared method \App\Db::createCommand
                Open

                        \App\Db::getInstance()->createCommand()
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by phan

                Call to undeclared method \App\Db::createCommand
                Open

                            $db->createCommand()->insert('u_#__servicecontracts_sla_policy', $data)->execute();
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by phan

                Expected @param annotation for endHour to be before the @param annotation for days
                Open

                     * @param array  $days
                Severity: Info
                Found in app/Utils/ServiceContracts.php by phan

                Returning type string but saveSlaPolicy() is declared to return void
                Open

                            return $db->getLastInsertID();
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phan

                Call to undeclared method \App\Db\Query::from
                Open

                            $rows = (new \App\Db\Query())->from('u_#__servicecontracts_sla_policy')->where(['crmid' => $serviceContractId])->all();
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by phan

                Call to undeclared method \App\Db\Query::from
                Open

                            $rows = (new \App\Db\Query())->from('s_#__sla_policy')->where(['tabid' => $moduleId, 'available_for_record_time_count' => 1])->all(\App\Db::getInstance('admin'));
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by phan

                Returning type false but getDiffFromDefaultBusinessHours() is declared to return int
                Open

                            return false;
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phan

                Call to undeclared method \App\Db\Query::from
                Open

                        $rows = (new \App\Db\Query())->from('s_#__business_hours')->all(\App\Db::getInstance('admin'));
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by phan

                Argument 2 (key) is int but \App\Cache::has() takes string defined at /code/app/Cache.php:74
                Open

                        if (\App\Cache::has('UtilsServiceContracts::getSlaPolicyById', $id)) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phan

                Argument 2 (key) is int but \App\Cache::get() takes string defined at /code/app/Cache.php:61
                Open

                            return \App\Cache::get('UtilsServiceContracts::getSlaPolicyById', $id);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phan

                Argument 2 (key) is int but \App\Cache::save() takes string defined at /code/app/Cache.php:89
                Open

                        \App\Cache::save('UtilsServiceContracts::getSlaPolicyByModule', $moduleId, $rows);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phan

                Argument 2 (key) is int but \App\Cache::delete() takes string defined at /code/app/Cache.php:105
                Open

                        \App\Cache::delete('UtilsServiceContracts::getSlaPolicyForServiceContracts', $crmId);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phan

                Expected @param annotation for recordModel to be before the @param annotation for end
                Open

                     * @param string               $end
                Severity: Info
                Found in app/Utils/ServiceContracts.php by phan

                Call to undeclared method \App\Db\Query::from
                Open

                        $row = (new \App\Db\Query())->from('s_#__sla_policy')->where(['id' => $id])->one(\App\Db::getInstance('admin'));
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by phan

                Returning type 0 but saveSlaPolicy() is declared to return void
                Open

                        return 0;
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phan

                Call to undeclared method \App\Db\Query::from
                Open

                        $rows = (new \App\Db\Query())->from('s_#__business_hours')->where(['id' => $ids])->all(\App\Db::getInstance('admin'));
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by phan

                Argument 2 (key) is int but \App\Cache::get() takes string defined at /code/app/Cache.php:61
                Open

                            return \App\Cache::get('UtilsServiceContracts::getSlaPolicyByModule', $moduleId);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phan

                Argument 2 (key) is int but \App\Cache::get() takes string defined at /code/app/Cache.php:61
                Open

                            $rows = \App\Cache::get('UtilsServiceContracts::getSlaPolicyForServiceContracts', $serviceContractId);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phan

                Returning type float but getDiffFromServiceContracts() is declared to return int
                Open

                                return round(\App\Fields\DateTime::getDiff($start, $end, 'minutes'));
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phan

                Call to undeclared method \App\Db\Query::from
                Open

                        $rows = (new \App\Db\Query())->from('s_#__sla_policy')->where(['tabid' => $moduleId])->all(\App\Db::getInstance('admin'));
                Severity: Critical
                Found in app/Utils/ServiceContracts.php by phan

                Argument 2 (key) is int but \App\Cache::has() takes string defined at /code/app/Cache.php:74
                Open

                        if (\App\Cache::has('UtilsServiceContracts::getSlaPolicyForModule', $moduleId)) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phan

                Argument 2 (key) is int but \App\Cache::save() takes string defined at /code/app/Cache.php:89
                Open

                        \App\Cache::save('UtilsServiceContracts::getSlaPolicyById', $id, $row);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phan

                Argument 2 (key) is int but \App\Cache::has() takes string defined at /code/app/Cache.php:74
                Open

                        if (\App\Cache::has('UtilsServiceContracts::getSlaPolicyByModule', $moduleId)) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phan

                Argument 2 (key) is int but \App\Cache::get() takes string defined at /code/app/Cache.php:61
                Open

                            $rows = \App\Cache::get('UtilsServiceContracts::getSlaPolicyForModule', $moduleId);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phan

                Argument 2 (key) is int but \App\Cache::has() takes string defined at /code/app/Cache.php:74
                Open

                        if (\App\Cache::has('UtilsServiceContracts::getSlaPolicyForServiceContracts', $serviceContractId)) {
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phan

                Doc-block of $ids in getBusinessHoursByIds contains phpdoc param type string which is incompatible with the param type array declared in the signature
                Open

                     * @param string $ids ex. '1,2'
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phan

                Argument 2 (key) is int but \App\Cache::save() takes string defined at /code/app/Cache.php:89
                Open

                            \App\Cache::save('UtilsServiceContracts::getSlaPolicyForServiceContracts', $serviceContractId, $rows);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phan

                Argument 2 (key) is int but \App\Cache::save() takes string defined at /code/app/Cache.php:89
                Open

                            \App\Cache::save('UtilsServiceContracts::getSlaPolicyForModule', $moduleId, $rows);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phan

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

                    public static function getSlaPolicyByModule(int $moduleId): array
                    {
                        if (\App\Cache::has('UtilsServiceContracts::getSlaPolicyByModule', $moduleId)) {
                            return \App\Cache::get('UtilsServiceContracts::getSlaPolicyByModule', $moduleId);
                        }
                Severity: Minor
                Found in app/Utils/ServiceContracts.php and 1 other location - About 50 mins to fix
                app/Utils/ServiceContracts.php on lines 128..136

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 97.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

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

                    private static function getSlaPolicyById(int $id): array
                    {
                        if (\App\Cache::has('UtilsServiceContracts::getSlaPolicyById', $id)) {
                            return \App\Cache::get('UtilsServiceContracts::getSlaPolicyById', $id);
                        }
                Severity: Minor
                Found in app/Utils/ServiceContracts.php and 1 other location - About 50 mins to fix
                app/Utils/ServiceContracts.php on lines 145..153

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 97.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

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

                        [$sh,$sm,$ss] = explode(':', $startHour);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                ShortVariable

                Since: 0.2

                Detects when a field, local, or parameter has a very short name.

                Example

                class Something {
                    private $q = 15; // VIOLATION - Field
                    public static function main( array $as ) { // VIOLATION - Formal
                        $r = 20 + $this->q; // VIOLATION - Local
                        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                            $r += $this->q;
                        }
                    }
                }

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

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

                        [$eh,$em,$es] = explode(':', $endHour);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                ShortVariable

                Since: 0.2

                Detects when a field, local, or parameter has a very short name.

                Example

                class Something {
                    private $q = 15; // VIOLATION - Field
                    public static function main( array $as ) { // VIOLATION - Formal
                        $r = 20 + $this->q; // VIOLATION - Local
                        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                            $r += $this->q;
                        }
                    }
                }

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

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

                        [$eh,$em,$es] = explode(':', $endHour);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                ShortVariable

                Since: 0.2

                Detects when a field, local, or parameter has a very short name.

                Example

                class Something {
                    private $q = 15; // VIOLATION - Field
                    public static function main( array $as ) { // VIOLATION - Formal
                        $r = 20 + $this->q; // VIOLATION - Local
                        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                            $r += $this->q;
                        }
                    }
                }

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

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

                        [$sh,$sm,$ss] = explode(':', $startHour);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                ShortVariable

                Since: 0.2

                Detects when a field, local, or parameter has a very short name.

                Example

                class Something {
                    private $q = 15; // VIOLATION - Field
                    public static function main( array $as ) { // VIOLATION - Formal
                        $r = 20 + $this->q; // VIOLATION - Local
                        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                            $r += $this->q;
                        }
                    }
                }

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

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

                        $db = \App\Db::getInstance();
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                ShortVariable

                Since: 0.2

                Detects when a field, local, or parameter has a very short name.

                Example

                class Something {
                    private $q = 15; // VIOLATION - Field
                    public static function main( array $as ) { // VIOLATION - Formal
                        $r = 20 + $this->q; // VIOLATION - Local
                        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                            $r += $this->q;
                        }
                    }
                }

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

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

                        [$sh,$sm,$ss] = explode(':', $startHour);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                ShortVariable

                Since: 0.2

                Detects when a field, local, or parameter has a very short name.

                Example

                class Something {
                    private $q = 15; // VIOLATION - Field
                    public static function main( array $as ) { // VIOLATION - Formal
                        $r = 20 + $this->q; // VIOLATION - Local
                        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                            $r += $this->q;
                        }
                    }
                }

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

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

                        [$eh,$em,$es] = explode(':', $endHour);
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                ShortVariable

                Since: 0.2

                Detects when a field, local, or parameter has a very short name.

                Example

                class Something {
                    private $q = 15; // VIOLATION - Field
                    public static function main( array $as ) { // VIOLATION - Formal
                        $r = 20 + $this->q; // VIOLATION - Local
                        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                            $r += $this->q;
                        }
                    }
                }

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

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

                    private static function getSlaPolicyById(int $id): array
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                ShortVariable

                Since: 0.2

                Detects when a field, local, or parameter has a very short name.

                Example

                class Something {
                    private $q = 15; // VIOLATION - Field
                    public static function main( array $as ) { // VIOLATION - Formal
                        $r = 20 + $this->q; // VIOLATION - Local
                        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                            $r += $this->q;
                        }
                    }
                }

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

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

                    private static function getExpectedTimes(int $id, \Vtiger_Record_Model $recordModel, array $type): array
                Severity: Minor
                Found in app/Utils/ServiceContracts.php by phpmd

                ShortVariable

                Since: 0.2

                Detects when a field, local, or parameter has a very short name.

                Example

                class Something {
                    private $q = 15; // VIOLATION - Field
                    public static function main( array $as ) { // VIOLATION - Formal
                        $r = 20 + $this->q; // VIOLATION - Local
                        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                            $r += $this->q;
                        }
                    }
                }

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

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

                        $end = new \DateTime($end);

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

                                $dates[] = [

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

                     * @param string $startHour

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

                    {

                Line exceeds 120 characters; contains 132 characters
                Open

                            if (isset($days[$date->format('N')]) && (!$holidays || ($holidays && !isset($holidaysDates[$date->format('Y-m-d')])))) {

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

                                ];

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

                            $businessStart = (clone $item['start'])->setTime($sh, $sm, $ss);

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

                                    'start' => clone $date,

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

                            $date->modify('+1 day')->setTime(0, 0, 0);

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

                            $businessEnd = (clone $item['end'])->setTime($eh, $em, $es);

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

                    public static function businessTime(string $start, string $end, string $startHour, string $endHour, array $days, bool $holidays): int

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

                        if ($holidays) {

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

                    /**

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

                     * @param bool   $holidays

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

                        }

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

                     * Fields map.

                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 (isset($days[$date->format('N')]) && (!$holidays || ($holidays && !isset($holidaysDates[$date->format('Y-m-d')])))) {

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

                     * Get the amount of business time between two dates in minutes.

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

                     * @param string $start

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

                     * @param string $end

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

                        $start = new \DateTime($start);

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

                        while ($date <= $end) {

                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

                     * @return int

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

                        $days = array_flip($days);

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

                     * @param string $endHour

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

                        'resolve_time' => 'solution',

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

                     *

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

                        'idle_time' => 'idle',

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

                            $holidaysDates = array_flip(array_keys(\App\Fields\Date::getHolidays($start->format('Y-m-d'), $end->format('Y-m-d'))));

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

                        }

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

                                    'end' => clone ($end < $datesEnd ? $end : $datesEnd),

                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

                        [$eh,$em,$es] = explode(':', $endHour);

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

                     * @param array  $days

                Line exceeds 120 characters; contains 137 characters
                Open

                    public static function businessTime(string $start, string $end, string $startHour, string $endHour, array $days, bool $holidays): int

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

                        $holidaysDates = $dates = [];

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

                        $date = clone $start;

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

                     */

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

                        'reaction_time' => 'response',

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

                            $datesEnd = (clone $date)->setTime(23, 59, 59);

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

                        return array_reduce($dates, function ($carry, $item) use ($sh, $sm, $ss, $eh, $em, $es) {

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

                    /**

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

                    private static $fieldsMap = [

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

                     */

                Line exceeds 120 characters; contains 131 characters
                Open

                            $holidaysDates = array_flip(array_keys(\App\Fields\Date::getHolidays($start->format('Y-m-d'), $end->format('Y-m-d'))));

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

                        [$sh,$sm,$ss] = explode(':', $startHour);

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

                        }, 0) / 60;

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

                    /**

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

                    {

                Line exceeds 120 characters; contains 126 characters
                Open

                        $rows = (new \App\Db\Query())->from('s_#__business_hours')->where(['id' => $ids])->all(\App\Db::getInstance('admin'));

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

                    }

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

                            foreach ($rows as $key => $value) {

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

                        if (\App\Cache::has('UtilsServiceContracts::getDefaultBusinessHours', '')) {

                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 array

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

                    /**

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

                     * @param int|null $rowId

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

                            ->delete('u_#__servicecontracts_sla_policy', $where)->execute();

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

                    }

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

                        $rows = (new \App\Db\Query())->from('s_#__business_hours')->where(['default' => 1])->all(\App\Db::getInstance('admin'));

                Line exceeds 120 characters; contains 128 characters
                Open

                        $rows = (new \App\Db\Query())->from('s_#__business_hours')->where(['default' => 1])->all(\App\Db::getInstance('admin'));

                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 array

                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\Cache::save('UtilsServiceContracts::getBusinessHoursById', $cacheKey, $rows);

                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 $row;

                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

                        \App\Cache::delete('UtilsServiceContracts::getSlaPolicyForServiceContracts', $crmId);

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

                        if ($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

                     * @param int $moduleId

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

                        return $rows;

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

                     * Get sla policy from service contracts by crm 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

                                    unset($rows[$key]);

                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

                     *

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

                            return \App\Cache::get('UtilsServiceContracts::getBusinessHoursById', $cacheKey);

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

                     * @param 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

                     * @param int      $serviceContractId Service contracts id

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

                     * @param int|null $sourceModuleId

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

                    public static function getAllBusinessHours(): array

                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

                            \App\Cache::save('UtilsServiceContracts::getSlaPolicyForServiceContracts', $serviceContractId, $rows);

                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 static function deleteSlaPolicy(int $crmId, int $sourceModuleId, ?int $rowId = null)

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

                     * Save sla policy for service contracts.

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

                    {

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

                        $db = \App\Db::getInstance();

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

                            return $db->getLastInsertID();

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

                    public static function getBusinessHoursByIds(array $ids): array

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

                    {

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

                        $row = (new \App\Db\Query())->from('s_#__sla_policy')->where(['id' => $id])->one(\App\Db::getInstance('admin'));

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

                    {

                Line exceeds 120 characters; contains 130 characters
                Open

                        $rows = (new \App\Db\Query())->from('s_#__sla_policy')->where(['tabid' => $moduleId])->all(\App\Db::getInstance('admin'));

                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

                            $end = ($item['end'] > $businessEnd) ? $businessEnd : $item['end'];

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

                            return \App\Cache::get('UtilsServiceContracts::getDefaultBusinessHours', '');

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

                        if (\App\Cache::has('UtilsServiceContracts::getAllBusinessHours', '')) {

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

                        return $rows;

                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 static function getSlaPolicyByModule(int $moduleId): array

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

                            return \App\Cache::get('UtilsServiceContracts::getSlaPolicyByModule', $moduleId);

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

                        \App\Cache::save('UtilsServiceContracts::getSlaPolicyByModule', $moduleId, $rows);

                Line exceeds 120 characters; contains 131 characters
                Open

                            $rows = (new \App\Db\Query())->from('u_#__servicecontracts_sla_policy')->where(['crmid' => $serviceContractId])->all();

                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 void

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

                     * @return void

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

                    public static function getDefaultBusinessHours(): array

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

                        return $rows;

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

                     * Get sla policy by 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

                     * Get sla policy by module id.

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

                    public static function getSlaPolicyForServiceContracts(int $serviceContractId, ?int $sourceModuleId = null): array

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

                        if ($rowId) {

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

                     * @param bool  $delete

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

                    public static function saveSlaPolicy(array $data, bool $delete = true)

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

                     * @return array

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

                        return $rows;

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

                    /**

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

                        $rows = (new \App\Db\Query())->from('s_#__business_hours')->all(\App\Db::getInstance('admin'));

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

                     *

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

                    private static function getSlaPolicyById(int $id): array

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

                     * @return array

                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 (\App\Cache::has('UtilsServiceContracts::getSlaPolicyForServiceContracts', $serviceContractId)) {

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

                            }

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

                     * @param int      $crmId

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

                        \App\Db::getInstance()->createCommand()

                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

                        \App\Cache::save('UtilsServiceContracts::getDefaultBusinessHours', '', $rows);

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

                     * @param string $ids ex. '1,2'

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

                            $rows = \App\Cache::get('UtilsServiceContracts::getSlaPolicyForServiceContracts', $serviceContractId);

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

                        }

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

                            $db->createCommand()->insert('u_#__servicecontracts_sla_policy', $data)->execute();

                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

                            return \App\Cache::get('UtilsServiceContracts::getSlaPolicyById', $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

                        return $rows;

                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 ($data['policy_type']) {

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

                            return $carry += max(0, $end->getTimestamp() - $start->getTimestamp());

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

                    }

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

                     * Get default business hours.

                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 \App\Cache::get('UtilsServiceContracts::getAllBusinessHours', '');

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

                    }

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

                        $rows = (new \App\Db\Query())->from('s_#__business_hours')->where(['id' => $ids])->all(\App\Db::getInstance('admin'));

                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 array

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

                        if (\App\Cache::has('UtilsServiceContracts::getSlaPolicyByModule', $moduleId)) {

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

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

                     * Delete sla policy for service contracts.

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

                        $where = ['crmid' => $crmId, 'tabid' => $sourceModuleId];

                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

                     * Get all business hours.

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

                        \App\Cache::save('UtilsServiceContracts::getAllBusinessHours', '', $rows);

                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

                        \App\Cache::save('UtilsServiceContracts::getSlaPolicyById', $id, $row);

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

                            $rows = (new \App\Db\Query())->from('u_#__servicecontracts_sla_policy')->where(['crmid' => $serviceContractId])->all();

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

                                if ($sourceModuleId !== $value['tabid']) {

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

                     * @param int      $sourceModuleId

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

                     *

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

                     * @param array $data

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

                     * Get business hours by ids .

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

                        $cacheKey = implode(',', $ids);

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

                        if (\App\Cache::has('UtilsServiceContracts::getBusinessHoursById', $cacheKey)) {

                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 (\App\Cache::has('UtilsServiceContracts::getSlaPolicyById', $id)) {

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

                        $rows = (new \App\Db\Query())->from('s_#__sla_policy')->where(['tabid' => $moduleId])->all(\App\Db::getInstance('admin'));

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

                            $where['id'] = $rowId;

                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 0;

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

                            $start = ($item['start'] < $businessStart) ? $businessStart : $item['start'];

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

                     * @return array

                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

                            self::deleteSlaPolicy($data['crmid'], $data['tabid']);

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

                        }

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

                                    $conditions = \App\Json::decode($slaPolicy['conditions']);

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

                                                'idle_time' => $row['idle_time'],

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

                     * @param int $moduleId

                Line exceeds 120 characters; contains 174 characters
                Open

                            $rows = (new \App\Db\Query())->from('s_#__sla_policy')->where(['tabid' => $moduleId, 'available_for_record_time_count' => 1])->all(\App\Db::getInstance('admin'));

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

                                    $days[$day] = [

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

                                    ];

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

                                    'working_hours_from' => $row['working_hours_from'],

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

                    public static function getRulesForServiceContracts(int $serviceContractId, \Vtiger_Record_Model $recordModel): array

                Line exceeds 120 characters; contains 126 characters
                Open

                                    if ($conditions && $row['business_hours'] && \App\Condition::checkConditions($conditions, $recordModel)) {

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

                                        || !isset($times['reaction_time'])) {

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

                        if ($businessHours) {

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

                            return $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

                    public static function getSlaPolicyForModule(int $moduleId): array

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

                            \App\Cache::save('UtilsServiceContracts::getSlaPolicyForModule', $moduleId, $rows);

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

                     * Parse business hours to days.

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

                        foreach ($rows as $row) {

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

                                    'resolve_time' => $row['resolve_time'],

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

                     * Get rules for record model which will be updated.

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

                     *

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

                                    $times = [

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

                            $result = [];

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

                                        'idle_time' => $row['idle_time'],

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

                                        'resolve_time' => $row['resolve_time'],

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

                     * @param \Vtiger_Record_Model $recordModel       Record the model that will be updated

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

                                        }

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

                                                'resolve_time' => $row['resolve_time'],

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

                                $result[] = array_merge($value, $times);

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

                                break;

                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 array

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

                     * @param int                  $serviceContractId Service contracts id

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

                                        if (empty($slaPolicy['operational_hours'])) {

                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

                                if ((isset($times['reaction_time']) && \App\Fields\TimePeriod::convertToMinutes($row['reaction_time']) < \App\Fields\TimePeriod::convertToMinutes($times['reaction_time']))

                Line exceeds 120 characters; contains 187 characters
                Open

                                if ((isset($times['reaction_time']) && \App\Fields\TimePeriod::convertToMinutes($row['reaction_time']) < \App\Fields\TimePeriod::convertToMinutes($times['reaction_time']))

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

                            $rows = (new \App\Db\Query())->from('s_#__sla_policy')->where(['tabid' => $moduleId, 'available_for_record_time_count' => 1])->all(\App\Db::getInstance('admin'));

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

                        }

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

                                        'working_hours_to' => $row['working_hours_to'],

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

                                                'reaction_time' => $row['reaction_time'],

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

                                    break;

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

                            foreach (self::optimizeBusinessHours(\array_unique($businessHours)) as $value) {

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

                     *

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

                        $times = $businessHours = [];

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

                        foreach (self::getSlaPolicyForModule($recordModel->getModule()->getId()) as $row) {

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

                            foreach (self::optimizeBusinessHours(\array_unique($businessHours)) as $value) {

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

                     * Get sla policy by crm id.

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

                        return $rows;

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

                     * @param array $rows

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

                            if (!empty($row['holidays']) && ((isset($holidays['working_hours_from']) && (int) $row['working_hours_from'] < (int) $holidays['working_hours_from'])

                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

                        $times = $businessHours = [];

                Line exceeds 120 characters; contains 121 characters
                Open

                        foreach (self::getSlaPolicyForServiceContracts($serviceContractId, $recordModel->getModule()->getId()) as $row) {

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

                                    break;

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

                    /**

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

                                        'reaction_time' => $row['reaction_time'],

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

                                $result[] = array_merge($value, $times);

                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

                        return ['days' => $days, 'holidays' => $holidays];

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

                     *

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

                            switch ($row['policy_type']) {

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

                                    if ($conditions && $row['business_hours'] && \App\Condition::checkConditions($conditions, $recordModel)) {

                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

                     */

                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

                     * @return array

                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 static function getSlaPolicyRulesForModule(\Vtiger_Record_Model $recordModel): array

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

                            if ($conditions && $row['business_hours'] && \App\Condition::checkConditions($conditions, $recordModel)) {

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

                                        'resolve_time' => $row['resolve_time'],

                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

                                if ((isset($days[$day]['working_hours_from']) && (int) $row['working_hours_from'] < (int) $days[$day]['working_hours_from'])

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

                            }

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

                     * Get rules for service contracts.

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

                                    if ($conditions && \App\Condition::checkConditions($conditions, $recordModel)) {

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

                                            return $slaPolicy;

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

                     * @param \Vtiger_Record_Model $recordModel Record the model that will be updated

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

                                        || !isset($times['reaction_time'])) {

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

                        $days = $holidays = [];

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

                                    || empty($days[$day]['working_hours_from'])) {

                Line exceeds 120 characters; contains 161 characters
                Open

                            if (!empty($row['holidays']) && ((isset($holidays['working_hours_from']) && (int) $row['working_hours_from'] < (int) $holidays['working_hours_from'])

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

                                $holidays = [

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

                     * @param array $businessHours

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

                                            return self::optimizeBusinessHours(explode(',', $slaPolicy['business_hours']));

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

                                    }

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

                                            $times = [

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

                    /**

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

                                        'reaction_time' => $row['reaction_time'],

                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

                                $result[$key] = ['working_days' => $result[$key]['working_days'] . ',' . $day] + $value;

                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 static function getDiffFromSlaPolicy(string $start, string $end, \Vtiger_Record_Model $recordModel): ?int

                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 $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

                        if ($rules = self::getRulesForServiceContracts($serviceContractId, $recordModel)) {

                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 = [];

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

                     * @return int

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

                            $recordModel->set($key . '_expected', $time);

                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 array

                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

                     *

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

                     * Undocumented function.

                Line exceeds 120 characters; contains 129 characters
                Open

                        ['days' => $days, 'holidays' => $holidays] = self::parseBusinessHoursToDays(self::getBusinessHoursByIds($businessHours));

                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

                    }

                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 (\is_int($diff = self::getDiffFromSlaPolicy($start, $end, $recordModel))) {

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

                     * @param string               $end

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

                            return $time;

                Line exceeds 120 characters; contains 173 characters
                Open

                                $time += self::businessTime($start, $end, $row['working_hours_from'], $row['working_hours_to'], explode(',', $row['working_days']), (bool) $row['holidays']);

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

                     *

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

                     * @param int                  $id          Service contract 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

                            if (isset($result[$key])) {

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

                                $result[$key] = ['working_days' => $day] + $value;

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

                            $diff = \App\Fields\DateTime::getDiff($start, $end, 'minutes');

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

                     * @param int                  $serviceContractId Service contracts id

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

                            $time = 0;

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

                            $diff = round(\App\Fields\DateTime::getDiff($start, $end, 'minutes'));

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

                        if ($rules = self::getSlaPolicyRulesForModule($recordModel)) {

                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 $time;

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

                    }

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

                     * @param string $start

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

                     *

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

                        $field = \App\Field::getRelatedFieldForModule($recordModel->getModuleName(), 'ServiceContracts');

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

                        $serviceContract = ($field && !empty($recordModel->get($field['fieldname']))) ? $recordModel->get($field['fieldname']) : 0;

                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

                                        $businessHours = \array_merge($businessHours, explode(',', $row['business_hours']));

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

                                        if ((isset($times['reaction_time']) && \App\Fields\TimePeriod::convertToMinutes($row['reaction_time']) < \App\Fields\TimePeriod::convertToMinutes($times['reaction_time']))

                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

                            $conditions = \App\Json::decode($row['conditions']);

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

                        return [];

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

                    {

                Line exceeds 120 characters; contains 140 characters
                Open

                                if ((isset($days[$day]['working_hours_from']) && (int) $row['working_hours_from'] < (int) $days[$day]['working_hours_from'])

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

                                    'idle_time' => $row['idle_time'],

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

                     * @param \Vtiger_Record_Model $recordModel Record the model that will be updated

                Line exceeds 120 characters; contains 174 characters
                Open

                                $time += self::businessTime($start, $end, $row['working_hours_from'], $row['working_hours_to'], explode(',', $row['working_days']), !empty($row['holidays']));

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

                        if (!($diff = self::getDiffFromDefaultBusinessHours($start, $end))) {

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

                     * Get the amount of business time between the two dates in minutes based on the global sla policy.

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

                     *

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

                     * @param string               $start

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

                     * @param string               $end

                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 (!$businessHours) {

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

                            if ($row['working_days']) {

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

                    /**

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

                        foreach (self::getExpectedTimes($serviceContract, $recordModel, $type) as $key => $time) {

                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

                        foreach (self::getSlaPolicyForServiceContracts($serviceContractId, $recordModel->getModule()->getId()) as $row) {

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

                                case 2:

                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 [];

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

                        if ($businessHours) {

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

                     * @return array

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

                        if (\App\Cache::has('UtilsServiceContracts::getSlaPolicyForModule', $moduleId)) {

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

                            $rows = \App\Cache::get('UtilsServiceContracts::getSlaPolicyForModule', $moduleId);

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

                    private static function parseBusinessHoursToDays(array $rows): array

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

                            foreach (explode(',', $row['working_days']) as $day) {

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

                                || empty($holidays['working_hours_from']))) {

                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

                     * @param string               $start

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

                     * @param \Vtiger_Record_Model $recordModel       Record the model that will be updated

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

                            foreach ($rules as $row) {

                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

                        $time = 0;

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

                        }

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

                     * @param array                $type

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

                    private static function getExpectedTimes(int $id, \Vtiger_Record_Model $recordModel, array $type): array

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

                     * Function returning difference in format between date times.

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

                            return self::getDiffFromServiceContracts($start, $end, $value, $recordModel);

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

                            if (isset($rules['id'])) {

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

                                $time += self::businessTime($start, $end, $row['working_hours_from'], $row['working_hours_to'], explode(',', $row['working_days']), !empty($row['holidays']));

                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

                        foreach ($businessHours as $row) {

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

                     * @return void

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

                    private static function optimizeBusinessHours(array $businessHours): array

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

                            $result[$key] = $result[$key] + ['holidays' => 1];

                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 $diff;

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

                            }

                Line exceeds 120 characters; contains 174 characters
                Open

                                $time += self::businessTime($start, $end, $row['working_hours_from'], $row['working_hours_to'], explode(',', $row['working_days']), !empty($row['holidays']));

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

                        }

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

                        $businessHours = self::getDefaultBusinessHours();

                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 array

                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

                     * @return array

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

                                    'reaction_time' => $row['reaction_time'],

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

                            }

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

                        ['days' => $days, 'holidays' => $holidays] = self::parseBusinessHoursToDays(self::getBusinessHoursByIds($businessHours));

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

                            $key = "{$value['working_hours_from']}|{$value['working_hours_to']}";

                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

                     * @param \Vtiger_Record_Model $recordModel Record the model that will be updated

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

                            $time = 0;

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

                     * Get the amount of default business time between two dates in minutes.

                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 false;

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

                     * @param array                $type

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

                    public static function updateExpectedTimes(\Vtiger_Record_Model $recordModel, array $type)

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

                    }

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

                                case 1:

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

                                    $slaPolicy = self::getSlaPolicyById($row['sla_policy_id']);

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

                                        if ($slaPolicy['business_hours']) {

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

                                    $conditions = \App\Json::decode($row['conditions']);

                Line exceeds 120 characters; contains 195 characters
                Open

                                        if ((isset($times['reaction_time']) && \App\Fields\TimePeriod::convertToMinutes($row['reaction_time']) < \App\Fields\TimePeriod::convertToMinutes($times['reaction_time']))

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

                            return $result;

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

                                $businessHours = \array_merge($businessHours, explode(',', $row['business_hours']));

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

                                        'idle_time' => $row['idle_time'],

                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

                                        'working_hours_from' => $row['working_hours_from'],

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

                                    'working_hours_to' => $row['working_hours_to'],

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

                            $key = "{$holidays['working_hours_from']}|{$holidays['working_hours_to']}";

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

                     * @param string               $end

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

                    public static function getDiff(string $start, \Vtiger_Record_Model $recordModel, string $end = ''): int

                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 = [];

                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 (!$end) {

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

                        $fieldModel = current($recordModel->getModule()->getReferenceFieldsForModule('ServiceContracts'));

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

                     * @return int

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

                     * @return int|null

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

                        return null;

                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

                        if ($holidays) {

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

                     * @param string               $start

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

                            return $diff;

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

                        }

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

                    }

                Line exceeds 120 characters; contains 146 characters
                Open

                    public static function getDiffFromServiceContracts(string $start, string $end, int $serviceContractId, \Vtiger_Record_Model $recordModel): int

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

                                return round(\App\Fields\DateTime::getDiff($start, $end, 'minutes'));

                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

                        if ($id && ($rules = self::getRulesForServiceContracts($id, $recordModel)) || ($rules = self::getSlaPolicyRulesForModule($recordModel))) {

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

                        foreach ($days as $day => $value) {

                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 ($fieldModel && ($value = $recordModel->get($fieldModel->getName()))) {

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

                    {

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

                            foreach ($rules as $row) {

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

                        }

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

                     * Update expected times.

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

                     * @param \Vtiger_Record_Model $recordModel

                Line exceeds 120 characters; contains 131 characters
                Open

                        $serviceContract = ($field && !empty($recordModel->get($field['fieldname']))) ? $recordModel->get($field['fieldname']) : 0;

                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

                     * @return int

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

                            $end = date('Y-m-d H:i:s');

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

                        if (!($diff = self::getDiffFromDefaultBusinessHours($start, $end))) {

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

                    /**

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

                     * Get the amount of business time between the two dates in minutes based on the service contracts.

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

                                $time += self::businessTime($start, $end, $row['working_hours_from'], $row['working_hours_to'], explode(',', $row['working_days']), !empty($row['holidays']));

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

                     * @param string $end

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

                    public static function getDiffFromServiceContracts(string $start, string $end, int $serviceContractId, \Vtiger_Record_Model $recordModel): int

                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 static function getDiffFromDefaultBusinessHours(string $start, string $end): int

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

                    {

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

                        $date = new \DateTime();

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

                                        $return[$fieldKey] = (clone $date)->modify("+$minutes minute")->format('Y-m-d H:i:s');

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

                            $daySetting = $days['holidays'];

                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

                                        $tmpDate = clone $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

                            if (isset($days['days'][$tempDay])) {

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

                            if (8 === $tempDay) {

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

                            ++$counter;

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

                            if (\App\RecordStatus::getFieldName($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

                                        }

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

                    }

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

                            $date->modify('+1 day');

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

                            if (\App\Fields\Date::getHolidays($date->format('Y-m-d'), $date->format('Y-m-d'))) {

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

                                break;

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

                                            $tmpDaySetting = self::getNextBusinessDay($tmpDate, $days);

                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

                        $modules = [];

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

                                        $minutes = \App\Fields\TimePeriod::convertToMinutes($rules[$key]);

                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 (\App\Fields\Date::getHolidays($date->format('Y-m-d'), $date->format('Y-m-d'))) {

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

                            $daySetting = $days['days'][$day];

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

                     * @param \DateTime $date

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

                        $counter = 1;

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

                        while ($counter < 14) {

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

                            \call_user_func_array([$date, 'setTime'], explode(':', $result['working_hours_from']));

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

                        return $modules;

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

                            if (isset($rules['id'])) {

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

                                            $minutes -= $tmpInterval;

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

                                                $return[$fieldKey] = (clone $tmpDate)->modify("+$minutes minute")->format('Y-m-d H:i:s');

                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

                        return $result;

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

                        foreach (\App\Field::getRelatedFieldForModule(false, 'ServiceContracts') as $moduleName => $value) {

                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

                        return $diff;

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

                     *

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

                                $time += self::businessTime($start, $end, $row['working_hours_from'], $row['working_hours_to'], explode(',', $row['working_days']), (bool) $row['holidays']);

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

                        return $time;

                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

                     * Get expected times from ServiceContracts.

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

                     * @param \Vtiger_Record_Model $recordModel

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

                        $return = [];

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

                        } elseif (empty($days['days'][$day])) {

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

                            $daySetting = self::getNextBusinessDay($date, $days);

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

                     * Get next business day.

                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 static function getModules(): array

                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

                        $daySetting = null;

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

                        } else {

                Line exceeds 120 characters; contains 187 characters
                Open

                                            $tmpInterval = \App\Fields\DateTime::getDiff($tmpDate->format('Y-m-d') . ' ' . $tmpDaySetting['working_hours_to'], $tmpDate->format('Y-m-d H:i:s'), 'minutes');

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

                Line exceeds 120 characters; contains 146 characters
                Open

                        if ($id && ($rules = self::getRulesForServiceContracts($id, $recordModel)) || ($rules = self::getSlaPolicyRulesForModule($recordModel))) {

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

                            return [];

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

                        }

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

                            $interval = \App\Fields\DateTime::getDiff($date->format('Y-m-d') . ' ' . $daySetting['working_hours_to'], $date->format('Y-m-d H:i:s'), 'minutes');

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

                                            $tmpInterval = \App\Fields\DateTime::getDiff($tmpDate->format('Y-m-d') . ' ' . $tmpDaySetting['working_hours_to'], $tmpDate->format('Y-m-d H:i:s'), 'minutes');

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

                    /**

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

                     * @param array     $days

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

                    {

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

                                break;

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

                                    if ($minutes < $interval) {

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

                        $tempDay = (int) $date->format('N') + 1;

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

                            ++$tempDay;

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

                        if ($daySetting) {

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

                            foreach (self::$fieldsMap as $key => $fieldKey) {

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

                                    $minutes = \App\Fields\TimePeriod::convertToMinutes($daySetting[$key]);

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

                                        $return[$fieldKey] = (clone $date)->modify("+$minutes minute")->format('Y-m-d H:i:s');

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

                                        while ($minutes > $tmpInterval) {

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

                     *

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

                    private static function getNextBusinessDay(\DateTime &$date, array $days): ?array

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

                        $result = null;

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

                     * Get modules name related to ServiceContracts.

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

                     * @return string[]

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

                        return [];

                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

                        } else {

                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 = $days['holidays'];

                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 (\in_array($fieldKey, $type)) {

                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 ($businessHours = self::getDefaultBusinessHours()) {

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

                                            if ($minutes < $tmpInterval) {

                Line exceeds 120 characters; contains 121 characters
                Open

                                                $return[$fieldKey] = (clone $tmpDate)->modify("+$minutes minute")->format('Y-m-d H:i:s');

                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 array|null

                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

                                foreach (self::$fieldsMap as $key => $fieldKey) {

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

                                    if (\in_array($fieldKey, $type)) {

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

                            $days = self::parseBusinessHoursToDays($rules);

                Line exceeds 120 characters; contains 159 characters
                Open

                            $interval = \App\Fields\DateTime::getDiff($date->format('Y-m-d') . ' ' . $daySetting['working_hours_to'], $date->format('Y-m-d H:i:s'), 'minutes');

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

                                        $tmpInterval = $interval;

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

                                $result = $days['days'][$tempDay];

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

                                $tempDay = 1;

                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

                                return $return;

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

                            $days = self::parseBusinessHoursToDays($businessHours);

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

                        $day = $date->format('N');

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

                            return $return;

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

                    /**

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

                                $modules[] = $moduleName;

                There are no issues that match your filters.

                Category
                Status