Function process
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
public function process(App\Request $request)
{
$result = false;
$fileContent = '';
if ($request->isEmpty('type') || $request->isEmpty('libraryName')) {
- 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 process
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process(App\Request $request)
{
$result = false;
$fileContent = '';
if ($request->isEmpty('type') || $request->isEmpty('libraryName')) {
Refactor this function to reduce its Cognitive Complexity from 23 to the 15 allowed. Open
public function process(App\Request $request)
- 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
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 {
if ('public' === $request->getByType('type', 1)) {
$dir = ROOT_DIRECTORY . DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR;
$libraryName = $request->getByType('libraryName', 'Text');
foreach ($this->packageFiles as $file) {
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method process uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$result = false;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method process uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$result = false;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method process uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$result = false;
}
- Read upRead up
- Exclude checks
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
Define a constant instead of duplicating this literal "libraryName" 3 times. Open
if ($request->isEmpty('type') || $request->isEmpty('libraryName')) {
- 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.
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('QUALIFIED_MODULE', $qualifiedModuleName);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('RESULT', $result);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('FILE_CONTENT', $fileContent);
- Exclude checks
Avoid excessively long class names like Settings_Dependencies_LibraryMoreInfo_View. Keep class name length under 40. Open
class Settings_Dependencies_LibraryMoreInfo_View extends Settings_Vtiger_BasicModal_View
{
/**
* Public libraries package files.
*
- Read upRead up
- Exclude checks
LongClassName
Since: 2.9
Detects when classes or interfaces are declared with excessively long names.
Example
class ATooLongClassNameThatHintsAtADesignProblem {
}
interface ATooLongInterfaceNameThatHintsAtADesignProblem {
}
Source https://phpmd.org/rules/naming.html#longclassname
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_Dependencies_LibraryMoreInfo_View extends Settings_Vtiger_BasicModal_View
- Exclude checks
The class Settings_Dependencies_LibraryMoreInfo_View is not named in CamelCase. Open
class Settings_Dependencies_LibraryMoreInfo_View extends Settings_Vtiger_BasicModal_View
{
/**
* Public libraries package files.
*
- 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
public $packageFiles = ['package.json', 'composer.json', 'bower.json'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fileContent = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($this->packageFiles as $file) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer = $this->getViewer($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
{
- 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
$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
public function process(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = false;
- 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
$viewer->view('LibraryMoreInfo.tpl', $qualifiedModuleName);
- 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
$filePath = 'vendor' . DIRECTORY_SEPARATOR . $request->getByType('libraryName', 'Text') . DIRECTORY_SEPARATOR . 'composer.json';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (file_exists($packageFile)) {
- 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
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (file_exists($filePath)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fileContent = file_get_contents($packageFile);
- 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
} elseif ('vendor' === $request->getByType('type', 1)) {
- 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
$result = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('QUALIFIED_MODULE', $qualifiedModuleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('public' === $request->getByType('type', 1)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$packageFile = $dir . $libraryName . DIRECTORY_SEPARATOR . $file;
- Exclude checks
Line exceeds 120 characters; contains 134 characters Open
$dir = ROOT_DIRECTORY . DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('RESULT', $result);
- 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
$result = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($request->isEmpty('type') || $request->isEmpty('libraryName')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$libraryName = $request->getByType('libraryName', 'Text');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fileContent = file_get_contents($filePath);
- 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
* @var string[]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('FILE_CONTENT', $fileContent);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Public libraries package files.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dir = ROOT_DIRECTORY . DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 144 characters Open
$filePath = 'vendor' . DIRECTORY_SEPARATOR . $request->getByType('libraryName', 'Text') . DIRECTORY_SEPARATOR . 'composer.json';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($fileContent) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = true;
- Exclude checks
Class name "Settings_Dependencies_LibraryMoreInfo_View" is not in camel caps format Open
class Settings_Dependencies_LibraryMoreInfo_View extends Settings_Vtiger_BasicModal_View
- Exclude checks