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 = [
- Read upRead up
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 = [
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');
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');
- Read upRead up
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
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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)
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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')) {
- Read upRead up
- Exclude checks
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),
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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']])) {
- Read upRead up
- Exclude checks
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')) {
- Read upRead up
- Exclude checks
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)
- Read upRead up
- Exclude checks
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));
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('ADDRESS_EMAIL', $mailDetail['username']);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('MISSING_FOLDERS', $missingFolders);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('MODULE_NAME', $moduleName);
- Exclude checks
Call to undeclared method \Vtiger_Record_Model::getFolders
Open
$mailScannerFolders = $mailScannerRecordModel->getFolders($record);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('RECORD', $record);
- Exclude checks
Reference to static property mainFolders
from undeclared class \OSSMailScanner_Record_Model
Open
foreach (OSSMailScanner_Record_Model::$mainFolders as $mainFolder) {
- Exclude checks
Call to undeclared method \Vtiger_Record_Model::getFolders
Open
$folders = $mailRecordModel->getFolders($record);
- Exclude checks
Avoid excessively long variable names like $mailScannerRecordModel. Keep variable name length under 20. Open
$mailScannerRecordModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner');
- Read upRead up
- Exclude checks
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
- Exclude checks
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)
{
- Read upRead up
- Exclude checks
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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (OSSMailScanner_Record_Model::$mainFolders as $mainFolder) {
- Exclude checks
Line exceeds 120 characters; contains 135 characters Open
$treeRecordId = 0 === $i ? "{$mainFolder}/{$folderName}" : "{$mainFolder}/{$foldersSplited[$i - 1]}/{$folderName}";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function checkPermission(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'text' => \App\Language::translate($mainFolder, $moduleName)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$treeRecord = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $tree;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function process(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$request->has('record')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tempArray[$mainFolder][] = $treeCategory['id'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tree[] = $treeRecord;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'type' => 'category',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getSize(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return 'modal-lg';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $folders
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $selectedFolders
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$treeRecord['type'] = 'record';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tempArray[$mainFolder][] = $treeRecord['id'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
parent::checkPermission($request);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$treeRecordId = 0 === $i ? "{$mainFolder}/{$folderName}" : "{$mainFolder}/{$foldersSplited[$i - 1]}/{$folderName}";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'id' => $treeRecordId,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$treeRecord['db_type'] = $mainFolder;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Process.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \App\Request $request
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private function getTreeData(string $moduleName, array $folders, array $selectedFolders): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$treeCategory = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'id' => $mainFolder,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parentPath = $mainFolder;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\NoPermittedForAdmin('LBL_PERMISSION_DENIED');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $moduleName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'parent' => $parentPath,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$mailRecordModel = Vtiger_Record_Model::getCleanInstance('OSSMail');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$mailScannerRecordModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('TREE', $this->getTreeData($moduleName, $folders, $selectedFolders));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get tree data.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$treeRecord['db_id'] = $folder;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$qualifiedModuleName = $request->getModule(false);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$record = $request->getInteger('record');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$missingFolders = $selectedFolders = $folders = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$folders = $mailRecordModel->getFolders($record);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$missingFolders[] = $folder['folder'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($folders as $folder) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$foldersSplited = explode('/', $folder);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($foldersSplited as $i => $folderName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'type' => 'category',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\App\Module::getModuleId('OSSMail')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->view('Folders.tpl', $qualifiedModuleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'parent' => '#',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!\in_array($treeRecordId, $tempArray[$mainFolder])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'state' => ['selected' => \in_array($folder, (array) ($selectedFolders[$mainFolder] ?? []))]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (end($foldersSplited) === $folderName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parentPath = $treeRecordId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleName = $request->getModule();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($mailScannerFolders as $folder) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tree = $tempArray = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tree[] = $treeCategory;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'text' => \App\Language::translate($folderName, $moduleName),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$mailDetail = OSSMail_Record_Model::getMailAccountDetail($record);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->preProcess($request);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('ADDRESS_EMAIL', $mailDetail['username']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!isset($folders[$folder['folder']])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('RECORD', $record);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$mailScannerFolders = $mailScannerRecordModel->getFolders($record);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$selectedFolders[$folder['type']][] = $folder['folder'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('MODULE_NAME', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('MISSING_FOLDERS', $missingFolders);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->postProcess($request);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer = $this->getViewer($request);
- Exclude checks
Class name "Settings_OSSMailScanner_Folders_View" is not in camel caps format Open
class Settings_OSSMailScanner_Folders_View extends Settings_Vtiger_BasicModal_View
- Exclude checks