YetiForceCompany/YetiForceCRM

View on GitHub
modules/OSSTimeControl/dashboards/TimeCounterModel.php

Summary

Maintainability
A
0 mins
Test Coverage
F
0%

Avoid using undefined variables such as '$data' which will lead to PHP notices.
Open

                $data[$fieldName] = $value ? explode(' |##| ', $value) : [];

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 '$data' which will lead to PHP notices.
Open

                $this->set('data', \App\Json::encode($data));

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 '\App\Language' in method 'getTitle'.
Open

        return \App\Language::translate($this->get('linklabel'), 'Dashboard');

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\Json' in method 'getFieldInstanceByName'.
Open

            $data = $this->get('data') ? \App\Json::decode($this->get('data')) : [];

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

        return \Vtiger_Field_Model::init($moduleName, $params, $name);

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\Json' in method 'setDataFromRequest'.
Open

                $this->set('data', \App\Json::encode($data));

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 "label" 6 times.
Open

        'default_time' => ['label' => 'LBL_DEFAULT_TIME', 'purifyType' => \App\Purifier::TEXT],

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 "purifyType" 5 times.
Open

        'default_time' => ['label' => 'LBL_DEFAULT_TIME', 'purifyType' => \App\Purifier::TEXT],

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 "default_time" 3 times.
Open

        'default_time' => ['label' => 'LBL_DEFAULT_TIME', 'purifyType' => \App\Purifier::TEXT],

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 class \Vtiger_Widget_Model
Open

            return parent::getFieldInstanceByName($name);

Reference to undeclared class \Vtiger_Widget_Model
Open

        parent::setDataFromRequest($request);

Class extends undeclared class \Vtiger_Widget_Model
Open

class OSSTimeControl_TimeCounterModel_Dashboard extends Vtiger_Widget_Model

Call to undeclared method \OSSTimeControl_TimeCounterModel_Dashboard::get
Open

            $data = $this->get('data') ? \App\Json::decode($this->get('data')) : [];

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

                $data[$fieldName] = $value ? explode(' |##| ', $value) : [];

Call to undeclared method \OSSTimeControl_TimeCounterModel_Dashboard::get
Open

        return \App\Language::translate($this->get('linklabel'), 'Dashboard');

Call to undeclared method \OSSTimeControl_TimeCounterModel_Dashboard::set
Open

                $this->set('data', \App\Json::encode($data));

Invalid offset "tooltip" of array type array{label:'LBL_DEFAULT_TIME',purifyType:'Text'}
Open

            'tooltip' => $this->customFields[$name]['tooltip'] ?? ''

Avoid excessively long class names like OSSTimeControl_TimeCounterModel_Dashboard. Keep class name length under 40.
Open

class OSSTimeControl_TimeCounterModel_Dashboard extends Vtiger_Widget_Model
{
    /** {@inheritdoc} */
    public $customFields = [
        'default_time' => ['label' => 'LBL_DEFAULT_TIME', 'purifyType' => \App\Purifier::TEXT],

LongClassName

Since: 2.9

Detects when classes or interfaces are declared with excessively long names.

Example

class ATooLongClassNameThatHintsAtADesignProblem {

}

interface ATooLongInterfaceNameThatHintsAtADesignProblem {

}

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

Each class must be in a namespace of at least one level (a top-level vendor name)
Open

class OSSTimeControl_TimeCounterModel_Dashboard extends Vtiger_Widget_Model

The class OSSTimeControl_TimeCounterModel_Dashboard is not named in CamelCase.
Open

class OSSTimeControl_TimeCounterModel_Dashboard extends Vtiger_Widget_Model
{
    /** {@inheritdoc} */
    public $customFields = [
        'default_time' => ['label' => 'LBL_DEFAULT_TIME', 'purifyType' => \App\Purifier::TEXT],

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

    /** {@inheritdoc} */

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

        $params = [

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

    public function getEditFields(): array

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

        $moduleName = 'Settings:WidgetsManagement';

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

        if (!isset($this->customFields[$name])) {

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

            'label' => $this->customFields[$name]['label'],

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

    public $editFields = [

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

    ];

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

            'tooltip' => $this->customFields[$name]['tooltip'] ?? ''

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 ('default_time' === $name) {

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

        'width' => ['label' => 'LBL_WIDTH', 'purifyType' => \App\Purifier::INTEGER],

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

    public function getFieldInstanceByName($name)

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 $customFields = [

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

        'isdefault' => ['label' => 'LBL_MANDATORY_WIDGET', 'purifyType' => \App\Purifier::BOOL],

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

        'height' => ['label' => 'LBL_HEIGHT', 'purifyType' => \App\Purifier::INTEGER],

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

        return $this->editFields + $this->customFields;

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

    {

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

            $params['uitype'] = 33;

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::getFieldInstanceByName($name);

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

            'name' => $name,

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

            $data = $this->get('data') ? \App\Json::decode($this->get('data')) : [];

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

                '90' => '90',

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

            ];

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

        'default_time' => ['label' => 'LBL_DEFAULT_TIME', 'purifyType' => \App\Purifier::TEXT],

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

        }

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

            $params['typeofdata'] = 'V~O';

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

        return \Vtiger_Field_Model::init($moduleName, $params, $name);

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

    }

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

                $value = $fieldModel->getDBValue($value);

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

        return \App\Language::translate($this->get('linklabel'), 'Dashboard');

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

                '30' => '30',

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

    public function setDataFromRequest(App\Request $request)

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

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

            $params['fieldvalue'] = implode(' |##| ', $value);

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

                $fieldModel = $this->getFieldInstanceByName($fieldName)->getUITypeModel();

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

    /** {@inheritdoc} */

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

                '40' => '40',

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

                $data[$fieldName] = $value ? explode(' |##| ', $value) : [];

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

        }

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

                '15' => '15',

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

                '60' => '60',

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

        foreach ($this->customFields as $fieldName => $fieldInfo) {

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

            if ($request->has($fieldName) && 'default_time' === $fieldName) {

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

                $fieldModel->validate($value, true);

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

                $this->set('data', \App\Json::encode($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

            $value = $data[$name] ?? [];

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

        parent::setDataFromRequest($request);

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

                $value = $request->getByType($fieldName, $fieldInfo['purifyType']);

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

            }

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

class OSSTimeControl_TimeCounterModel_Dashboard extends Vtiger_Widget_Model

There are no issues that match your filters.

Category
Status