YetiForceCompany/YetiForceCRM

View on GitHub
modules/Users/actions/ExportData.php

Summary

Maintainability
B
4 hrs
Test Coverage
F
0%

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

    public function setDataFromRequest(App\Request $request)
    {
        $searchParams = \App\Condition::validSearchParams($this->moduelName, $request->getArray('search_params'));
        $operator = $request->isEmpty('operator') ? '' : $request->getByType('operator');
        if ($operator && $searchValue = \App\Condition::validSearchValue($request->getByType('search_value', \App\Purifier::TEXT), $this->moduelName, $request->getByType('search_key', \App\Purifier::ALNUM), $operator)) {
Severity: Minor
Found in modules/Users/actions/ExportData.php - About 1 hr to fix

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

        public function setDataFromRequest(App\Request $request)
        {
            $searchParams = \App\Condition::validSearchParams($this->moduelName, $request->getArray('search_params'));
            $operator = $request->isEmpty('operator') ? '' : $request->getByType('operator');
            if ($operator && $searchValue = \App\Condition::validSearchValue($request->getByType('search_value', \App\Purifier::TEXT), $this->moduelName, $request->getByType('search_key', \App\Purifier::ALNUM), $operator)) {
    Severity: Minor
    Found in modules/Users/actions/ExportData.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

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

        public function setDataFromRequest(App\Request $request)
        {
            $searchParams = \App\Condition::validSearchParams($this->moduelName, $request->getArray('search_params'));
            $operator = $request->isEmpty('operator') ? '' : $request->getByType('operator');
            if ($operator && $searchValue = \App\Condition::validSearchValue($request->getByType('search_value', \App\Purifier::TEXT), $this->moduelName, $request->getByType('search_key', \App\Purifier::ALNUM), $operator)) {
    Severity: Minor
    Found in modules/Users/actions/ExportData.php by phpmd

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

                throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);
    Severity: Minor
    Found in modules/Users/actions/ExportData.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 '67', column '16').
    Open

                        throw new \App\Exceptions\IllegalValue('ERR_FIELD_NOT_FOUND||mode');
    Severity: Minor
    Found in modules/Users/actions/ExportData.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\Config' in method 'process'.
    Open

                ->setLimit(\App\Config::performance('MAX_NUMBER_EXPORT_RECORDS'))
    Severity: Minor
    Found in modules/Users/actions/ExportData.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 assigning values to variables in if clauses and the like (line '59', column '10').
    Open

        public function setDataFromRequest(App\Request $request)
        {
            $searchParams = \App\Condition::validSearchParams($this->moduelName, $request->getArray('search_params'));
            $operator = $request->isEmpty('operator') ? '' : $request->getByType('operator');
            if ($operator && $searchValue = \App\Condition::validSearchValue($request->getByType('search_value', \App\Purifier::TEXT), $this->moduelName, $request->getByType('search_key', \App\Purifier::ALNUM), $operator)) {
    Severity: Minor
    Found in modules/Users/actions/ExportData.php by phpmd

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

            $searchParams = \App\Condition::validSearchParams($this->moduelName, $request->getArray('search_params'));
    Severity: Minor
    Found in modules/Users/actions/ExportData.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\Condition' in method 'setDataFromRequest'.
    Open

            if ($operator && $searchValue = \App\Condition::validSearchValue($request->getByType('search_value', \App\Purifier::TEXT), $this->moduelName, $request->getByType('search_key', \App\Purifier::ALNUM), $operator)) {
    Severity: Minor
    Found in modules/Users/actions/ExportData.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 assigning values to variables in if clauses and the like (line '43', column '20').
    Open

        public function setDataFromRequest(App\Request $request)
        {
            $searchParams = \App\Condition::validSearchParams($this->moduelName, $request->getArray('search_params'));
            $operator = $request->isEmpty('operator') ? '' : $request->getByType('operator');
            if ($operator && $searchValue = \App\Condition::validSearchValue($request->getByType('search_value', \App\Purifier::TEXT), $this->moduelName, $request->getByType('search_key', \App\Purifier::ALNUM), $operator)) {
    Severity: Minor
    Found in modules/Users/actions/ExportData.php by phpmd

    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

    Call to method exportData from undeclared class \App\Export\ExportRecords
    Open

            $this->exportModel->exportData();
    Severity: Critical
    Found in modules/Users/actions/ExportData.php by phan

    Reference to instance property fullData from undeclared class \App\Export\ExportRecords
    Open

            $this->exportModel->fullData = true;
    Severity: Minor
    Found in modules/Users/actions/ExportData.php by phan

    Call to method getQueryGenerator from undeclared class \App\Export\ExportRecords
    Open

            $queryGenerator = $this->exportModel->getQueryGenerator();
    Severity: Critical
    Found in modules/Users/actions/ExportData.php by phan

    Call to method sendHttpHeader from undeclared class \App\Export\ExportRecords
    Open

            $this->exportModel->sendHttpHeader();
    Severity: Critical
    Found in modules/Users/actions/ExportData.php by phan

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

            if (!\App\User::getCurrentUserModel()->isAdmin()) {
    Severity: Critical
    Found in modules/Users/actions/ExportData.php by phan

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

                    case 'ExportSelectedRecords':
                        $selectedIds = $request->getArray('selected_ids', \App\Purifier::ALNUM);
                        if ($selectedIds && 'all' !== $selectedIds[0]) {
                            $queryGenerator->addCondition('id', $selectedIds, 'e');
                        }
    Severity: Major
    Found in modules/Users/actions/ExportData.php and 1 other location - About 2 hrs to fix
    modules/Vtiger/actions/ExportData.php on lines 102..114

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 135.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

    class Users_ExportData_Action extends Vtiger_ExportData_Action

    The class Users_ExportData_Action is not named in CamelCase.
    Open

    class Users_ExportData_Action extends Vtiger_ExportData_Action
    {
        /** {@inheritdoc} */
        public function checkPermission(App\Request $request)
        {
    Severity: Minor
    Found in modules/Users/actions/ExportData.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

    Terminating statement must be indented to the same level as the CASE body
    Open

                        break;

    Terminating statement must be indented to the same level as the CASE body
    Open

                        throw new \App\Exceptions\IllegalValue('ERR_FIELD_NOT_FOUND||mode');

    Terminating statement must be indented to the same level as the CASE body
    Open

                        break;

    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

            $this->exportModel = \App\Export\Records::getInstance($this->moduelName, 'csv')

    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

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

    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

                        }

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

    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->moduelName, $request->getByType('search_key', \App\Purifier::ALNUM), $operator)) {

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

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

    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 process(App\Request $request)

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

                        if ($operator && $searchValue && $searchKey) {

    Line exceeds 120 characters; contains 220 characters
    Open

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

    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

                        if ($selectedIds && 'all' !== $selectedIds[0]) {

    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

                        throw new \App\Exceptions\IllegalValue('ERR_FIELD_NOT_FOUND||mode');

    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

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

            $operator = $request->isEmpty('operator') ? '' : $request->getByType('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

            $queryGenerator->addCondition('status', 'Active', 'e');

    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

                        $queryGenerator->parseAdvFilter($queryGenerator->parseBaseSearchParamsToCondition($searchParams));

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

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

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

            if (!\App\User::getCurrentUserModel()->isAdmin()) {

    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 setDataFromRequest(App\Request $request)

    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

                        }

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

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

    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

                            $queryGenerator->addCondition($searchKey, $searchValue, $operator);

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

            $this->exportModel->fullData = true;

    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 checkPermission(App\Request $request)

    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

                $searchKey = $request->getByType('search_key', \App\Purifier::ALNUM);

    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

            switch ($request->getMode()) {

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

                    default:

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

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

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

                    case 'ExportAllData':

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

                    case 'ExportSelectedRecords':

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

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

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

    class Users_ExportData_Action extends Vtiger_ExportData_Action

    Line indented incorrectly; expected 16 spaces, found 20
    Open

                        if ($operator && $searchValue && $searchKey) {

    Line indented incorrectly; expected 16 spaces, found 20
    Open

                        if ($selectedIds && 'all' !== $selectedIds[0]) {

    Closing brace indented incorrectly; expected 8 spaces, found 12
    Open

                }

    Line indented incorrectly; expected 16 spaces, found 20
    Open

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

    Line indented incorrectly; expected 16 spaces, found 20
    Open

                        }

    Line indented incorrectly; expected 16 spaces, found 20
    Open

                        }

    Line indented incorrectly; expected 8 spaces, found 12
    Open

                }

    Line indented incorrectly; expected 12 spaces, found 16
    Open

                    case 'ExportAllData':

    Line indented incorrectly; expected 16 spaces, found 20
    Open

                        }

    Line indented incorrectly; expected 12 spaces, found 16
    Open

                    case 'ExportSelectedRecords':

    Line indented incorrectly; expected 12 spaces, found 16
    Open

                    default:

    There are no issues that match your filters.

    Category
    Status