YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/models/ExportToCsv.php

Summary

Maintainability
A
2 hrs
Test Coverage
F
0%

Function getEntries has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    public function getEntries(): array
    {
        $entries = [];
        $addInventoryData = $this->fullData && $this->moduleInstance->isInventory();
        if ($addInventoryData) {
Severity: Minor
Found in modules/Vtiger/models/ExportToCsv.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

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

    public function getEntries(): array
    {
        $entries = [];
        $addInventoryData = $this->fullData && $this->moduleInstance->isInventory();
        if ($addInventoryData) {
Severity: Minor
Found in modules/Vtiger/models/ExportToCsv.php - About 1 hr to fix

    Missing class import via use statement (line '52', column '18').
    Open

                    $rows = (new \App\Db\Query())->from($inventoryTable)->where(['crmid' => $row['id']])->orderBy('seq')->all();
    Severity: Minor
    Found in modules/Vtiger/models/ExportToCsv.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 'Vtiger_Inventory_Model' in method 'getEntries'.
    Open

                $inventoryModel = Vtiger_Inventory_Model::getInstance($this->moduleName);
    Severity: Minor
    Found in modules/Vtiger/models/ExportToCsv.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

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

                    } else {
                        $entries[] = $sanitizedRow;
                    }
    Severity: Minor
    Found in modules/Vtiger/models/ExportToCsv.php by phpmd

    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

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

                } else {
                    $entries[] = $sanitizedRow;
                }
    Severity: Minor
    Found in modules/Vtiger/models/ExportToCsv.php by phpmd

    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

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

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

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

                    $rows = (new \App\Db\Query())->from($inventoryTable)->where(['crmid' => $row['id']])->orderBy('seq')->all();
    Severity: Critical
    Found in modules/Vtiger/models/ExportToCsv.php by phan

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

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

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

                            $sanitizedInventoryRow = $this->sanitizeInventoryValues($row, $inventoryFields);
    Severity: Minor
    Found in modules/Vtiger/models/ExportToCsv.php by phpmd

    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_ExportToCsv_Model extends \App\Export\Records

    The class Vtiger_ExportToCsv_Model is not named in CamelCase.
    Open

    class Vtiger_ExportToCsv_Model extends \App\Export\Records
    {
        /** @var string File extension. */
        protected $fileExtension = 'csv';
    
    
    Severity: Minor
    Found in modules/Vtiger/models/ExportToCsv.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

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

        /** @var string File extension. */

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

            $rowsCounter = 0;

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

                        $entries[] = $sanitizedRow;

    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

            return $entries;

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

         * Function that create the exported file.

    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 exports the data based on the mode.

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

            $this->output($this->getHeaders(), $this->getEntries());

    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

            $output = fopen('php://output', 'w');

    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 $entries - output file data

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

            fputcsv($output, $headers);

    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 = $this->getExportQuery()->createCommand()->query();

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

                if ($addInventoryData) {

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

                    $sanitizedRow[] = $rowsCounter++;

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

                        foreach ($rows as &$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

        /**

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

         *

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

                fputcsv($output, $row);

    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

                $inventoryFields = $inventoryModel->getFields();

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

        /**

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

                $inventoryTable = $inventoryModel->getDataTableName();

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

                    if ($rows) {

    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 getEntries(): array

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

                    $entries[] = $sanitizedRow;

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

        public function output(array $headers, array $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

         * Get entires.

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

         */

    Line exceeds 120 characters; contains 124 characters
    Open

                    $rows = (new \App\Db\Query())->from($inventoryTable)->where(['crmid' => $row['id']])->orderBy('seq')->all();

    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

        protected $fileExtension = 'csv';

    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

            if ($addInventoryData) {

    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

         * @param array $headers - output file header

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

            fclose($output);

    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

                    $rows = (new \App\Db\Query())->from($inventoryTable)->where(['crmid' => $row['id']])->orderBy('seq')->all();

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

                $inventoryModel = Vtiger_Inventory_Model::getInstance($this->moduleName);

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

                            $sanitizedInventoryRow = $this->sanitizeInventoryValues($row, $inventoryFields);

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

        {

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

            $addInventoryData = $this->fullData && $this->moduleInstance->isInventory();

    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

                            $entries[] = array_merge($sanitizedRow, $sanitizedInventoryRow);

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

                $sanitizedRow = $this->sanitizeValues($row);

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

        {

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

            foreach ($entries as $row) {

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

    class Vtiger_ExportToCsv_Model extends \App\Export\Records

    There are no issues that match your filters.

    Category
    Status