YetiForceCompany/YetiForceCRM

View on GitHub
modules/OSSTimeControl/dashboards/AllTimeControl.php

Summary

Maintainability
C
1 day
Test Coverage
F
0%

Function getWidgetTimeControl has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

    public function getWidgetTimeControl($user, $time)
    {
        if (!$time) {
            return ['show_chart' => false];
        }
Severity: Minor
Found in modules/OSSTimeControl/dashboards/AllTimeControl.php - About 6 hrs to fix

Cognitive Complexity

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

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

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

Further reading

Method getWidgetTimeControl has 95 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getWidgetTimeControl($user, $time)
    {
        if (!$time) {
            return ['show_chart' => false];
        }
Severity: Major
Found in modules/OSSTimeControl/dashboards/AllTimeControl.php - About 3 hrs to fix

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

        public function process(App\Request $request)
        {
            $currentUserId = \App\User::getCurrentUserId();
            $viewer = $this->getViewer($request);
            $moduleName = $request->getModule();
    Severity: Minor
    Found in modules/OSSTimeControl/dashboards/AllTimeControl.php - About 1 hr to fix

      The method getWidgetTimeControl() has 101 lines of code. Current threshold is set to 100. Avoid really long methods.
      Open

          public function getWidgetTimeControl($user, $time)
          {
              if (!$time) {
                  return ['show_chart' => false];
              }

      The method getWidgetTimeControl() has an NPath complexity of 6800. The configured NPath complexity threshold is 200.
      Open

          public function getWidgetTimeControl($user, $time)
          {
              if (!$time) {
                  return ['show_chart' => false];
              }

      NPathComplexity

      Since: 0.1

      The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

      Example

      class Foo {
          function bar() {
              // lots of complicated code
          }
      }

      Source https://phpmd.org/rules/codesize.html#npathcomplexity

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

          public function getWidgetTimeControl($user, $time)
          {
              if (!$time) {
                  return ['show_chart' => false];
              }

      CyclomaticComplexity

      Since: 0.1

      Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

      Example

      // Cyclomatic Complexity = 11
      class Foo {
      1   public function example() {
      2       if ($a == $b) {
      3           if ($a1 == $b1) {
                      fiddle();
      4           } elseif ($a2 == $b2) {
                      fiddle();
                  } else {
                      fiddle();
                  }
      5       } elseif ($c == $d) {
      6           while ($c == $d) {
                      fiddle();
                  }
      7        } elseif ($e == $f) {
      8           for ($n = 0; $n < $h; $n++) {
                      fiddle();
                  }
              } else {
                  switch ($z) {
      9               case 1:
                          fiddle();
                          break;
      10              case 2:
                          fiddle();
                          break;
      11              case 3:
                          fiddle();
                          break;
                      default:
                          fiddle();
                          break;
                  }
              }
          }
      }

      Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

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

          public function getWidgetTimeControl($user, $time)

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

      See

      The class OSSTimeControl_AllTimeControl_Dashboard has a coupling between objects value of 14. Consider to reduce the number of dependencies under 13.
      Open

      class OSSTimeControl_AllTimeControl_Dashboard extends Vtiger_IndexAjax_View
      {
          public function getSearchParams($assignedto, $date)
          {
              $conditions = [];

      CouplingBetweenObjects

      Since: 1.1.0

      A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

      Example

      class Foo {
          /**
           * @var \foo\bar\X
           */
          private $x = null;
      
          /**
           * @var \foo\bar\Y
           */
          private $y = null;
      
          /**
           * @var \foo\bar\Z
           */
          private $z = null;
      
          public function setFoo(\Foo $foo) {}
          public function setBar(\Bar $bar) {}
          public function setBaz(\Baz $baz) {}
      
          /**
           * @return \SplObjectStorage
           * @throws \OutOfRangeException
           * @throws \InvalidArgumentException
           * @throws \ErrorException
           */
          public function process(\Iterator $it) {}
      
          // ...
      }

      Source https://phpmd.org/rules/design.html#couplingbetweenobjects

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

              $query = (new App\Db\Query())->select(['sum_time', 'due_date', 'vtiger_osstimecontrol.timecontrol_type', 'vtiger_crmentity.smownerid', 'timecontrol_typeid'])

      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\Utils' in method 'getWidgetTimeControl'.
      Open

                      $chartData['labels'][] = \App\Utils::getInitials($ownerName);

      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 'Users_Record_Model' in method 'getWidgetTimeControl'.
      Open

              $currentUser = Users_Record_Model::getCurrentUserModel();

      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\User' in method 'process'.
      Open

              $currentUserId = \App\User::getCurrentUserId();

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class 'Settings_WidgetsManagement_Module_Model' in method 'process'.
      Open

                  $user = Settings_WidgetsManagement_Module_Model::getDefaultUserId($widget);

      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\PrivilegeQuery' in method 'getWidgetTimeControl'.
      Open

              \App\PrivilegeQuery::getConditions($query, $moduleName);

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class '\App\Language' in method 'getWidgetTimeControl'.
      Open

                  $label = \App\Language::translate($row['timecontrol_type'], 'OSSTimeControl');

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

              } else {
                  $viewer->view('dashboards/AllTimeControl.tpl', $moduleName);
              }

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

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

      Avoid using static access to class '\App\Fields\Owner' in method 'getWidgetTimeControl'.
      Open

                      $ownerName = \App\Fields\Owner::getUserLabel($row['smownerid']);

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

                  } else {
                      $workingTimeByType[$label] = (float) $row['sum_time'];
                  }

      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\RangeTime' in method 'getWidgetTimeControl'.
      Open

                  $dataset['label'] .= ': ' . \App\Fields\RangeTime::displayElapseTime($workingTimeByType[$dataset['label']]);

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class 'Settings_WidgetsManagement_Module_Model' in method 'process'.
      Open

                  $time = Settings_WidgetsManagement_Module_Model::getDefaultDateRange($widget);

      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\Picklist' in method 'getWidgetTimeControl'.
      Open

              $colors = \App\Fields\Picklist::getColors('timecontrol_type');

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

                  } else {
                      $workingTime[$row['smownerid']][$row['timecontrol_type']] = (float) $row['sum_time'];
                  }

      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\Date' in method 'getWidgetTimeControl'.
      Open

              $time = \App\Fields\Date::formatRangeToDisplay($time);

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

                          } else {
                              $userTime = 0;
                          }

      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\RangeTime' in method 'getWidgetTimeControl'.
      Open

                                  $dataset['dataFormatted'][] = \App\Fields\RangeTime::displayElapseTime($userTime);

      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 'Vtiger_Widget_Model' in method 'process'.
      Open

              $widget = Vtiger_Widget_Model::getInstance($request->getInteger('linkid'), $currentUserId);

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

              $viewer->assign('DTIME', \App\Fields\Date::formatRangeToDisplay($time));

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

                  return ['show_chart' => false];

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

                          'label' => $label,

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

              $query = (new App\Db\Query())->select(['sum_time', 'due_date', 'vtiger_osstimecontrol.timecontrol_type', 'vtiger_crmentity.smownerid', 'timecontrol_typeid'])

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

              $colors = \App\Fields\Picklist::getColors('timecontrol_type');

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

                  if (isset($workingTime[$row['smownerid']][$row['timecontrol_type']])) {

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

                  'datasets' => [],

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

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

      Noncompliant Code Example

      With the default threshold of 3:

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

      Compliant Solution

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

      Exceptions

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

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

              $query = (new App\Db\Query())->select(['sum_time', 'due_date', 'vtiger_osstimecontrol.timecontrol_type', 'vtiger_crmentity.smownerid', 'timecontrol_typeid'])

      Call to method getCurrentUserId from undeclared class \App\User (Did you mean class \Tests\App\User)
      Open

              $currentUserId = \App\User::getCurrentUserId();

      Call to undeclared method \Vtiger_Viewer::assign
      Open

              $viewer->assign('DATA', $this->getWidgetTimeControl($user, $time));

      Call to undeclared method \Vtiger_Viewer::assign
      Open

              $viewer->assign('OWNER', $user);

      Call to undeclared method \Vtiger_Viewer::assign
      Open

              $viewer->assign('WIDGET', $widget);

      Call to method getInstance from undeclared class \Vtiger_Widget_Model
      Open

              $widget = Vtiger_Widget_Model::getInstance($request->getInteger('linkid'), $currentUserId);

      Call to method getUserLabel from undeclared class \App\Fields\Owner
      Open

                      $ownerName = \App\Fields\Owner::getUserLabel($row['smownerid']);

      Call to undeclared method \Vtiger_Viewer::assign
      Open

              $viewer->assign('ACCESSIBLE_GROUPS', \App\Fields\Owner::getInstance($moduleName, $currentUserId)->getAccessibleGroupForModule());

      Call to undeclared method \Vtiger_Viewer::assign
      Open

              $viewer->assign('DTIME', \App\Fields\Date::formatRangeToDisplay($time));

      Call to undeclared method \Vtiger_Viewer::assign
      Open

              $viewer->assign('MODULE_NAME', $moduleName);

      Call to method getInstance from undeclared class \App\Fields\Owner
      Open

              $viewer->assign('ACCESSIBLE_GROUPS', \App\Fields\Owner::getInstance($moduleName, $currentUserId)->getAccessibleGroupForModule());

      Call to undeclared method \Vtiger_Viewer::assign
      Open

              $viewer->assign('TCPMODULE_MODEL', Settings_TimeControlProcesses_Module_Model::getCleanInstance()->getConfigInstance());

      Call to undeclared method \Vtiger_Viewer::assign
      Open

              $viewer->assign('ACCESSIBLE_USERS', \App\Fields\Owner::getInstance($moduleName, $currentUserId)->getAccessibleUsersForModule());

      Call to undeclared method \Vtiger_Viewer::assign
      Open

              $viewer->assign('LOGGEDUSERID', $currentUserId);

      Call to method getInstance from undeclared class \App\Fields\Owner
      Open

                  $user = array_keys(\App\Fields\Owner::getInstance(false, $currentUser)->getAccessibleUsers());

      Call to method getInstance from undeclared class \App\Fields\Owner
      Open

              $viewer->assign('ACCESSIBLE_USERS', \App\Fields\Owner::getInstance($moduleName, $currentUserId)->getAccessibleUsersForModule());

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

                  if (!\in_array($row['timecontrol_type'], $timeTypes)) {
                      $timeTypes[$row['timecontrol_typeid']] = $row['timecontrol_type'];
                      // one dataset per type
                      $chartData['datasets'][] = [
                          'label' => $label,
      Severity: Minor
      Found in modules/OSSTimeControl/dashboards/AllTimeControl.php and 1 other location - About 50 mins to fix
      modules/OSSTimeControl/dashboards/TimeControl.php on lines 75..87

      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

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

      class OSSTimeControl_AllTimeControl_Dashboard extends Vtiger_IndexAjax_View

      The class OSSTimeControl_AllTimeControl_Dashboard is not named in CamelCase.
      Open

      class OSSTimeControl_AllTimeControl_Dashboard extends Vtiger_IndexAjax_View
      {
          public function getSearchParams($assignedto, $date)
          {
              $conditions = [];

      CamelCaseClassName

      Since: 0.2

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

      Example

      class class_name {
      }

      Source

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

              $smOwners = [];

      Line exceeds 120 characters; contains 165 characters
      Open

              $query = (new App\Db\Query())->select(['sum_time', 'due_date', 'vtiger_osstimecontrol.timecontrol_type', 'vtiger_crmentity.smownerid', 'timecontrol_typeid'])

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

              if (!empty($date)) {

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

                  $user = array_keys(\App\Fields\Owner::getInstance(false, $currentUser)->getAccessibleUsers());

      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 (!\is_array($user)) {

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

                  ['>=', 'vtiger_osstimecontrol.due_date', $time[0]],

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

              if ('' != $assignedto) {

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

              }

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

              $listSearchParams[] = $conditions;

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

                  'show_chart' => false,

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

                  array_push($conditions, ['assigned_user_id', 'e', $assignedto]);

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

                  ->from('vtiger_osstimecontrol')

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

                  ['vtiger_osstimecontrol.deleted' => 0],

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

              $time = \App\Fields\Date::formatRangeToDisplay($time);

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

              $workingTimeByType = $workingTime = [];

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

          {

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

          public function getWidgetTimeControl($user, $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

              $query = (new App\Db\Query())->select(['sum_time', 'due_date', 'vtiger_osstimecontrol.timecontrol_type', 'vtiger_crmentity.smownerid', 'timecontrol_typeid'])

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

              return '&search_params=' . json_encode($listSearchParams);

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

                  return ['show_chart' => false];

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

                  ->where(['vtiger_crmentity.setype' => $moduleName, 'vtiger_crmentity.smownerid' => $user]);

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

              \App\PrivilegeQuery::getConditions($query, $moduleName);

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

                  'and',

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

          public function getSearchParams($assignedto, $date)

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

                  array_push($conditions, ['due_date', 'bw', implode(',', $date)]);

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

                  'labels' => [],

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

                  'fullLabels' => [],

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

              }

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

                  ->innerJoin('vtiger_timecontrol_type', 'vtiger_osstimecontrol.timecontrol_type = vtiger_timecontrol_type.timecontrol_type')

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

              $conditions = [];

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

              $query->andWhere([

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

                  ['<=', 'vtiger_osstimecontrol.due_date', $time[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

                      $ownerName = \App\Fields\Owner::getUserLabel($row['smownerid']);

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

                      foreach ($timeTypes as $timeTypeId => $timeType) {

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

                              if ($dataset['_type'] === $timeType) {

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

                                  $dataset['backgroundColor'][] = $colors[$timeTypeId];

      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 = Settings_WidgetsManagement_Module_Model::getDefaultDateRange($widget);

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

              }

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

              $listSearchParams = [];

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

          }

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

                  $user = [$user];

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

              $moduleName = 'OSSTimeControl';

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

                  ->innerJoin('vtiger_crmentity', 'vtiger_osstimecontrol.osstimecontrolid = vtiger_crmentity.crmid')

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

              $dataReader = $query->createCommand()->query();

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

                  'datasets' => [],

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

              ];

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

                  $label = \App\Language::translate($row['timecontrol_type'], 'OSSTimeControl');

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

                          'original_label' => $label,

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

                      $smOwners[] = $row['smownerid'];

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

                  foreach ($workingTime as $ownerId => $timeValue) {

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

                                  // each data item is an different owner time in this dataset/time 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

              $currentUserId = \App\User::getCurrentUserId();

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

              $currentUser = Users_Record_Model::getCurrentUserModel();

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

              $chartData = [

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

                          'data' => [],

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

                      $chartData['labels'][] = \App\Utils::getInitials($ownerName);

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

                          }

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

              $dataReader->close();

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

              $moduleName = $request->getModule();

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

              if (!$time) {

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

              if ('all' == $user) {

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

              }

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

              $colors = \App\Fields\Picklist::getColors('timecontrol_type');

      Line exceeds 120 characters; contains 135 characters
      Open

                  ->innerJoin('vtiger_timecontrol_type', 'vtiger_osstimecontrol.timecontrol_type = vtiger_timecontrol_type.timecontrol_type')

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

              $timeTypes = [];

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

                          'label' => $label,

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

                          'links' => [],

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

              foreach ($chartData['datasets'] as &$dataset) {

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

                          // if owner has this kind of type

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

                          if (!empty($timeValue[$timeType])) {

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

              $widget = Vtiger_Widget_Model::getInstance($request->getInteger('linkid'), $currentUserId);

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

              $viewer->assign('TCPMODULE_MODEL', Settings_TimeControlProcesses_Module_Model::getCleanInstance()->getConfigInstance());

      Line exceeds 120 characters; contains 128 characters
      Open

              $viewer->assign('TCPMODULE_MODEL', Settings_TimeControlProcesses_Module_Model::getCleanInstance()->getConfigInstance());

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

              $viewer->assign('WIDGET', $widget);

      Line exceeds 120 characters; contains 137 characters
      Open

              $viewer->assign('ACCESSIBLE_GROUPS', \App\Fields\Owner::getInstance($moduleName, $currentUserId)->getAccessibleGroupForModule());

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

                      // one dataset per type

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

                          foreach ($chartData['datasets'] as &$dataset) {

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

              $user = $request->getByType('owner', 2);

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

              $viewer->assign('LOGGEDUSERID', $currentUserId);

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

                  if (isset($workingTimeByType[$label])) {

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

                      $chartData['fullLabels'][] = $ownerName;

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

              if ($dataReader->count() > 0) {

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

                              $userTime = $timeValue[$timeType];

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

                                  $dataset['data'][] = round($userTime / 60, 2);

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

                          $dataset['links'][] = 'index.php?module=OSSTimeControl&view=List&viewname=All&entityState=Active' . $this->getSearchParams($ownerId, $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

                      $workingTimeByType[$label] += (float) $row['sum_time'];

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

                      $workingTimeByType[$label] = (float) $row['sum_time'];

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

                      $workingTime[$row['smownerid']][$row['timecontrol_type']] += (float) $row['sum_time'];

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

                  if (!\in_array($row['timecontrol_type'], $timeTypes)) {

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

                          '_type' => $row['timecontrol_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

              }

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

                      $chartData['datasets'][] = [

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

                  foreach ($smOwners as $ownerId) {

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

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

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

              while ($row = $dataReader->read()) {

      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

                                  $dataset['dataFormatted'][] = \App\Fields\RangeTime::displayElapseTime($userTime);

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

              }

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

              $viewer->assign('DTIME', \App\Fields\Date::formatRangeToDisplay($time));

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

              $viewer->assign('MODULE_NAME', $moduleName);

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

              $viewer->assign('ACCESSIBLE_USERS', \App\Fields\Owner::getInstance($moduleName, $currentUserId)->getAccessibleUsersForModule());

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

              $viewer->assign('ACCESSIBLE_GROUPS', \App\Fields\Owner::getInstance($moduleName, $currentUserId)->getAccessibleGroupForModule());

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

                  $viewer->view('dashboards/TimeControlContents.tpl', $moduleName);

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

                  $dataset['label'] .= ': ' . \App\Fields\RangeTime::displayElapseTime($workingTimeByType[$dataset['label']]);

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

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

              return $chartData;

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

              if ($request->has('content')) {

      Line exceeds 120 characters; contains 160 characters
      Open

                          $dataset['links'][] = 'index.php?module=OSSTimeControl&view=List&viewname=All&entityState=Active' . $this->getSearchParams($ownerId, $time);

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

              $time = $request->getDateRange('time');

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

              $viewer->assign('DATA', $this->getWidgetTimeControl($user, $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

                          'dataFormatted' => [],

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

                          'backgroundColor' => [],

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

                  $chartData['show_chart'] = true;

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

                  }

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

              $viewer->assign('OWNER', $user);

      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

                      foreach ($chartData['datasets'] as &$dataset) {

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

                      }

      Line exceeds 120 characters; contains 136 characters
      Open

              $viewer->assign('ACCESSIBLE_USERS', \App\Fields\Owner::getInstance($moduleName, $currentUserId)->getAccessibleUsersForModule());

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

                  if (isset($workingTime[$row['smownerid']][$row['timecontrol_type']])) {

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

                      $workingTime[$row['smownerid']][$row['timecontrol_type']] = (float) $row['sum_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

          public function process(App\Request $request)

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

              if (empty($time)) {

      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

                  $viewer->view('dashboards/AllTimeControl.tpl', $moduleName);

      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

                  $user = Settings_WidgetsManagement_Module_Model::getDefaultUserId($widget);

      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

                      $timeTypes[$row['timecontrol_typeid']] = $row['timecontrol_type'];

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

                  if (!\in_array($row['smownerid'], $smOwners)) {

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

              if (empty($user)) {

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

      class OSSTimeControl_AllTimeControl_Dashboard extends Vtiger_IndexAjax_View

      There are no issues that match your filters.

      Category
      Status