Function process
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
public function process()
{
foreach (App\Integrations\Magento\Config::getAllServers() as $serverId => $config) {
if (0 === (int) $config['status']) {
continue;
- 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 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process()
{
foreach (App\Integrations\Magento\Config::getAllServers() as $serverId => $config) {
if (0 === (int) $config['status']) {
continue;
Avoid too many return
statements within this method. Open
return;
The method process() has an NPath complexity of 4097. The configured NPath complexity threshold is 200. Open
public function process()
{
foreach (App\Integrations\Magento\Config::getAllServers() as $serverId => $config) {
if (0 === (int) $config['status']) {
continue;
- Read upRead up
- Exclude checks
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 process() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10. Open
public function process()
{
foreach (App\Integrations\Magento\Config::getAllServers() as $serverId => $config) {
if (0 === (int) $config['status']) {
continue;
- Read upRead up
- Exclude checks
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 25 to the 15 allowed. Open
public function process()
- 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
Reduce the number of returns of this function 5, down to the maximum allowed 3. Open
public function process()
- Read upRead up
- Exclude checks
Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.
Noncompliant Code Example
With the default threshold of 3:
function myFunction(){ // Noncompliant as there are 4 return statements if (condition1) { return true; } else { if (condition2) { return false; } else { return true; } } return false; }
Missing class import via use statement (line '25', column '22'). Open
$connector = (new App\Integrations\Magento\Controller($serverId));
- 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 'App\Integrations\Magento\Config' in method 'process'. Open
foreach (App\Integrations\Magento\Config::getAllServers() as $serverId => $config) {
- 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
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Vtiger_Magento_Cron extends \App\CronHandler
- Exclude checks
The class Vtiger_Magento_Cron is not named in CamelCase. Open
class Vtiger_Magento_Cron extends \App\CronHandler
{
/** {@inheritdoc} */
public function process()
{
- 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
return;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$connector->synchronizeCurrencies();
- 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 ($connector->config->get('sync_orders')) {
- 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
$this->updateLastActionTime();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->updateLastActionTime();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function process()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($this->checkTimeout()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$connector->synchronizeCategories();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (App\Integrations\Magento\Config::getAllServers() as $serverId => $config) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($this->checkTimeout()) {
- 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
continue;
- 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 ($connector->config->get('sync_currency')) {
- 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
$connector->synchronizeCustomers();
- 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->updateLastActionTime();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($connector->config->get('sync_categories')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($connector->config->get('sync_customers')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (0 === (int) $config['status']) {
- 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 ($connector->config->get('sync_products')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$connector->synchronizeProducts();
- 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
return;
- 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->updateLastActionTime();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->updateLastActionTime();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$connector->synchronizeInvoices();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($this->checkTimeout()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($this->checkTimeout()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->updateLastActionTime();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$connector = (new App\Integrations\Magento\Controller($serverId));
- 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 ($connector->config->get('sync_invoices')) {
- 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;
- 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
$connector->synchronizeOrders();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($this->checkTimeout()) {
- Exclude checks
Class name "Vtiger_Magento_Cron" is not in camel caps format Open
class Vtiger_Magento_Cron extends \App\CronHandler
- Exclude checks