YetiForceCompany/YetiForceCRM

View on GitHub
api/webservice/WebservicePremium/Dashboard.php

Summary

Maintainability
A
0 mins
Test Coverage
F
49%

Missing class import via use statement (line '79', column '22').
Open

        $dataReader = (new \App\Db\Query())->select(['u_#__dashboard_type.*'])->from('u_#__dashboard_type')

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 '130', column '22').
Open

        $widgetModel = new \Vtiger_MiniList_Model();

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 '162', column '22').
Open

        $widgetModel = new \Vtiger_ChartFilter_Model();

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\Module' in method 'getData'.
Open

                'vtiger_module_dashboard_blocks.tabid' => Module::getModuleId($this->moduleName),

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 'getMiniList'.
Open

            $headers[$fieldName] = Language::translate($fieldModel->getFieldLabel(), $fieldModel->getModuleName());

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 'getTabs'.
Open

                'name' => \App\Language::translate($dashboard['name'], $this->moduleName),

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_Widget_Model' in method 'getMiniList'.
Open

        $widgetModel->setWidgetModel(\Vtiger_Widget_Model::getInstanceFromValues($row));

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_Widget_Model' in method 'getChartFilter'.
Open

        $widgetModel->setWidgetModel(\Vtiger_Widget_Model::getInstanceFromValues($row));

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 'getMiniList'.
Open

                'title' => \App\Language::translate($widgetModel->getTitle(), $widgetModel->getTargetModule()),

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 "linklabel" 4 times.
Open

            if (isset(self::$supportedWidgetsTypes[$row['linklabel']])) {

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.

null passed to foreach instead of array
Open

        foreach ($headerFields as $fieldName => $fieldModel) {

Call to undeclared method \App\Db\Query::select
Open

        $query = (new Query())->select(['vtiger_module_dashboard.*', 'vtiger_links.linklabel'])

Call to method getInstanceFromValues from undeclared class \Vtiger_Widget_Model
Open

        $widgetModel->setWidgetModel(\Vtiger_Widget_Model::getInstanceFromValues($row));

Call to method getInstanceFromValues from undeclared class \Vtiger_Widget_Model
Open

        $widgetModel->setWidgetModel(\Vtiger_Widget_Model::getInstanceFromValues($row));

Call to undeclared method \App\Db\Query::select
Open

        $dataReader = (new \App\Db\Query())->select(['u_#__dashboard_type.*'])->from('u_#__dashboard_type')

null passed to foreach instead of array
Open

        foreach ($widgetModel->getRecords('all') as $recordModel) {

null passed to foreach instead of array
Open

            foreach ($headerFields as $fieldName => $fieldModel) {

Avoid excessively long variable names like $supportedWidgetsTypes. Keep variable name length under 20.
Open

    public static $supportedWidgetsTypes = [
        'Mini List' => 'getMiniList',
        'ChartFilter' => 'getChartFilter',
    ];

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

Source https://phpmd.org/rules/naming.html#longvariable

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

    /** @var string[] Id application. */

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

    protected $dashboardType;

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

        'ChartFilter' => 'getChartFilter',

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

    protected $application;

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

     * Set dashboard ID.

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

        $tabs = [];

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

            ->innerJoin('vtiger_module_dashboard_blocks', 'vtiger_module_dashboard_blocks.id = vtiger_module_dashboard.blockid')

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

            $headers[$fieldName] = Language::translate($fieldModel->getFieldLabel(), $fieldModel->getModuleName());

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

        $widgetModel = new \Vtiger_ChartFilter_Model();

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

            ],

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

    /** @var int Id application. */

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

     * Function to get instance.

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

        $dataReader = (new \App\Db\Query())->select(['u_#__dashboard_type.*'])->from('u_#__dashboard_type')

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

            ->innerJoin('vtiger_module_dashboard_blocks', 'u_#__dashboard_type.dashboard_id = vtiger_module_dashboard_blocks.dashboard_id')

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

            ->where(['vtiger_module_dashboard_blocks.authorized' => $this->application])

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

                $widgets[] = $this->{self::$supportedWidgetsTypes[$row['linklabel']]}($row);

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

     * @return self

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

        $instance = new static();

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

     * @param int $dashboardType

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 $tabs;

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

    public function getData(): array

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

                'vtiger_module_dashboard_blocks.tabid' => Module::getModuleId($this->moduleName),

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

            if (isset(self::$supportedWidgetsTypes[$row['linklabel']])) {

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

        }

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

     * @param array $row

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

        foreach ($widgetModel->getRecords('all') as $recordModel) {

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

        }

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

            'data' => [

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

            ],

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

                'typeChart' => $widgetModel->getType(),

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

                'widgetData' => $widgetModel->getChartData(),

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

    public function setDashboard(int $dashboardType): self

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

        $dataReader = $query->createCommand()->query();

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

    {

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

        $headers = $records = [];

Line exceeds 120 characters; contains 133 characters
Open

                $records[$recordModel->getId()][$fieldName] = $recordModel->getDisplayValue($fieldName, $recordModel->getId(), true);

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

                'headers' => $headers,

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

                'records' => $records,

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

    /**

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

     * Get chart filter widget data.

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

    public static $supportedWidgetsTypes = [

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

     * Gets tabs.

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

        while ($dashboard = $dataReader->read()) {

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

    }

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

        'Mini List' => 'getMiniList',

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

     * @param string $moduleName

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

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

    public function getTabs(): 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

                'system' => $dashboard['system'],

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

    public function getMiniList(array $row): 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

                'name' => \App\Language::translate($dashboard['name'], $this->moduleName),

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

                'vtiger_module_dashboard_blocks.authorized' => $this->application,

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

        $widgetModel = new \Vtiger_MiniList_Model();

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

        }

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

                $records[$recordModel->getId()][$fieldName] = $recordModel->getDisplayValue($fieldName, $recordModel->getId(), true);

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

            }

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

    /** @var string Module name. */

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

                'title' => \App\Language::translate($widgetModel->getTitle(), $widgetModel->getTargetModule()),

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

            'data' => [

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

    protected $moduleName;

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

    /** @var int Type of dashboard. */

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

        $instance->moduleName = $moduleName;

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->dashboardType = $dashboardType;

Line exceeds 120 characters; contains 139 characters
Open

            ->innerJoin('vtiger_module_dashboard_blocks', 'u_#__dashboard_type.dashboard_id = vtiger_module_dashboard_blocks.dashboard_id')

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

    {

Line exceeds 120 characters; contains 128 characters
Open

            ->innerJoin('vtiger_module_dashboard_blocks', 'vtiger_module_dashboard_blocks.id = vtiger_module_dashboard.blockid')

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

            ->innerJoin('vtiger_links', 'vtiger_links.linkid = vtiger_module_dashboard.linkid')

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

                'vtiger_module_dashboard_blocks.dashboard_id' => $this->dashboardType,

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

     * @param array $row

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

     */

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

                'filterIds' => $widgetModel->getFilterIds(),

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

     *

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

     * @param int    $application

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

            $dbId = $dashboard['dashboard_id'];

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

            ->where([

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

        $widgets = [];

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

        $headerFields = $widgetModel->getHeaders();

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

    public function getChartFilter(array $row): array

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

     * @param int    $dashboardType

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

            ->distinct()->createCommand()->query();

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

        }

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

        $query = (new Query())->select(['vtiger_module_dashboard.*', 'vtiger_links.linklabel'])

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

            ->from('vtiger_module_dashboard')

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 [

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

        return [

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

            'type' => $row['linklabel'],

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

                'stacked' => $widgetModel->isStacked() ? 1 : 0,

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

        $instance->dashboardType = $dashboardType;

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

     */

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

            $tabs[$dbId] = [

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

                'id' => $dbId,

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

            $row['linkid'] = $row['id'];

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

     */

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

        foreach ($headerFields as $fieldName => $fieldModel) {

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

    public static function getInstance(string $moduleName, int $dashboardType, int $application): self

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

     * Return data about all added widgets in this dashboard.

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

        while ($row = $dataReader->read()) {

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

            foreach ($headerFields as $fieldName => $fieldModel) {

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

            'type' => $row['linklabel'],

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

                'colorsFromDividingField' => $widgetModel->areColorsFromDividingField() ? 1 : 0,

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

    }

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

        $instance->application = $application;

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

            }

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

        return $widgets;

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

    /**

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

     * Get mini list widget data.

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

     *

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

                'modulename' => $widgetModel->getTargetModule(),

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

        return $instance;

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

        $widgetModel->setWidgetModel(\Vtiger_Widget_Model::getInstanceFromValues($row));

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

        $widgetModel->setWidgetModel(\Vtiger_Widget_Model::getInstanceFromValues($row));

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

        return $this;

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

                'modulename' => $widgetModel->getTargetModule(),

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

                'title' => $widgetModel->getTitle(),

There are no issues that match your filters.

Category
Status