YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/OSSMailScanner/views/Folders.php

Summary

Maintainability
B
4 hrs
Test Coverage
F
0%

Function getTreeData has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    private function getTreeData(string $moduleName, array $folders, array $selectedFolders): array
    {
        $tree = $tempArray = [];
        foreach (OSSMailScanner_Record_Model::$mainFolders as $mainFolder) {
            $treeCategory = [
Severity: Minor
Found in modules/Settings/OSSMailScanner/views/Folders.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 getTreeData has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function getTreeData(string $moduleName, array $folders, array $selectedFolders): array
    {
        $tree = $tempArray = [];
        foreach (OSSMailScanner_Record_Model::$mainFolders as $mainFolder) {
            $treeCategory = [
Severity: Minor
Found in modules/Settings/OSSMailScanner/views/Folders.php - About 1 hr to fix

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

        public function process(App\Request $request)
        {
            $moduleName = $request->getModule();
            $qualifiedModuleName = $request->getModule(false);
            $record = $request->getInteger('record');
    Severity: Minor
    Found in modules/Settings/OSSMailScanner/views/Folders.php - About 1 hr to fix

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

          public function process(App\Request $request)
          {
              $moduleName = $request->getModule();
              $qualifiedModuleName = $request->getModule(false);
              $record = $request->getInteger('record');
      Severity: Minor
      Found in modules/Settings/OSSMailScanner/views/Folders.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

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

          private function getTreeData(string $moduleName, array $folders, array $selectedFolders): array

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

                  throw new \App\Exceptions\NoPermittedForAdmin('LBL_PERMISSION_DENIED');

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

                  $mailRecordModel = Vtiger_Record_Model::getCleanInstance('OSSMail');

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

                      'text' => \App\Language::translate($mainFolder, $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 'Vtiger_Record_Model' in method 'process'.
      Open

                  $mailScannerRecordModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner');

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

              if (\App\Module::getModuleId('OSSMail')) {

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

                                  'text' => \App\Language::translate($folderName, $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 'OSSMail_Record_Model' in method 'process'.
      Open

              $mailDetail = OSSMail_Record_Model::getMailAccountDetail($record);

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

                      if (!isset($folders[$folder['folder']])) {

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

              if (!$request->has('record')) {

      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 parameters such as '$request'.
      Open

          public function getSize(App\Request $request)

      UnusedFormalParameter

      Since: 0.2

      Avoid passing parameters to methods or constructors and then not using those parameters.

      Example

      class Foo
      {
          private function bar($howdy)
          {
              // $howdy is not used
          }
      }

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

      Call to undeclared method \Vtiger_Viewer::assign
      Open

              $viewer->assign('TREE', $this->getTreeData($moduleName, $folders, $selectedFolders));

      Call to undeclared method \Vtiger_Viewer::assign
      Open

              $viewer->assign('ADDRESS_EMAIL', $mailDetail['username']);

      Call to undeclared method \Vtiger_Viewer::assign
      Open

              $viewer->assign('MISSING_FOLDERS', $missingFolders);

      Call to undeclared method \Vtiger_Viewer::assign
      Open

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

      Call to undeclared method \Vtiger_Record_Model::getFolders
      Open

                  $mailScannerFolders = $mailScannerRecordModel->getFolders($record);

      Call to undeclared method \Vtiger_Viewer::assign
      Open

              $viewer->assign('RECORD', $record);

      Reference to static property mainFolders from undeclared class \OSSMailScanner_Record_Model
      Open

              foreach (OSSMailScanner_Record_Model::$mainFolders as $mainFolder) {

      Call to undeclared method \Vtiger_Record_Model::getFolders
      Open

                  $folders = $mailRecordModel->getFolders($record);

      Avoid excessively long variable names like $mailScannerRecordModel. Keep variable name length under 20.
      Open

                  $mailScannerRecordModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner');

      LongVariable

      Since: 0.2

      Detects when a field, formal or local variable is declared with a long name.

      Example

      class Something {
          protected $reallyLongIntName = -3; // VIOLATION - Field
          public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
              $otherReallyLongName = -5; // VIOLATION - Local
              for ($interestingIntIndex = 0; // VIOLATION - For
                   $interestingIntIndex < 10;
                   $interestingIntIndex++ ) {
              }
          }
      }

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

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

      class Settings_OSSMailScanner_Folders_View extends Settings_Vtiger_BasicModal_View

      The class Settings_OSSMailScanner_Folders_View is not named in CamelCase.
      Open

      class Settings_OSSMailScanner_Folders_View extends Settings_Vtiger_BasicModal_View
      {
          /** {@inheritdoc} */
          public function checkPermission(App\Request $request)
          {

      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

              }

      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 (OSSMailScanner_Record_Model::$mainFolders as $mainFolder) {

      Line exceeds 120 characters; contains 135 characters
      Open

                          $treeRecordId = 0 === $i ? "{$mainFolder}/{$folderName}" : "{$mainFolder}/{$foldersSplited[$i - 1]}/{$folderName}";

      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 checkPermission(App\Request $request)

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

                      'text' => \App\Language::translate($mainFolder, $moduleName)

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

                              $treeRecord = [

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

      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 (!$request->has('record')) {

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

                  $tempArray[$mainFolder][] = $treeCategory['id'];

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

                              $tree[] = $treeRecord;

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

                      'type' => 'category',

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

          public function getSize(App\Request $request)

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

              return 'modal-lg';

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

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

           * @param array  $selectedFolders

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

                                  $treeRecord['type'] = 'record';

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

                              $tempArray[$mainFolder][] = $treeRecord['id'];

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

              parent::checkPermission($request);

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

                  ];

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

           */

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

                          $treeRecordId = 0 === $i ? "{$mainFolder}/{$folderName}" : "{$mainFolder}/{$foldersSplited[$i - 1]}/{$folderName}";

      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

                                  'id' => $treeRecordId,

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

                                  $treeRecord['db_type'] = $mainFolder;

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

           * Process.

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

           * @param \App\Request $request

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

          /** {@inheritdoc} */

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

           */

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

          private function getTreeData(string $moduleName, array $folders, array $selectedFolders): array

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

                  $treeCategory = [

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

                      'id' => $mainFolder,

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

                      $parentPath = $mainFolder;

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

                  throw new \App\Exceptions\NoPermittedForAdmin('LBL_PERMISSION_DENIED');

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

           * @param string $moduleName

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

                                  'parent' => $parentPath,

      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

                  $mailRecordModel = Vtiger_Record_Model::getCleanInstance('OSSMail');

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

                  $mailScannerRecordModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner');

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

              $viewer->assign('TREE', $this->getTreeData($moduleName, $folders, $selectedFolders));

      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 tree data.

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

                                  $treeRecord['db_id'] = $folder;

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

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

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

              $record = $request->getInteger('record');

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

              $missingFolders = $selectedFolders = $folders = [];

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

                  $folders = $mailRecordModel->getFolders($record);

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

                          $missingFolders[] = $folder['folder'];

      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 ($folders as $folder) {

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

                      $foldersSplited = explode('/', $folder);

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

                      foreach ($foldersSplited as $i => $folderName) {

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

                                  'type' => 'category',

      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 (\App\Module::getModuleId('OSSMail')) {

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

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

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

                      'parent' => '#',

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

                          if (!\in_array($treeRecordId, $tempArray[$mainFolder])) {

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

                                  'state' => ['selected' => \in_array($folder, (array) ($selectedFolders[$mainFolder] ?? []))]

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

                              if (end($foldersSplited) === $folderName) {

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

                          $parentPath = $treeRecordId;

      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

              $moduleName = $request->getModule();

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

                  foreach ($mailScannerFolders as $folder) {

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

          }

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

              $tree = $tempArray = [];

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

                  $tree[] = $treeCategory;

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

                                  'text' => \App\Language::translate($folderName, $moduleName),

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

              $mailDetail = OSSMail_Record_Model::getMailAccountDetail($record);

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

              $this->preProcess($request);

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

          }

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

              $viewer->assign('ADDRESS_EMAIL', $mailDetail['username']);

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

                      if (!isset($folders[$folder['folder']])) {

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

              $viewer->assign('RECORD', $record);

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

                  $mailScannerFolders = $mailScannerRecordModel->getFolders($record);

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

                      $selectedFolders[$folder['type']][] = $folder['folder'];

      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('MISSING_FOLDERS', $missingFolders);

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

              $this->postProcess($request);

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

              }

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

                  }

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

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

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

      class Settings_OSSMailScanner_Folders_View extends Settings_Vtiger_BasicModal_View

      There are no issues that match your filters.

      Category
      Status