YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/actions/QuickExportData.php

Summary

Maintainability
A
2 hrs
Test Coverage
F
0%

Method setDataFromRequest has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function setDataFromRequest(App\Request $request)
    {
        if ($request->has('xmlExportType')) {
            $this->exportModel->setTemplate($request->getByType('xmlExportType', 'Text'));
        }
Severity: Minor
Found in modules/Vtiger/actions/QuickExportData.php - About 1 hr to fix

    Function setDataFromRequest has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        public function setDataFromRequest(App\Request $request)
        {
            if ($request->has('xmlExportType')) {
                $this->exportModel->setTemplate($request->getByType('xmlExportType', 'Text'));
            }
    Severity: Minor
    Found in modules/Vtiger/actions/QuickExportData.php - About 1 hr 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

    The method setDataFromRequest() has an NPath complexity of 1728. The configured NPath complexity threshold is 200.
    Open

        public function setDataFromRequest(App\Request $request)
        {
            if ($request->has('xmlExportType')) {
                $this->exportModel->setTemplate($request->getByType('xmlExportType', 'Text'));
            }

    NPathComplexity

    Since: 0.1

    The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

    Example

    class Foo {
        function bar() {
            // lots of complicated code
        }
    }

    Source https://phpmd.org/rules/codesize.html#npathcomplexity

    The method setDataFromRequest() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
    Open

        public function setDataFromRequest(App\Request $request)
        {
            if ($request->has('xmlExportType')) {
                $this->exportModel->setTemplate($request->getByType('xmlExportType', 'Text'));
            }

    CyclomaticComplexity

    Since: 0.1

    Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

    Example

    // Cyclomatic Complexity = 11
    class Foo {
    1   public function example() {
    2       if ($a == $b) {
    3           if ($a1 == $b1) {
                    fiddle();
    4           } elseif ($a2 == $b2) {
                    fiddle();
                } else {
                    fiddle();
                }
    5       } elseif ($c == $d) {
    6           while ($c == $d) {
                    fiddle();
                }
    7        } elseif ($e == $f) {
    8           for ($n = 0; $n < $h; $n++) {
                    fiddle();
                }
            } else {
                switch ($z) {
    9               case 1:
                        fiddle();
                        break;
    10              case 2:
                        fiddle();
                        break;
    11              case 3:
                        fiddle();
                        break;
                    default:
                        fiddle();
                        break;
                }
            }
        }
    }

    Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

    Missing class import via use statement (line '29', column '14').
    Open

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

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

            $searchParams = \App\Condition::validSearchParams($this->moduleName, $request->getArray('search_params'));

    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 assigning values to variables in if clauses and the like (line '66', column '7').
    Open

        public function setDataFromRequest(App\Request $request)
        {
            if ($request->has('xmlExportType')) {
                $this->exportModel->setTemplate($request->getByType('xmlExportType', 'Text'));
            }

    IfStatementAssignment

    Since: 2.7.0

    Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($foo = 'bar') { // possible typo
                // ...
            }
            if ($baz = 0) { // always false
                // ...
            }
        }
    }

    Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

    Avoid using static access to class '\App\Config' in method 'process'.
    Open

                ->setLimit(\App\Config::performance('MAX_NUMBER_EXPORT_RECORDS'))

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

            if ($operator && $searchValue = \App\Condition::validSearchValue($request->getByType('search_value', \App\Purifier::TEXT), $this->moduleName, $request->getByType('search_key', \App\Purifier::ALNUM), $operator)) {

    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 assigning values to variables in if clauses and the like (line '75', column '20').
    Open

        public function setDataFromRequest(App\Request $request)
        {
            if ($request->has('xmlExportType')) {
                $this->exportModel->setTemplate($request->getByType('xmlExportType', 'Text'));
            }

    IfStatementAssignment

    Since: 2.7.0

    Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($foo = 'bar') { // possible typo
                // ...
            }
            if ($baz = 0) { // always false
                // ...
            }
        }
    }

    Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

    Avoid using static access to class 'Users_Privileges_Model' in method 'checkPermission'.
    Open

            $currentUserPriviligesModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();

    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 assigning values to variables in if clauses and the like (line '80', column '7').
    Open

        public function setDataFromRequest(App\Request $request)
        {
            if ($request->has('xmlExportType')) {
                $this->exportModel->setTemplate($request->getByType('xmlExportType', 'Text'));
            }

    IfStatementAssignment

    Since: 2.7.0

    Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($foo = 'bar') { // possible typo
                // ...
            }
            if ($baz = 0) { // always false
                // ...
            }
        }
    }

    Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

    Avoid assigning values to variables in if clauses and the like (line '84', column '52').
    Open

        public function setDataFromRequest(App\Request $request)
        {
            if ($request->has('xmlExportType')) {
                $this->exportModel->setTemplate($request->getByType('xmlExportType', 'Text'));
            }

    IfStatementAssignment

    Since: 2.7.0

    Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($foo = 'bar') { // possible typo
                // ...
            }
            if ($baz = 0) { // always false
                // ...
            }
        }
    }

    Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

    The method setDataFromRequest uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $this->exportModel->loadFieldsFromCvId($cvId);
            }

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

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

    Avoid using static access to class '\App\Condition' in method 'setDataFromRequest'.
    Open

                $queryGenerator->setAdvancedConditions(\App\Condition::validAdvancedConditions($advancedConditions));

    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

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

                $queryGenerator->parseAdvFilter($transformedSearchParams);
    Severity: Critical
    Found in modules/Vtiger/actions/QuickExportData.php by phan

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

            $queryGenerator->initForCustomViewById($cvId);
    Severity: Critical
    Found in modules/Vtiger/actions/QuickExportData.php by phan

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

                $queryGenerator->addCondition($request->getByType('search_key', \App\Purifier::ALNUM), $searchValue, $operator);
    Severity: Critical
    Found in modules/Vtiger/actions/QuickExportData.php by phan

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

                $queryGenerator->addCondition('id', $excludedIds, 'n');
    Severity: Critical
    Found in modules/Vtiger/actions/QuickExportData.php by phan

    Call to undeclared method \App\Export\Records::setTemplate
    Open

                $this->exportModel->setTemplate($request->getByType('xmlExportType', 'Text'));
    Severity: Critical
    Found in modules/Vtiger/actions/QuickExportData.php by phan

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

            $queryGenerator->setStateCondition($request->getByType('entityState'));
    Severity: Critical
    Found in modules/Vtiger/actions/QuickExportData.php by phan

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

                $queryGenerator->setAdvancedConditions(\App\Condition::validAdvancedConditions($advancedConditions));
    Severity: Critical
    Found in modules/Vtiger/actions/QuickExportData.php by phan

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

                $transformedSearchParams = $queryGenerator->parseBaseSearchParamsToCondition($searchParams);
    Severity: Critical
    Found in modules/Vtiger/actions/QuickExportData.php by phan

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

                $queryGenerator->addCondition('id', $selectedIds, 'e');
    Severity: Critical
    Found in modules/Vtiger/actions/QuickExportData.php by phan

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

                $transformedSearchParams = $queryGenerator->parseBaseSearchParamsToCondition($searchParams);

    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

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

            $currentUserPriviligesModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();

    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

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

    class Vtiger_QuickExportData_Action extends Vtiger_Mass_Action

    The class Vtiger_QuickExportData_Action is not named in CamelCase.
    Open

    class Vtiger_QuickExportData_Action extends Vtiger_Mass_Action
    {
        /** @var string Module name */
        protected $moduleName;
        /** @var \App\Export\Records Export model instance */

    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->addCondition('id', $selectedIds, 'e');

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

        public function checkPermission(App\Request $request)

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

            if ($selectedIds && 'all' !== $selectedIds[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

            if ($searchParams) {

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

            }

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

        protected $exportModel;

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

        }

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

         * Set condition data in export model.

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

            $currentUserPriviligesModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();

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

            }

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

                ->setLimit(\App\Config::performance('MAX_NUMBER_EXPORT_RECORDS'))

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

            $searchParams = \App\Condition::validSearchParams($this->moduleName, $request->getArray('search_params'));

    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

            $queryGenerator = $this->exportModel->getQueryGenerator();

    Line exceeds 120 characters; contains 124 characters
    Open

                $queryGenerator->addCondition($request->getByType('search_key', \App\Purifier::ALNUM), $searchValue, $operator);

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

        /** @var \App\Export\Records Export model instance */

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

            if (!$currentUserPriviligesModel->hasModuleActionPermission($this->moduleName, 'QuickExportToExcel')) {

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

         */

    Line exceeds 120 characters; contains 220 characters
    Open

            if ($operator && $searchValue = \App\Condition::validSearchValue($request->getByType('search_value', \App\Purifier::TEXT), $this->moduleName, $request->getByType('search_key', \App\Purifier::ALNUM), $operator)) {

    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 ($request->has('xmlExportType')) {

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

            $cvId = $request->getInteger('viewname');

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

                $queryGenerator->setAdvancedConditions(\App\Condition::validAdvancedConditions($advancedConditions));

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

            if ($excludedIds = $request->getArray('excluded_ids', \App\Purifier::INTEGER)) {

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

            if ($advancedConditions = $request->has('advancedConditions') ? $request->getArray('advancedConditions') : []) {

    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

                $this->exportModel->setFields($fields);

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

            $this->exportModel->exportData();

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

            $selectedIds = $request->getArray('selected_ids', \App\Purifier::ALNUM);

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

            $operator = $request->isEmpty('operator') ? '' : $request->getByType('operator');

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

            $queryGenerator->setStateCondition($request->getByType('entityState'));

    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 void

    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

            $this->moduleName = $request->getModule();

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

                throw new \App\Exceptions\NoPermitted('LBL_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

            } else {

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

        public function process(App\Request $request)

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

         * @param App\Request $request

    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

            $this->exportModel = \App\Export\Records::getInstance($this->moduleName, $request->getByType('export_type', \App\Purifier::ALNUM))

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

            $queryGenerator->initForCustomViewById($cvId);

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

            if (!$request->isEmpty('exportColumns', true) && $fields = $request->getArray('exportColumns', \App\Purifier::TEXT)) {

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

        /** {@inheritdoc} */

    Line exceeds 120 characters; contains 138 characters
    Open

            $this->exportModel = \App\Export\Records::getInstance($this->moduleName, $request->getByType('export_type', \App\Purifier::ALNUM))

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

                ->setFormat(\App\Export\Records::USER_FORMAT);

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

            }

    Line exceeds 120 characters; contains 126 characters
    Open

            if (!$request->isEmpty('exportColumns', true) && $fields = $request->getArray('exportColumns', \App\Purifier::TEXT)) {

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

                $this->exportModel->loadFieldsFromCvId($cvId);

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

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

                $queryGenerator->parseAdvFilter($transformedSearchParams);

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

            if ($operator && $searchValue = \App\Condition::validSearchValue($request->getByType('search_value', \App\Purifier::TEXT), $this->moduleName, $request->getByType('search_key', \App\Purifier::ALNUM), $operator)) {

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

                $queryGenerator->addCondition('id', $excludedIds, 'n');

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

            $this->exportModel->sendHttpHeader();

    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->exportModel->setTemplate($request->getByType('xmlExportType', 'Text'));

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

                $transformedSearchParams = $queryGenerator->parseBaseSearchParamsToCondition($searchParams);

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

                $queryGenerator->addCondition($request->getByType('search_key', \App\Purifier::ALNUM), $searchValue, $operator);

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

    class Vtiger_QuickExportData_Action extends Vtiger_Mass_Action

    There are no issues that match your filters.

    Category
    Status