Function getCustomFields
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getCustomFields(): array
{
if ($this->Record && !isset($this->fields)) {
$this->fields = [];
$handlerClass = \Vtiger_Loader::getComponentClassName('Model', 'PDF', $this->moduleModel->getName());
- 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
Avoid using undefined variables such as '$params' which will lead to PHP notices. Open
$params['uitype'] = 16;
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$params' which will lead to PHP notices. Open
$this->fields['template'] = \Vtiger_Field_Model::init($this->moduleModel->getName(), $params, 'template');
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$params' which will lead to PHP notices. Open
$params['picklistValues'][$key] = \App\Language::translate($pdfTemplate->get('primary_name'), $this->moduleModel->getName());
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$params' which will lead to PHP notices. Open
$params['picklistValues'] = [];
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$params' which will lead to PHP notices. Open
$params['fieldvalue'] = array_key_first($templates);
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using static access to class '\Vtiger_Loader' in method 'getCustomFields'. Open
$handlerClass = \Vtiger_Loader::getComponentClassName('Model', 'PDF', $this->moduleModel->getName());
- 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 'getCustomFields'. Open
$params['picklistValues'][$key] = \App\Language::translate($pdfTemplate->get('primary_name'), $this->moduleModel->getName());
- 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 assigning values to variables in if clauses and the like (line '27', column '58'). Open
public function getWidget()
{
$this->Config['url'] = 'module=' . $this->Module . '&view=Detail&record=' . $this->Record . '&mode=showPDF';
$this->Config['tpl'] = 'PDFViewerContainer.tpl';
if (!empty($this->Data['action']) && $this->Record && ($fields = $this->getCustomFields())) {
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid using static access to class '\App\YetiForce\Shop' in method 'isPermitted'. Open
return parent::isPermitted() && \App\YetiForce\Shop::check('YetiForceWidgets') && Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModuleActionPermission($this->Module, 'ExportPdf') && \Vtiger_PDF_Model::getTemplatesByModule($this->Module);
- 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_Field_Model' in method 'getCustomFields'. Open
$this->fields['template'] = \Vtiger_Field_Model::init($this->moduleModel->getName(), $params, 'template');
- 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_PDF_Model' in method 'isPermitted'. Open
return parent::isPermitted() && \App\YetiForce\Shop::check('YetiForceWidgets') && Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModuleActionPermission($this->Module, 'ExportPdf') && \Vtiger_PDF_Model::getTemplatesByModule($this->Module);
- 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 "template" 3 times. Open
$this->Config['url'] .= '&template=' . $fields['template']->get('fieldvalue');
- 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.
Reference to undeclared property \Vtiger_PDFViewer_Widget->fields
Open
$this->fields = [];
- Exclude checks
Call to method getName
on non-class type false
Open
$params['picklistValues'][$key] = \App\Language::translate($pdfTemplate->get('primary_name'), $this->moduleModel->getName());
- Exclude checks
Reference to undeclared property \Vtiger_PDFViewer_Widget->fields
Open
if ($this->Record && !isset($this->fields)) {
- Exclude checks
Call to method check
from undeclared class \App\YetiForce\Shop
Open
return parent::isPermitted() && \App\YetiForce\Shop::check('YetiForceWidgets') && Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModuleActionPermission($this->Module, 'ExportPdf') && \Vtiger_PDF_Model::getTemplatesByModule($this->Module);
- Exclude checks
Reference to undeclared property \Vtiger_PDFViewer_Widget->Data
Open
if (!empty($this->Data['action'])) {
- Exclude checks
Variable $params
was undeclared, but array fields are being added to it. Open
$params['uitype'] = 16;
- Exclude checks
Call to method getName
on non-class type false
Open
$handlerClass = \Vtiger_Loader::getComponentClassName('Model', 'PDF', $this->moduleModel->getName());
- Exclude checks
Argument 1 (moduleName)
is false
but \Vtiger_PDF_Model::getTemplatesByModule()
takes string
defined at /code/modules/Vtiger/models/PDF.php:238
Open
return parent::isPermitted() && \App\YetiForce\Shop::check('YetiForceWidgets') && Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModuleActionPermission($this->Module, 'ExportPdf') && \Vtiger_PDF_Model::getTemplatesByModule($this->Module);
- Exclude checks
Reference to undeclared property \Vtiger_PDFViewer_Widget->Data
Open
if (!empty($this->Data['action']) && $this->Record && ($fields = $this->getCustomFields())) {
- Exclude checks
Call to method getName
on non-class type false
Open
$templates = $pdfModel->getActiveTemplatesForRecord($this->Record, 'Detail', $this->moduleModel->getName());
- Exclude checks
Call to undeclared function \array_key_first()
Open
$params['fieldvalue'] = array_key_first($templates);
- Exclude checks
Call to method getName
on non-class type false
Open
$this->fields['template'] = \Vtiger_Field_Model::init($this->moduleModel->getName(), $params, 'template');
- Exclude checks
Reference to undeclared property \Vtiger_PDFViewer_Widget->fields
Open
return $this->fields ?? [];
- Exclude checks
Suspicious type false
of a variable or expression used to build a string. (Expected type to be able to cast to a string) Open
$this->Config['url'] = 'module=' . $this->Module . '&view=Detail&record=' . $this->Record . '&mode=showPDF';
- Exclude checks
Reference to undeclared property \Vtiger_PDFViewer_Widget->fields
Open
$this->fields['template'] = \Vtiger_Field_Model::init($this->moduleModel->getName(), $params, 'template');
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Vtiger_PDFViewer_Widget extends Vtiger_Basic_Widget
- Exclude checks
The class Vtiger_PDFViewer_Widget is not named in CamelCase. Open
class Vtiger_PDFViewer_Widget extends Vtiger_Basic_Widget
{
/** {@inheritdoc} */
public function isPermitted(): bool
{
- 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 function isPermitted(): bool
- 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
public function getConfigTplName()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$templates = $pdfModel->getActiveTemplatesForRecord($this->Record, 'Detail', $this->moduleModel->getName());
- 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 ($templates as $key => $pdfTemplate) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->fields['template'] = \Vtiger_Field_Model::init($this->moduleModel->getName(), $params, 'template');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return parent::getWidget();
- 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
$pdfModel = new $handlerClass();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params['fieldvalue'] = array_key_first($templates);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getCustomFields(): 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->Config['url'] .= '&template=' . $fields['template']->get('fieldvalue');
- 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 getWidget()
- Exclude checks
Line exceeds 120 characters; contains 259 characters Open
return parent::isPermitted() && \App\YetiForce\Shop::check('YetiForceWidgets') && Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModuleActionPermission($this->Module, 'ExportPdf') && \Vtiger_PDF_Model::getTemplatesByModule($this->Module);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params['picklistValues'][$key] = \App\Language::translate($pdfTemplate->get('primary_name'), $this->moduleModel->getName());
- 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->fields = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$handlerClass = \Vtiger_Loader::getComponentClassName('Model', 'PDF', $this->moduleModel->getName());
- 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 'PDFViewerConfig';
- 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 (!empty($this->Data['action']) && $this->Record && ($fields = $this->getCustomFields())) {
- 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 $this->fields ?? [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params['picklistValues'] = [];
- 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
return parent::isPermitted() && \App\YetiForce\Shop::check('YetiForceWidgets') && Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModuleActionPermission($this->Module, 'ExportPdf') && \Vtiger_PDF_Model::getTemplatesByModule($this->Module);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Line exceeds 120 characters; contains 141 characters Open
$params['picklistValues'][$key] = \App\Language::translate($pdfTemplate->get('primary_name'), $this->moduleModel->getName());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($this->Data['action'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->Config['url'] = 'module=' . $this->Module . '&view=Detail&record=' . $this->Record . '&mode=showPDF';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Gets custom fields.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params['uitype'] = 16;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->Config['tpl'] = 'PDFViewerContainer.tpl';
- 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 ($this->Record && !isset($this->fields)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Class name "Vtiger_PDFViewer_Widget" is not in camel caps format Open
class Vtiger_PDFViewer_Widget extends Vtiger_Basic_Widget
- Exclude checks