YetiForceCompany/YetiForceCRM

View on GitHub
modules/OSSTimeControl/models/Module.php

Summary

Maintainability
A
1 hr
Test Coverage
F
38%

Method getRelatedSummary has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getRelatedSummary(App\Db\Query $query)
    {
        $totalTime = $query->limit(null)->orderBy('')->sum('vtiger_osstimecontrol.sum_time');

        $userTime = [
Severity: Minor
Found in modules/OSSTimeControl/models/Module.php - About 1 hr to fix

    Missing class import via use statement (line '65', column '50').
    Open

            $dataReader = $query->select(['sumtime' => new \yii\db\Expression('SUM(vtiger_osstimecontrol.sum_time)'), 'vtiger_crmentity.smownerid'])

    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\Utils' in method 'getRelatedSummary'.
    Open

                $userTime['labels'][] = \App\Utils::getInitials($ownerName);

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

                'title' => \App\Language::translate('LBL_SUM', $this->getName()) . ': ' . \App\Fields\RangeTime::displayElapseTime($totalTime, 'i', 'hi', false),

    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\Fields\Owner' in method 'getRelatedSummary'.
    Open

                $color = App\Fields\Owner::getColor($row['smownerid']);

    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\Fields\Owner' in method 'getRelatedSummary'.
    Open

                $ownerName = App\Fields\Owner::getLabel($row['smownerid']) ?? '';

    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\Fields\RangeTime' in method 'getRelatedSummary'.
    Open

                $userTime['datasets'][0]['dataFormatted'][] = \App\Fields\RangeTime::displayElapseTime($row['sumtime']);

    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_Link_Model' in method 'getSideBarLinks'.
    Open

            array_unshift($links['SIDEBARLINK'], Vtiger_Link_Model::getInstanceFromValues([
                'linktype' => 'SIDEBARLINK',
                'linklabel' => 'LBL_CALENDAR_VIEW',
                'linkurl' => $this->getCalendarViewUrl(),
                'linkicon' => 'fas fa-calendar-alt',

    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\Fields\RangeTime' in method 'getRelatedSummary'.
    Open

                'title' => \App\Language::translate('LBL_SUM', $this->getName()) . ': ' . \App\Fields\RangeTime::displayElapseTime($totalTime, 'i', 'hi', false),

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

            $dataReader = $query->select(['sumtime' => new \yii\db\Expression('SUM(vtiger_osstimecontrol.sum_time)'), 'vtiger_crmentity.smownerid'])

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

                'datasets' => [

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

            $dataReader = $query->select(['sumtime' => new \yii\db\Expression('SUM(vtiger_osstimecontrol.sum_time)'), 'vtiger_crmentity.smownerid'])

    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.

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

            $totalTime = $query->limit(null)->orderBy('')->sum('vtiger_osstimecontrol.sum_time');
    Severity: Critical
    Found in modules/OSSTimeControl/models/Module.php by phan

    Call to method getLabel from undeclared class \App\Fields\Owner
    Open

                $ownerName = App\Fields\Owner::getLabel($row['smownerid']) ?? '';
    Severity: Critical
    Found in modules/OSSTimeControl/models/Module.php by phan

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

            $dataReader = $query->select(['sumtime' => new \yii\db\Expression('SUM(vtiger_osstimecontrol.sum_time)'), 'vtiger_crmentity.smownerid'])
    Severity: Critical
    Found in modules/OSSTimeControl/models/Module.php by phan

    Call to method getColor from undeclared class \App\Fields\Owner
    Open

                $color = App\Fields\Owner::getColor($row['smownerid']);
    Severity: Critical
    Found in modules/OSSTimeControl/models/Module.php by phan

    Call to method __construct from undeclared class \yii\db\Expression
    Open

            $dataReader = $query->select(['sumtime' => new \yii\db\Expression('SUM(vtiger_osstimecontrol.sum_time)'), 'vtiger_crmentity.smownerid'])
    Severity: Critical
    Found in modules/OSSTimeControl/models/Module.php by phan

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

    class OSSTimeControl_Module_Model extends Vtiger_Module_Model

    The class OSSTimeControl_Module_Model is not named in CamelCase.
    Open

    class OSSTimeControl_Module_Model extends Vtiger_Module_Model
    {
        public function getCalendarViewUrl()
        {
            return 'index.php?module=' . $this->getName() . '&view=Calendar';

    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

         *

    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 getLayoutTypeForQuickCreate(): string

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

        {

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

         * Function to get the Default View Component Name.

    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

                'datasets' => [

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

                ->groupBy('vtiger_crmentity.smownerid')->orderBy(['vtiger_crmentity.smownerid' => SORT_ASC])->createCommand()

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

                $userTime['labels'][] = \App\Utils::getInitials($ownerName);

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

                $userTime['datasets'][0]['data'][] = round((float) $row['sumtime'] / 60, 2);

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

        {

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

                        'tooltips' => [],

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

        }

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

                'title' => \App\Language::translate('LBL_SUM', $this->getName()) . ': ' . \App\Fields\RangeTime::displayElapseTime($totalTime, 'i', 'hi', false),

    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

            array_unshift($links['SIDEBARLINK'], Vtiger_Link_Model::getInstanceFromValues([

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

                'linkurl' => $this->getCalendarViewUrl(),

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

         * Function to get data of charts.

    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

            $totalTime = $query->limit(null)->orderBy('')->sum('vtiger_osstimecontrol.sum_time');

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

                'labels' => [],

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

                $userTime['datasets'][0]['dataFormatted'][] = \App\Fields\RangeTime::displayElapseTime($row['sumtime']);

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

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

            return $links;

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

        public function getDefaultViewName()

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

         */

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

            $userTime = [

    Line exceeds 120 characters; contains 121 characters
    Open

                ->groupBy('vtiger_crmentity.smownerid')->orderBy(['vtiger_crmentity.smownerid' => SORT_ASC])->createCommand()

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

                $color = App\Fields\Owner::getColor($row['smownerid']);

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

        public function getFieldsForSave(Vtiger_Record_Model $recordModel)

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

            return $fields;

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

                'linklabel' => 'LBL_CALENDAR_VIEW',

    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 getRelatedSummary(App\Db\Query $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

                    [

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

            $dataReader->close();

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

            return ['totalTime' => $totalTime, 'userTime' => $userTime];

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

            $fields = parent::getFieldsForSave($recordModel);

    Line exceeds 120 characters; contains 157 characters
    Open

                'title' => \App\Language::translate('LBL_SUM', $this->getName()) . ': ' . \App\Fields\RangeTime::displayElapseTime($totalTime, 'i', 'hi', false),

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

                        'data' => [],

    Line exceeds 120 characters; contains 144 characters
    Open

            $dataReader = $query->select(['sumtime' => new \yii\db\Expression('SUM(vtiger_osstimecontrol.sum_time)'), 'vtiger_crmentity.smownerid'])

    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 string

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

                $ownerName = App\Fields\Owner::getLabel($row['smownerid']) ?? '';

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

            return 'index.php?module=' . $this->getName() . '&view=Calendar';

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

                'linktype' => 'SIDEBARLINK',

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

                'linkicon' => 'fas fa-calendar-alt',

    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

                $userTime['datasets'][0]['backgroundColor'][] = $color;

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

        {

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

                $fields[] = 'sum_time';

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

         * @param App\Db\Query $query

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

                        'backgroundColor' => [],

    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->select(['sumtime' => new \yii\db\Expression('SUM(vtiger_osstimecontrol.sum_time)'), 'vtiger_crmentity.smownerid'])

    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

            if (!\in_array('sum_time', $fields)) {

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

    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 getSideBarLinks($linkParams)

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

            $links = parent::getSideBarLinks($linkParams);

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

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

                $userTime['datasets'][0]['tooltips'][] = $ownerName;

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

                $userTime['datasets'][0]['borderColor'][] = $color;

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

        public function getCalendarViewUrl()

    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

        /** {@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

                        'borderColor' => [],

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

    class OSSTimeControl_Module_Model extends Vtiger_Module_Model

    There are no issues that match your filters.

    Category
    Status