imagecms/ImageCMS

View on GitHub
application/modules/import_export/classes/Export.php

Summary

Maintainability
F
6 days
Test Coverage

File Export.php has 550 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/**
 * Клас призначений для експорту даних в файл форматів: csv,xlsx,xls.
 * Також передбачена можливість вигрузки основних та додаткових зображень в ZIP-архів
Severity: Major
Found in application/modules/import_export/classes/Export.php - About 1 day to fix

Function addToArchive has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

    public function addToArchive($arr) {
        $zip = new \ZipArchive();
        $date = date('m_d_y');
        $time = date('G_i_s');
        $zipName = 'archive_' . $date . '_' . $time . '.zip';
Severity: Minor
Found in application/modules/import_export/classes/Export.php - About 3 hrs 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

Function getAddCatFullIds has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

    private function getAddCatFullIds($prodIds) {

        if (count($prodIds)) {
            $catIds = [];
            $cats = [];
Severity: Minor
Found in application/modules/import_export/classes/Export.php - About 2 hrs 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

Export has 24 functions (exceeds 20 allowed). Consider refactoring.
Open

class Export
{

    public $delimiter = ';';

Severity: Minor
Found in application/modules/import_export/classes/Export.php - About 2 hrs to fix

Function getDataFromBase has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    protected function getDataFromBase() {
        $query = $this->createQuery();
        $result = $this->db->query($query);
        $list = [];
        $prodIds = [];
Severity: Minor
Found in application/modules/import_export/classes/Export.php - About 2 hrs 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

Function getAddCategories has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    private function getAddCategories($prodIds) {
        if (!isset($prodIds)) {
            return [];
        }
        $catIds = [];
Severity: Minor
Found in application/modules/import_export/classes/Export.php - About 2 hrs 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 createQuery has 60 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function createQuery() {
        $fieldsArray = []; // tables and fields
        $fields = '';
        $joins = '';
        foreach ($this->completeFields as $field) {
Severity: Major
Found in application/modules/import_export/classes/Export.php - About 2 hrs to fix

Function __construct has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    public function __construct(array $settings = []) {
        $ci = &get_instance();
        $this->db = $ci->db;

        if (count($settings) > 0) {
Severity: Minor
Found in application/modules/import_export/classes/Export.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

Function createQuery has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    protected function createQuery() {
        $fieldsArray = []; // tables and fields
        $fields = '';
        $joins = '';
        foreach ($this->completeFields as $field) {
Severity: Minor
Found in application/modules/import_export/classes/Export.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 __construct has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function __construct(array $settings = []) {
        $ci = &get_instance();
        $this->db = $ci->db;

        if (count($settings) > 0) {
Severity: Minor
Found in application/modules/import_export/classes/Export.php - About 1 hr to fix

Method getAbbreviation has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function getAbbreviation($field = NULL) {
        $abbreviationsArray = [
                               'name'    => '`shop_products_i18n`.`name` as product_name', //
                               'url'     => '`route`.`url` as url', //
                               'oldprc'  => 'old_price', //
Severity: Minor
Found in application/modules/import_export/classes/Export.php - About 1 hr to fix

Method addToArchive has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function addToArchive($arr) {
        $zip = new \ZipArchive();
        $date = date('m_d_y');
        $time = date('G_i_s');
        $zipName = 'archive_' . $date . '_' . $time . '.zip';
Severity: Minor
Found in application/modules/import_export/classes/Export.php - About 1 hr to fix

Method getAddCategories has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function getAddCategories($prodIds) {
        if (!isset($prodIds)) {
            return [];
        }
        $catIds = [];
Severity: Minor
Found in application/modules/import_export/classes/Export.php - About 1 hr to fix

Method getDataFromBase has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function getDataFromBase() {
        $query = $this->createQuery();
        $result = $this->db->query($query);
        $list = [];
        $prodIds = [];
Severity: Minor
Found in application/modules/import_export/classes/Export.php - About 1 hr to fix

Method saveToExcelFile has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function saveToExcelFile($pathToFile, $type = 'Excel5') {
        switch ($type) {
            case 'Excel5':
                $path = $pathToFile . 'products.xls';
                break;
Severity: Minor
Found in application/modules/import_export/classes/Export.php - About 1 hr to fix

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

    private function getAddCatFullIds($prodIds) {

        if (count($prodIds)) {
            $catIds = [];
            $cats = [];
Severity: Minor
Found in application/modules/import_export/classes/Export.php - About 1 hr to fix

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

    public function saveToExcelFile($pathToFile, $type = 'Excel5') {
        switch ($type) {
            case 'Excel5':
                $path = $pathToFile . 'products.xls';
                break;
Severity: Minor
Found in application/modules/import_export/classes/Export.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 getCategoriesFromBase has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function getCategoriesFromBase() {
        $query = "
            SELECT 
                `shop_category`.`id`, 
                `shop_category`.`parent_id`, 
Severity: Minor
Found in application/modules/import_export/classes/Export.php - About 1 hr to fix

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

    protected function getAbbreviation($field = NULL) {
        $abbreviationsArray = [
                               'name'    => '`shop_products_i18n`.`name` as product_name', //
                               'url'     => '`route`.`url` as url', //
                               'oldprc'  => 'old_price', //
Severity: Minor
Found in application/modules/import_export/classes/Export.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

Function getCompleteFields has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    protected function getCompleteFields() {
        $abbreviations = $this->getAbbreviation();
        $completeFields = [];

        //a reduction of the field names and field attributes
Severity: Minor
Found in application/modules/import_export/classes/Export.php - About 45 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

Function getDataCsv has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public function getDataCsv() {
        if (!$this->resultString) {
            $fileContents = '';
            $someProductData = current($this->resultArray);
            $headerArray = [];
Severity: Minor
Found in application/modules/import_export/classes/Export.php - About 45 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

Function getFullField has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    protected function getFullField($fieldName) {
        if (preg_match('/^\`[0-9a-zA-Z\_]+\`\.\`[0-9a-zA-Z\_]+\`/i', $fieldName)) {
            return $fieldName;
        } elseif (preg_match('/^[0-9a-zA-Z\_]+$/i', $fieldName)) {
            // тільки поле
Severity: Minor
Found in application/modules/import_export/classes/Export.php - About 35 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

Function getCategoriesPaths has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function getCategoriesPaths() {
        $categoriesPathes = [];
        foreach ($this->categoriesData as $id => $data) {
            if (is_array($data['full_path_ids']) & $data['full_path_ids'] !== FALSE) {
                $pathNames = [];
Severity: Minor
Found in application/modules/import_export/classes/Export.php - About 25 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

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

        $abbreviationsArray = [
                               'name'    => '`shop_products_i18n`.`name` as product_name', //
                               'url'     => '`route`.`url` as url', //
                               'oldprc'  => 'old_price', //
                               'archive' => 'archive', //
Severity: Major
Found in application/modules/import_export/classes/Export.php and 1 other location - About 3 hrs to fix
application/config/user_agents.php on lines 84..113

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 143.

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

There are no issues that match your filters.

Category
Status