Method getQueryByModuleField
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getQueryByModuleField($sourceModule, $field, $record, App\QueryGenerator $queryGenerator)
{
$supportedModulesList = [$this->getName(), 'Vendors', 'Leads', 'Accounts', 'PriceBooks'];
if (\in_array($sourceModule, $supportedModulesList) || Vtiger_Module_Model::getInstance($sourceModule)->isInventory()) {
$condition = ['and', ['vtiger_products.discontinued' => 1]];
Function getQueryByModuleField
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getQueryByModuleField($sourceModule, $field, $record, App\QueryGenerator $queryGenerator)
{
$supportedModulesList = [$this->getName(), 'Vendors', 'Leads', 'Accounts', 'PriceBooks'];
if (\in_array($sourceModule, $supportedModulesList) || Vtiger_Module_Model::getInstance($sourceModule)->isInventory()) {
$condition = ['and', ['vtiger_products.discontinued' => 1]];
- 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
Missing class import via use statement (line '41', column '22'). Open
$subQuery = (new App\Db\Query())
- 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
Missing class import via use statement (line '29', column '22'). Open
$subQuery = (new App\Db\Query())
- 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
Missing class import via use statement (line '34', column '22'). Open
$subQuery = (new App\Db\Query())
- 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
Define a constant instead of duplicating this literal "vtiger_products.productid" 4 times. Open
$condition[] = ['not in', 'vtiger_products.productid', $subQuery];
- 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 "productid" 3 times. Open
->select(['productid'])
- 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 "not in" 3 times. Open
$condition[] = ['not in', 'vtiger_products.productid', $subQuery];
- 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 '$field'. Open
public function getQueryByModuleField($sourceModule, $field, $record, App\QueryGenerator $queryGenerator)
- 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
Parameter $queryGenerator
has undeclared type \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
public function getQueryByModuleField($sourceModule, $field, $record, App\QueryGenerator $queryGenerator)
- Exclude checks
Call to method addCondition
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->addCondition('discontinued', 1, 'e');
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$subQuery = (new App\Db\Query())
- Exclude checks
Return type of getQueryForRecords()
is undeclared type \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
public function getQueryForRecords(string $searchValue, int $limit, int $srcRecord = null): App\QueryGenerator
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$subQuery = (new App\Db\Query())
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$subQuery = (new App\Db\Query())
- Exclude checks
Call to method addNativeCondition
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->addNativeCondition($condition);
- Exclude checks
Saw an @param annotation for skipSelected,
but it was not found in the param list of function getQueryByModuleField(string $sourceModule, string $field, string $record, \App\QueryGenerator $queryGenerator)
Open
* @param bool $skipSelected
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Products_Module_Model extends Vtiger_Module_Model
- Exclude checks
The class Products_Module_Model is not named in CamelCase. Open
class Products_Module_Model extends Vtiger_Module_Model
{
/**
* Function to get list view query for popup window.
*
- 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
* @param bool $skipSelected
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->select(['productid'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('vtiger_seproductsrel')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$condition[] = ['not in', 'vtiger_products.productid', $subQuery];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get list view query for popup window.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 128 characters Open
if (\in_array($sourceModule, $supportedModulesList) || Vtiger_Module_Model::getInstance($sourceModule)->isInventory()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['productid' => $record]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$subQuery = (new App\Db\Query())
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ('Vendors' === $sourceModule) {
- 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
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ('PriceBooks' === $sourceModule) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$condition[] = ['<>', 'vtiger_products.vendor_id', $record];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['setype' => $sourceModule]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getQueryByModuleField($sourceModule, $field, $record, App\QueryGenerator $queryGenerator)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$condition[] = ['not in', 'vtiger_products.productid', $subQuery];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->select(['productid'])
- 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
->where(['pricebookid' => $record]);
- 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
$condition = ['and', ['vtiger_products.discontinued' => 1]];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\in_array($sourceModule, $supportedModulesList) || Vtiger_Module_Model::getInstance($sourceModule)->isInventory()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $field parent fieldname
- 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
$condition[] = ['<>', 'vtiger_products.productid', $record];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->addNativeCondition($condition);
- 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 isSummaryViewSupported()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getQueryForRecords(string $searchValue, int $limit, int $srcRecord = null): App\QueryGenerator
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->addCondition('discontinued', 1, 'e');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $queryGenerator;
- 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 \App\QueryGenerator $queryGenerator
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($sourceModule === $this->getName()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$subQuery = (new App\Db\Query())
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to check whether the module is summary view supported.
- 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
$subQuery = (new App\Db\Query())
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('vtiger_pricebookproductrel')
- 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
$queryGenerator = parent::getQueryForRecords($searchValue, $limit, $srcRecord);
- 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
->from('vtiger_seproductsrel')
- 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 string $sourceModule Parent module
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $record parent id
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$supportedModulesList = [$this->getName(), 'Vendors', 'Leads', 'Accounts', 'PriceBooks'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->select(['crmid'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$condition[] = ['not in', 'vtiger_products.productid', $subQuery];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Class name "Products_Module_Model" is not in camel caps format Open
class Products_Module_Model extends Vtiger_Module_Model
- Exclude checks