YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
2 hrs
Test Coverage
F
0%

Method deleteAllRecords has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function deleteAllRecords(string $untilModifiedTime, int $userId)
    {
        $actualUserId = App\User::getCurrentUserId();
        try {
            if (!App\User::isExists($userId)) {
Severity: Minor
Found in modules/RecycleBin/models/Module.php - About 1 hr to fix

    Function deleteAllRecords has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function deleteAllRecords(string $untilModifiedTime, int $userId)
        {
            $actualUserId = App\User::getCurrentUserId();
            try {
                if (!App\User::isExists($userId)) {
    Severity: Minor
    Found in modules/RecycleBin/models/Module.php - About 55 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

    Missing class import via use statement (line '75', column '11').
    Open

                        (new App\BatchMethod(['method' => 'RecycleBin_Module_Model::deleteAllRecords', 'params' => [$untilModifiedTime, $userId]]))->save();
    Severity: Minor
    Found in modules/RecycleBin/models/Module.php by phpmd

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

                    throw new \App\Exceptions\NoPermitted('ERR_PERMISSION_DENIED', 406);
    Severity: Minor
    Found in modules/RecycleBin/models/Module.php by phpmd

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

                $dataReader = (new \App\Db\Query())->select(['crmid', 'setype'])->from('vtiger_crmentity')
    Severity: Minor
    Found in modules/RecycleBin/models/Module.php by phpmd

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

                App\User::setCurrentUserId($userId);
    Severity: Minor
    Found in modules/RecycleBin/models/Module.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 '\vtlib\Functions' in method 'deleteAllRecords'.
    Open

                $modulesList = \vtlib\Functions::getAllModules(true, false, 0);
    Severity: Minor
    Found in modules/RecycleBin/models/Module.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\Config' in method 'deleteAllRecords'.
    Open

                $deleteMaxCount = App\Config::module('RecycleBin', 'DELETE_MAX_COUNT');
    Severity: Minor
    Found in modules/RecycleBin/models/Module.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\User' in method 'deleteAllRecords'.
    Open

                App\User::setCurrentUserId($actualUserId);
    Severity: Minor
    Found in modules/RecycleBin/models/Module.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\User' in method 'deleteAllRecords'.
    Open

                App\User::setCurrentUserId($actualUserId);
    Severity: Minor
    Found in modules/RecycleBin/models/Module.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 '\vtlib\Functions' in method 'getAllModuleList'.
    Open

            return \vtlib\Functions::getAllModules(true, false, 0);
    Severity: Minor
    Found in modules/RecycleBin/models/Module.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\Log' in method 'deleteAllRecords'.
    Open

                \App\Log::error($ex->__toString());
    Severity: Minor
    Found in modules/RecycleBin/models/Module.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_Record_Model' in method 'deleteAllRecords'.
    Open

                    $recordModel = Vtiger_Record_Model::getInstanceById($row['crmid'], $row['setype']);
    Severity: Minor
    Found in modules/RecycleBin/models/Module.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\User' in method 'deleteAllRecords'.
    Open

            $actualUserId = App\User::getCurrentUserId();
    Severity: Minor
    Found in modules/RecycleBin/models/Module.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\User' in method 'deleteAllRecords'.
    Open

                if (!App\User::isExists($userId)) {
    Severity: Minor
    Found in modules/RecycleBin/models/Module.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 "setype" 3 times.
    Open

                $dataReader = (new \App\Db\Query())->select(['crmid', 'setype'])->from('vtiger_crmentity')
    Severity: Critical
    Found in modules/RecycleBin/models/Module.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.

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

                App\User::setCurrentUserId($userId);
    Severity: Critical
    Found in modules/RecycleBin/models/Module.php by phan

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

                $dataReader = (new \App\Db\Query())->select(['crmid', 'setype'])->from('vtiger_crmentity')
    Severity: Critical
    Found in modules/RecycleBin/models/Module.php by phan

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

                App\User::setCurrentUserId($actualUserId);
    Severity: Critical
    Found in modules/RecycleBin/models/Module.php by phan

    Call to method error from undeclared class \App\Log
    Open

                \App\Log::error($ex->__toString());
    Severity: Critical
    Found in modules/RecycleBin/models/Module.php by phan

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

                App\User::setCurrentUserId($actualUserId);
    Severity: Critical
    Found in modules/RecycleBin/models/Module.php by phan

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

            $actualUserId = App\User::getCurrentUserId();
    Severity: Critical
    Found in modules/RecycleBin/models/Module.php by phan

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

                if (!App\User::isExists($userId)) {
    Severity: Critical
    Found in modules/RecycleBin/models/Module.php by phan

    Saw an @param annotation for recordsToDelete, but it was not found in the param list of function deleteAllRecords(string $untilModifiedTime, int $userId)
    Open

         * @param int[]  $recordsToDelete
    Severity: Info
    Found in modules/RecycleBin/models/Module.php by phan

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

    class RecycleBin_Module_Model extends Vtiger_Module_Model

    The class RecycleBin_Module_Model is not named in CamelCase.
    Open

    class RecycleBin_Module_Model extends Vtiger_Module_Model
    {
        /**
         * Function to get all available modules for list.
         *
    Severity: Minor
    Found in modules/RecycleBin/models/Module.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

    Only one argument is allowed per line in a multi-line function call
    Open

                            ['<=', 'modifiedtime', $untilModifiedTime], ])

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

        public function isQuickSearchEnabled(): bool

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

    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

            return false;

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

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

            return \vtlib\Functions::getAllModules(true, false, 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

                $dataReader = (new \App\Db\Query())->select(['crmid', 'setype'])->from('vtiger_crmentity')

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

                    $recordModel->delete();

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

                    --$deleteMaxCount;

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

                App\User::setCurrentUserId($actualUserId);

    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 isAdvSortEnabled(): bool

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

        {

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

            try {

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

                $modulesList = \vtlib\Functions::getAllModules(true, false, 0);

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

                        continue;

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

                \App\Log::error($ex->__toString());

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

                    throw new \App\Exceptions\NoPermitted('ERR_PERMISSION_DENIED', 406);

    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

                            ['<=', 'modifiedtime', $untilModifiedTime], ])

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

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

        public function isCustomViewAdvCondEnabled(): bool

    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

                if (!App\User::isExists($userId)) {

    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

         * @param int[]  $recordsToDelete

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

            $actualUserId = App\User::getCurrentUserId();

    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

         * @throws \App\Exceptions\NoPermitted

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

        public static function deleteAllRecords(string $untilModifiedTime, int $userId)

    Line exceeds 120 characters; contains 152 characters
    Open

                        (new App\BatchMethod(['method' => 'RecycleBin_Module_Model::deleteAllRecords', 'params' => [$untilModifiedTime, $userId]]))->save();

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

         * Function to get all available modules for list.

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

                            ['vtiger_crmentity.deleted' => 1],

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

            } catch (\Throwable $ex) {

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

                App\User::setCurrentUserId($actualUserId);

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

        }

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

         * Delete all records from recycle to given date and module.

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

         * @param string $untilModifiedTime

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

        {

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

                        (new App\BatchMethod(['method' => 'RecycleBin_Module_Model::deleteAllRecords', 'params' => [$untilModifiedTime, $userId]]))->save();

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

                    unset($recordModel);

    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

                    if (0 >= $deleteMaxCount) {

    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

                $deleteMaxCount = App\Config::module('RecycleBin', 'DELETE_MAX_COUNT');

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

            return false;

    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

                    ->createCommand()->query();

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

                        break;

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

                    if (!$recordModel->privilegeToDelete()) {

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

                        ['and',

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

                App\User::setCurrentUserId($userId);

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

                            ['in', 'setype', array_column($modulesList, 'name')],

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

                    $recordModel = Vtiger_Record_Model::getInstanceById($row['crmid'], $row['setype']);

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

                }

    Multi-line function call not indented correctly; expected 16 spaces but found 24
    Open

                            ['<=', 'modifiedtime', $untilModifiedTime], ])

    Closing parenthesis of a multi-line function call must be on a line by itself
    Open

                            ['<=', 'modifiedtime', $untilModifiedTime], ])

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

    class RecycleBin_Module_Model extends Vtiger_Module_Model

    There are no issues that match your filters.

    Category
    Status