YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
35 mins
Test Coverage
F
40%

Method getEmailSendEntries has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public static function getEmailSendEntries($userId, $modules, $startDate, $endDate, $isExists = false)
Severity: Minor
Found in modules/Notification/models/Module.php - About 35 mins to fix

    The method getEmailSendEntries has a boolean flag argument $isExists, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public static function getEmailSendEntries($userId, $modules, $startDate, $endDate, $isExists = false)

    BooleanArgumentFlag

    Since: 1.4.0

    A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

    Example

    class Foo {
        public function bar($flag = true) {
        }
    }

    Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

    Missing class import via use statement (line '86', column '17').
    Open

            $query = (new \App\Db\Query())

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

            $queryGenerator = new App\QueryGenerator($this->getName());

    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

    The method getEntriesInstance has a boolean flag argument $limit, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public function getEntriesInstance($limit = false, $conditions = [])

    BooleanArgumentFlag

    Since: 1.4.0

    A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

    Example

    class Foo {
        public function bar($flag = true) {
        }
    }

    Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

    Avoid using static access to class 'Vtiger_Record_Model' in method 'getEntriesInstance'.
    Open

                $recordModel = Vtiger_Record_Model::getCleanInstance($this->getName());

    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\User' in method 'getQuery'.
    Open

            $queryGenerator->addNativeCondition(['smownerid' => \App\User::getCurrentUserId()]);

    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_Record_Model' in method 'getEmailSendEntries'.
    Open

                $recordModel = Vtiger_Record_Model::getCleanInstance('Notification');

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

            $queryGenerator->addNativeCondition(['u_#__notification.notification_status' => 'PLL_UNREAD']);

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

            $queryGenerator->setFields(['description', 'assigned_user_id', 'id', 'title', 'link', 'linkextend', 'process', 'subprocess', 'createdtime', 'notification_type', 'smcreatorid', 'notification_type', 'subprocess_sl']);

    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 "u_#__notification.notification_status" 3 times.
    Open

            $queryGenerator->addNativeCondition(['u_#__notification.notification_status' => 'PLL_UNREAD']);

    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 method setFields from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

            $queryGenerator->setFields(['description', 'assigned_user_id', 'id', 'title', 'link', 'linkextend', 'process', 'subprocess', 'createdtime', 'notification_type', 'smcreatorid', 'notification_type', 'subprocess_sl']);
    Severity: Critical
    Found in modules/Notification/models/Module.php by phan

    Call to method addNativeCondition from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

                $queryGenerator->addNativeCondition($conditions);
    Severity: Critical
    Found in modules/Notification/models/Module.php by phan

    Call to method addNativeCondition from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

            $queryGenerator->addNativeCondition(['u_#__notification.notification_status' => 'PLL_UNREAD']);
    Severity: Critical
    Found in modules/Notification/models/Module.php by phan

    Call to method __construct from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

            $queryGenerator = new App\QueryGenerator($this->getName());
    Severity: Critical
    Found in modules/Notification/models/Module.php by phan

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

                $query->limit($limit);
    Severity: Critical
    Found in modules/Notification/models/Module.php by phan

    Call to method close from undeclared class \yii\db\DataReader
    Open

            $dataReader->close();
    Severity: Critical
    Found in modules/Notification/models/Module.php by phan

    Default value for int $limit can't be false
    Open

        public function getEntriesInstance($limit = false, $conditions = [])
    Severity: Minor
    Found in modules/Notification/models/Module.php by phan

    Call to method createQuery from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

            return $queryGenerator->createQuery();
    Severity: Critical
    Found in modules/Notification/models/Module.php by phan

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

            return $query->count();
    Severity: Critical
    Found in modules/Notification/models/Module.php by phan

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

            $query = (new \App\Db\Query())
    Severity: Critical
    Found in modules/Notification/models/Module.php by phan

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

            $query->andWhere(['u_#__notification.notification_status' => 'PLL_UNREAD']);
    Severity: Critical
    Found in modules/Notification/models/Module.php by phan

    Call to method read from undeclared class \yii\db\DataReader
    Open

            while ($row = $dataReader->read()) {
    Severity: Critical
    Found in modules/Notification/models/Module.php by phan

    Call to method getCurrentUserId from undeclared class \App\User (Did you mean class \Tests\App\User)
    Open

            $queryGenerator->addNativeCondition(['smownerid' => \App\User::getCurrentUserId()]);
    Severity: Critical
    Found in modules/Notification/models/Module.php by phan

    Call to method addNativeCondition from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

            $queryGenerator->addNativeCondition(['smownerid' => \App\User::getCurrentUserId()]);
    Severity: Critical
    Found in modules/Notification/models/Module.php by phan

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

            $query->andWhere(['u_#__notification.notification_status' => 'PLL_UNREAD']);
    Severity: Critical
    Found in modules/Notification/models/Module.php by phan

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

    class Notification_Module_Model extends Vtiger_Module_Model

    The class Notification_Module_Model is not named in CamelCase.
    Open

    class Notification_Module_Model extends Vtiger_Module_Model
    {
        /**
         * Get query.
         *

    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

            $queryGenerator->setFields(['description', 'assigned_user_id', 'id', 'title', 'link', 'linkextend', 'process', 'subprocess', 'createdtime', 'notification_type', 'smcreatorid', 'notification_type', 'subprocess_sl']);

    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->andWhere(['u_#__notification.notification_status' => 'PLL_UNREAD']);

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

         * Get number of notifications.

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

            $query->andWhere(['u_#__notification.notification_status' => 'PLL_UNREAD']);

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

         * @param bool   $isExists

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

         * @param array $conditions

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

            return $entries;

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

         *

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

            $entries = [];

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

                $entries[$row['notification_type']][$row['notificationid']] = $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

        public function getTypes()

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

            $queryGenerator->addNativeCondition(['u_#__notification.notification_status' => 'PLL_UNREAD']);

    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

         * Function to get types of notification.

    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_Module_Model::getInstance($this->getName())->getFieldByName('notification_type')->getPicklistValues();

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

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

            $entries = [];

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

         * Function gets notifications to be sent.

    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

         */

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

        public function getQuery(array $conditions = []): App\Db\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

                ->from('u_#__notification')

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

            return $queryGenerator->createQuery();

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

                ->andWhere(['or', ['in', 'crmlink.setype', $modules], ['in', 'crmprocess.setype', $modules], ['in', 'crmsubprocess.setype', $modules]])

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

        }

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

                $queryGenerator->addNativeCondition($conditions);

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

         * @param int   $limit

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

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

                $entries[$row['id']] = $recordModel;

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

        public static function getEmailSendEntries($userId, $modules, $startDate, $endDate, $isExists = false)

    Line exceeds 120 characters; contains 124 characters
    Open

            return Vtiger_Module_Model::getInstance($this->getName())->getFieldByName('notification_type')->getPicklistValues();

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

         * @param array $conditions

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

            return $query->count();

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

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

         * @param string $startDate

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

         * @return Vtiger_Record_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

        {

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

            $query = $this->getQuery();

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

            $query = (new \App\Db\Query())

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

                ->leftJoin('vtiger_crmentity as crmsubprocess', 'u_#__notification.subprocess = crmsubprocess.crmid')

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

            $query->select(['u_#__notification.*', 'vtiger_crmentity.*']);

    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

                $recordModel = Vtiger_Record_Model::getCleanInstance('Notification');

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

            }

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

            $queryGenerator->addNativeCondition(['smownerid' => \App\User::getCurrentUserId()]);

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

            $query = $this->getQuery($conditions);

    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

                $recordModel = Vtiger_Record_Model::getCleanInstance($this->getName());

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

         * @return int

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

                return $query->exists();

    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

            while ($row = $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

         */

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

                ->where(['vtiger_crmentity.deleted' => 0, 'vtiger_crmentity.smownerid' => $userId])

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

         * Function returns notifications list.

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

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

         * @return \App\Db\Query

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

         * @param string $endDate

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

         *

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

                ->leftJoin('vtiger_crmentity as crmlink', 'u_#__notification.link = crmlink.crmid')

    Line exceeds 120 characters; contains 147 characters
    Open

                ->andWhere(['or', ['in', 'crmlink.setype', $modules], ['in', 'crmprocess.setype', $modules], ['in', 'crmsubprocess.setype', $modules]])

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

                ->andWhere(['between', 'vtiger_crmentity.createdtime', (string) $startDate, $endDate])

    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

         *

    Line exceeds 120 characters; contains 223 characters
    Open

            $queryGenerator->setFields(['description', 'assigned_user_id', 'id', 'title', 'link', 'linkextend', 'process', 'subprocess', 'createdtime', 'notification_type', 'smcreatorid', 'notification_type', 'subprocess_sl']);

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

        {

    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

            return $entries;

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

        {

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

            $queryGenerator = new App\QueryGenerator($this->getName());

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

            if (!empty($conditions)) {

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

        public function getEntriesInstance($limit = false, $conditions = [])

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

            if (!empty($limit)) {

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

                $recordModel->setData($row);

    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

        public function getEntriesCount(): int

    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 ($isExists) {

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

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

                ->innerJoin('vtiger_crmentity', 'u_#__notification.notificationid = vtiger_crmentity.crmid')

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

                ->leftJoin('vtiger_crmentity as crmprocess', 'u_#__notification.process = crmprocess.crmid')

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

                ->andWhere(['notification_status' => 'PLL_UNREAD']);

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

                $recordModel->setData($row);

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

         */

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

    class Notification_Module_Model extends Vtiger_Module_Model

    There are no issues that match your filters.

    Category
    Status