imagecms/ImageCMS

View on GitHub
application/modules/comments/commentsapi.php

Summary

Maintainability
F
1 wk
Test Coverage

File commentsapi.php has 526 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

use core\models\Route;
use core\src\CoreFactory;
use CMSFactory\Events;
Severity: Major
Found in application/modules/comments/commentsapi.php - About 1 day to fix

Function newPost has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
Open

    public function newPost() {
        $this->load->model('base');
        $this->_init_settings();

        ($hook = get_hook('comments_on_add')) ? eval($hook) : NULL;
Severity: Minor
Found in application/modules/comments/commentsapi.php - About 5 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 newPost has 121 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function newPost() {
        $this->load->model('base');
        $this->_init_settings();

        ($hook = get_hook('comments_on_add')) ? eval($hook) : NULL;
Severity: Major
Found in application/modules/comments/commentsapi.php - About 4 hrs to fix

Method addPost has 90 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function addPost() {

        $this->setCommentsLocale();
        $this->load->model('base');
        $this->_init_settings();
Severity: Major
Found in application/modules/comments/commentsapi.php - About 3 hrs to fix

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

    public function addPost() {

        $this->setCommentsLocale();
        $this->load->model('base');
        $this->_init_settings();
Severity: Minor
Found in application/modules/comments/commentsapi.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 parsUrl has 57 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function parsUrl($url) {
        $productUrl = parse_url($url);
        $urlArraySegments = explode('/', $productUrl['path']);

        if(!\MY_Controller::isCorporateCMS()) {
Severity: Major
Found in application/modules/comments/commentsapi.php - About 2 hrs to fix

Method renderPosts has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function renderPosts() {
        $this->load->model('base');
        $this->_init_settings();

        $item_id = $this->parsUrl($this->input->server('HTTP_REFERER'));
Severity: Minor
Found in application/modules/comments/commentsapi.php - About 2 hrs to fix

Method renderAsArray has 48 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function renderAsArray($url) {
        $this->load->model('base');
        $this->_init_settings();

        $this->module = $this->getModule($url);
Severity: Minor
Found in application/modules/comments/commentsapi.php - About 1 hr to fix

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

    public function parsUrl($url) {
        $productUrl = parse_url($url);
        $urlArraySegments = explode('/', $productUrl['path']);

        if(!\MY_Controller::isCorporateCMS()) {
Severity: Minor
Found in application/modules/comments/commentsapi.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 getComments has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getComments($url) {
        $this->load->model('base');
        $this->_init_settings();
        $this->module = $this->getModule($url);
        $item_id = $this->parsUrl($url);
Severity: Minor
Found in application/modules/comments/commentsapi.php - About 1 hr to fix

Function renderPosts has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    public function renderPosts() {
        $this->load->model('base');
        $this->_init_settings();

        $item_id = $this->parsUrl($this->input->server('HTTP_REFERER'));
Severity: Minor
Found in application/modules/comments/commentsapi.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 renderAsArray has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    public function renderAsArray($url) {
        $this->load->model('base');
        $this->_init_settings();

        $this->module = $this->getModule($url);
Severity: Minor
Found in application/modules/comments/commentsapi.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 getComments has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public function getComments($url) {
        $this->load->model('base');
        $this->_init_settings();
        $this->module = $this->getModule($url);
        $item_id = $this->parsUrl($url);
Severity: Minor
Found in application/modules/comments/commentsapi.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

Avoid too many return statements within this method.
Open

        return $page->id;
Severity: Major
Found in application/modules/comments/commentsapi.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

        return 'core';
Severity: Major
Found in application/modules/comments/commentsapi.php - About 30 mins to fix

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

    public function getTotalCommentsForProducts($ids, $module = 'shop', $status = 0) {
        if ($ids == null || !$this->db->table_exists('comments')) {
            return;
        }

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

    public function setyes() {
        $comid = $this->input->post('comid');
        if ($this->session->userdata('commentl' . $comid) != 1) {
            $row = $this->db->where('id', $comid)->get('comments')->row();
            $like = $row->like;
Severity: Major
Found in application/modules/comments/commentsapi.php and 1 other location - About 5 hrs to fix
application/modules/comments/commentsapi.php on lines 619..636

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

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

    public function setno() {
        $comid = $this->input->post('comid');
        if ($this->session->userdata('commentl' . $comid) != 1) {
            $row = $this->db->where('id', $comid)->get('comments')->row();
            $disslike = $row->disslike;
Severity: Major
Found in application/modules/comments/commentsapi.php and 1 other location - About 5 hrs to fix
application/modules/comments/commentsapi.php on lines 600..617

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

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

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

        if ($this->dx_auth->is_logged_in() == FALSE) {
            ($hook = get_hook('comments_set_val_rules')) ? eval($hook) : NULL;

            $this->form_validation->set_rules('comment_email', lang('Email', 'comments'), 'trim|required|xss_clean|valid_email');
            $this->form_validation->set_rules('comment_author', lang('Your name', 'comments'), 'trim|required|xss_clean|max_length[50]');
Severity: Major
Found in application/modules/comments/commentsapi.php and 1 other location - About 2 hrs to fix
application/modules/comments/comments.php on lines 356..362

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

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

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

                if (class_exists('SProductsQuery')) {
                    if (SProductsQuery::create()->setComment(__METHOD__)->findPk($item_id) !== null) {
                        $model = SProductsRatingQuery::create()->setComment(__METHOD__)->findPk($item_id);
                        if ($model === null) {
                            $model = new SProductsRating;
Severity: Major
Found in application/modules/comments/commentsapi.php and 1 other location - About 2 hrs to fix
application/modules/comments/comments.php on lines 404..415

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

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

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

            if ($this->dx_auth->is_logged_in() == FALSE) {
                ($hook = get_hook('comments_author_not_logged')) ? eval($hook) : NULL;

                $comment_author = trim(htmlspecialchars($this->input->post('comment_author')));
                $comment_email = trim(htmlspecialchars($this->input->post('comment_email')));
Severity: Major
Found in application/modules/comments/commentsapi.php and 1 other location - About 1 hr to fix
application/modules/comments/comments.php on lines 381..395

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

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