YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/widgets/PDFViewer.php

Summary

Maintainability
A
25 mins
Test Coverage
F
0%

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());
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php - About 25 mins to fix

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;
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phpmd

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');
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phpmd

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());
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phpmd

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'] = [];
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phpmd

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);
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phpmd

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());
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phpmd

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());
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phpmd

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())) {
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phpmd

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);
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phpmd

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');
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phpmd

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);
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phpmd

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');
Severity: Critical
Found in modules/Vtiger/widgets/PDFViewer.php by sonar-php

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 = [];
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phan

Call to method getName on non-class type false
Open

                $params['picklistValues'][$key] = \App\Language::translate($pdfTemplate->get('primary_name'), $this->moduleModel->getName());
Severity: Critical
Found in modules/Vtiger/widgets/PDFViewer.php by phan

Reference to undeclared property \Vtiger_PDFViewer_Widget->fields
Open

        if ($this->Record && !isset($this->fields)) {
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phan

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);
Severity: Critical
Found in modules/Vtiger/widgets/PDFViewer.php by phan

Reference to undeclared property \Vtiger_PDFViewer_Widget->Data
Open

            if (!empty($this->Data['action'])) {
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phan

Variable $params was undeclared, but array fields are being added to it.
Open

            $params['uitype'] = 16;
Severity: Info
Found in modules/Vtiger/widgets/PDFViewer.php by phan

Call to method getName on non-class type false
Open

            $handlerClass = \Vtiger_Loader::getComponentClassName('Model', 'PDF', $this->moduleModel->getName());
Severity: Critical
Found in modules/Vtiger/widgets/PDFViewer.php by phan

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);
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phan

Reference to undeclared property \Vtiger_PDFViewer_Widget->Data
Open

        if (!empty($this->Data['action']) && $this->Record && ($fields = $this->getCustomFields())) {
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phan

Call to method getName on non-class type false
Open

            $templates = $pdfModel->getActiveTemplatesForRecord($this->Record, 'Detail', $this->moduleModel->getName());
Severity: Critical
Found in modules/Vtiger/widgets/PDFViewer.php by phan

Call to undeclared function \array_key_first()
Open

                $params['fieldvalue'] = array_key_first($templates);
Severity: Critical
Found in modules/Vtiger/widgets/PDFViewer.php by phan

Call to method getName on non-class type false
Open

            $this->fields['template'] = \Vtiger_Field_Model::init($this->moduleModel->getName(), $params, 'template');
Severity: Critical
Found in modules/Vtiger/widgets/PDFViewer.php by phan

Reference to undeclared property \Vtiger_PDFViewer_Widget->fields
Open

        return $this->fields ?? [];
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phan

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';
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phan

Reference to undeclared property \Vtiger_PDFViewer_Widget->fields
Open

            $this->fields['template'] = \Vtiger_Field_Model::init($this->moduleModel->getName(), $params, 'template');
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phan

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

The class Vtiger_PDFViewer_Widget is not named in CamelCase.
Open

class Vtiger_PDFViewer_Widget extends Vtiger_Basic_Widget
{
    /** {@inheritdoc} */
    public function isPermitted(): bool
    {
Severity: Minor
Found in modules/Vtiger/widgets/PDFViewer.php by phpmd

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

Spaces must be used to indent lines; tabs are not allowed
Open

    /** {@inheritdoc} */

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getConfigTplName()

Spaces must be used to indent lines; tabs are not allowed
Open

            $templates = $pdfModel->getActiveTemplatesForRecord($this->Record, 'Detail', $this->moduleModel->getName());

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

            foreach ($templates as $key => $pdfTemplate) {

Spaces must be used to indent lines; tabs are not allowed
Open

            $this->fields['template'] = \Vtiger_Field_Model::init($this->moduleModel->getName(), $params, 'template');

Spaces must be used to indent lines; tabs are not allowed
Open

        return parent::getWidget();

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return array

Spaces must be used to indent lines; tabs are not allowed
Open

            $pdfModel = new $handlerClass();

Spaces must be used to indent lines; tabs are not allowed
Open

                $params['fieldvalue'] = array_key_first($templates);

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getCustomFields(): array

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

            $this->Config['url'] .= '&template=' . $fields['template']->get('fieldvalue');

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getWidget()

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);

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());

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

            $this->fields = [];

Spaces must be used to indent lines; tabs are not allowed
Open

            $handlerClass = \Vtiger_Loader::getComponentClassName('Model', 'PDF', $this->moduleModel->getName());

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

        return 'PDFViewerConfig';

Spaces must be used to indent lines; tabs are not allowed
Open

            }

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        if (!empty($this->Data['action']) && $this->Record && ($fields = $this->getCustomFields())) {

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        return $this->fields ?? [];

Spaces must be used to indent lines; tabs are not allowed
Open

            $params['picklistValues'] = [];

Spaces must be used to indent lines; tabs are not allowed
Open

            }

Spaces must be used to indent lines; tabs are not allowed
Open

    /** {@inheritdoc} */

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);

Spaces must be used to indent lines; tabs are not allowed
Open

    /** {@inheritdoc} */

Line exceeds 120 characters; contains 141 characters
Open

                $params['picklistValues'][$key] = \App\Language::translate($pdfTemplate->get('primary_name'), $this->moduleModel->getName());

Spaces must be used to indent lines; tabs are not allowed
Open

            if (!empty($this->Data['action'])) {

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';

Spaces must be used to indent lines; tabs are not allowed
Open

     * Gets custom fields.

Spaces must be used to indent lines; tabs are not allowed
Open

            $params['uitype'] = 16;

Spaces must be used to indent lines; tabs are not allowed
Open

        $this->Config['tpl'] = 'PDFViewerContainer.tpl';

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        if ($this->Record && !isset($this->fields)) {

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Class name "Vtiger_PDFViewer_Widget" is not in camel caps format
Open

class Vtiger_PDFViewer_Widget extends Vtiger_Basic_Widget

There are no issues that match your filters.

Category
Status