imagecms/ImageCMS

View on GitHub
application/modules/sitemap/sitemap.php

Summary

Maintainability
F
4 days
Test Coverage

File sitemap.php has 476 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

use CMSFactory\Events;
use core\models\Route;
use core\src\CoreFactory;
Severity: Minor
Found in application/modules/sitemap/sitemap.php - About 7 hrs to fix

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

    public function not_blocked_url($url) {

        if (!in_array($url, $this->blocked_urls) && !in_array(substr($url, 0, -1), $this->blocked_urls)) {
            foreach ($this->blocked_urls as $blocked_url) {
                $url = str_replace(site_url(), '', $url);
Severity: Minor
Found in application/modules/sitemap/sitemap.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

Sitemap has 23 functions (exceeds 20 allowed). Consider refactoring.
Open

class Sitemap extends MY_Controller
{

    /**
     * Blocked urls array
Severity: Minor
Found in application/modules/sitemap/sitemap.php - About 2 hrs to fix

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

    private function getPagesCategories() {

        // Add categories to sitemap urls.
        $categories = $this->lib_category->unsorted();

Severity: Minor
Found in application/modules/sitemap/sitemap.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 getShopCategories has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    private function getShopCategories() {

        // Get Shop Categories
        $shop_categories = $this->sitemap_model->get_shop_categories();

Severity: Minor
Found in application/modules/sitemap/sitemap.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 generate_xml has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    private function generate_xml(array $items = []) {

        $data = '';

        $site_maps = [];
Severity: Minor
Found in application/modules/sitemap/sitemap.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 getPagesCategories has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function getPagesCategories() {

        // Add categories to sitemap urls.
        $categories = $this->lib_category->unsorted();

Severity: Minor
Found in application/modules/sitemap/sitemap.php - About 1 hr to fix

Function sitemap_ul has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    public function sitemap_ul($items = [], $pages_without_category = []) {

        $out = '<ul class="sitemap">';

        foreach ($items as $item) {
Severity: Minor
Found in application/modules/sitemap/sitemap.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 getAllPages has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    private function getAllPages() {

        // Get all pages
        $pages = $this->sitemap_model->get_all_pages();

Severity: Minor
Found in application/modules/sitemap/sitemap.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 getShopProducts has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    private function getShopProducts() {

        // Get Shop products
        $shop_products = $this->sitemap_model->get_shop_products();

Severity: Minor
Found in application/modules/sitemap/sitemap.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 not_blocked_url has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function not_blocked_url($url) {

        if (!in_array($url, $this->blocked_urls) && !in_array(substr($url, 0, -1), $this->blocked_urls)) {
            foreach ($this->blocked_urls as $blocked_url) {
                $url = str_replace(site_url(), '', $url);
Severity: Minor
Found in application/modules/sitemap/sitemap.php - About 1 hr to fix

Method generate_xml has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function generate_xml(array $items = []) {

        $data = '';

        $site_maps = [];
Severity: Minor
Found in application/modules/sitemap/sitemap.php - About 1 hr to fix

Method initialize has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function initialize() {

        // Get sitemap values
        $priorities = $this->sitemap_model->getPriorities();
        $changfreq = $this->sitemap_model->getChangefreq();
Severity: Minor
Found in application/modules/sitemap/sitemap.php - About 1 hr to fix

Method getAllPages has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function getAllPages() {

        // Get all pages
        $pages = $this->sitemap_model->get_all_pages();

Severity: Minor
Found in application/modules/sitemap/sitemap.php - About 1 hr to fix

Method getShopCategories has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function getShopCategories() {

        // Get Shop Categories
        $shop_categories = $this->sitemap_model->get_shop_categories();

Severity: Minor
Found in application/modules/sitemap/sitemap.php - About 1 hr to fix

Method ping_google has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function ping_google() {

        // Checking is used server is local

        $ci = &get_instance();
Severity: Minor
Found in application/modules/sitemap/sitemap.php - About 1 hr to fix

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

    public function build_xml_map($regenerate = FALSE) {

        $settings = $this->sitemap_model->load_settings();

        // Generate new or use saved map
Severity: Minor
Found in application/modules/sitemap/sitemap.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 getShopBrands has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    private function getShopBrands() {

        // Get Shop Brands
        $shop_brands = $this->sitemap_model->get_shop_brands();

Severity: Minor
Found in application/modules/sitemap/sitemap.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 _create_map has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function _create_map() {

        if ($this->robotsCheck()) {
            $this->initialize();

Severity: Minor
Found in application/modules/sitemap/sitemap.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

        if ($changfreq) {
            $this->main_page_changefreq = $changfreq['main_page_changefreq'];
            $this->categories_changefreq = $changfreq['categories_changefreq'];
            $this->products_categories_changefreq = $changfreq['products_categories_changefreq'];
            $this->products_sub_categories_changefreq = $changfreq['products_sub_categories_changefreq'];
Severity: Major
Found in application/modules/sitemap/sitemap.php and 1 other location - About 1 hr to fix
application/modules/sitemap/sitemap.php on lines 278..287

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

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

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

        if ($priorities) {
            $this->main_page_priority = $priorities['main_page_priority'];
            $this->cats_priority = $priorities['cats_priority'];
            $this->pages_priority = $priorities['pages_priority'];
            $this->sub_cats_priority = $priorities['sub_cats_priority'];
Severity: Major
Found in application/modules/sitemap/sitemap.php and 1 other location - About 1 hr to fix
application/modules/sitemap/sitemap.php on lines 290..299

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

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

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

                if ($this->not_blocked_url($localeSegment . Route::createRouteUrl($shopprod['url'], $shopprod['parent_url'], Route::TYPE_PRODUCT))) {

                    if ($shopprod['updated'] > 0) {
                        $date = date('Y-m-d', $shopprod['updated']);
                    } else {
Severity: Minor
Found in application/modules/sitemap/sitemap.php and 1 other location - About 45 mins to fix
application/modules/sitemap/sitemap.php on lines 541..555

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

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

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

            if ($this->not_blocked_url($localeSegment . 'shop/brand/' . $shopbr['url'])) {
                // create date
                if ($shopbr['updated'] > 0) {
                    $date = date('Y-m-d', $shopbr['updated']);
                } else {
Severity: Minor
Found in application/modules/sitemap/sitemap.php and 1 other location - About 45 mins to fix
application/modules/sitemap/sitemap.php on lines 574..588

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

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