squirrly/squirrly-seo

View on GitHub
models/SQ_Frontend.php

Summary

Maintainability
F
1 wk
Test Coverage

File SQ_Frontend.php has 882 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

class Model_SQ_Frontend {

    /** @var string */
Severity: Major
Found in models/SQ_Frontend.php - About 2 days to fix

    Function grabKeywordsFromPost has a Cognitive Complexity of 76 (exceeds 5 allowed). Consider refactoring.
    Open

        private function grabKeywordsFromPost($id = null) {
            global $wp_query;
    
            $this->max_keywrods = ($this->max_keywrods > 0 ? ($this->max_keywrods - 1) : 0);
            if ($this->max_keywrods == 0)
    Severity: Minor
    Found in models/SQ_Frontend.php - About 1 day 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

    Model_SQ_Frontend has 48 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Model_SQ_Frontend {
    
        /** @var string */
        private $title;
    
    Severity: Minor
    Found in models/SQ_Frontend.php - About 6 hrs to fix

      Function getCanonicalUrl has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
      Open

          function getCanonicalUrl() {
              global $wp_query;
      
              if (!isset($wp_query) || $wp_query->is_404 || $wp_query->is_search) {
                  return false;
      Severity: Minor
      Found in models/SQ_Frontend.php - About 6 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 getCustomDescription has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

          private function getCustomDescription() {
              global $wp_query;
              $sep = '|';
              $description = '';
      
      Severity: Minor
      Found in models/SQ_Frontend.php - About 4 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 calcDensity has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

          private function calcDensity($text, $title = '', $description = '') {
              $keywords = array();
              $text = $title . '. ' . $text;
              $text = @preg_replace('/[^a-zA-Z0-9-.]/', ' ', $text);
              $title = explode(" ", $title);
      Severity: Minor
      Found in models/SQ_Frontend.php - About 4 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 getCustomTitle has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getCustomTitle() {
              global $wp_query;
              $count = 0;
              $title = '';
              $optitle = '';
      Severity: Minor
      Found in models/SQ_Frontend.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

      Method getCanonicalUrl has 79 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          function getCanonicalUrl() {
              global $wp_query;
      
              if (!isset($wp_query) || $wp_query->is_404 || $wp_query->is_search) {
                  return false;
      Severity: Major
      Found in models/SQ_Frontend.php - About 3 hrs to fix

        Method grabKeywordsFromPost has 76 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function grabKeywordsFromPost($id = null) {
                global $wp_query;
        
                $this->max_keywrods = ($this->max_keywrods > 0 ? ($this->max_keywrods - 1) : 0);
                if ($this->max_keywrods == 0)
        Severity: Major
        Found in models/SQ_Frontend.php - About 3 hrs to fix

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

              function setHeader() {
                  global $wp_query;
                  $ret = '';
                  $this->post = $wp_query->get_queried_object();
                  $this->meta['blogname'] = get_bloginfo('name');
          Severity: Minor
          Found in models/SQ_Frontend.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 getCustomDescription has 60 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function getCustomDescription() {
                  global $wp_query;
                  $sep = '|';
                  $description = '';
          
          Severity: Major
          Found in models/SQ_Frontend.php - About 2 hrs to fix

            Consider simplifying this complex logical expression.
            Open

                    if (is_home() || (isset($wp_query->query) && empty($wp_query->query)) || is_single() || is_preview() || is_page() || is_archive() || is_category() || is_author() || is_tag() || is_search()) {
            
            
                        /* Meta setting */
                        $this->title = $this->clearTitle($this->getCustomTitle());
            Severity: Critical
            Found in models/SQ_Frontend.php - About 2 hrs to fix

              Consider simplifying this complex logical expression.
              Open

                      if (is_home() || (isset($wp_query->query) && empty($wp_query->query)) || is_single() || is_preview() || is_page() || is_archive() || is_author() || is_category() || is_tag() || is_search()) {
              
                          $title = $this->getCustomTitle();
                          if (isset($title) && !empty($title) && $title <> '') {
                              $buffer = @preg_replace('/<title[^<>]*>([^<>]*)<\/title>/si', sprintf("<title>%s</title>", $title), $buffer, 1, $count);
              Severity: Critical
              Found in models/SQ_Frontend.php - About 2 hrs to fix

                Method getCustomTitle has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function getCustomTitle() {
                        global $wp_query;
                        $count = 0;
                        $title = '';
                        $optitle = '';
                Severity: Major
                Found in models/SQ_Frontend.php - About 2 hrs to fix

                  Method calcDensity has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private function calcDensity($text, $title = '', $description = '') {
                          $keywords = array();
                          $text = $title . '. ' . $text;
                          $text = @preg_replace('/[^a-zA-Z0-9-.]/', ' ', $text);
                          $title = explode(" ", $title);
                  Severity: Minor
                  Found in models/SQ_Frontend.php - About 1 hr to fix

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

                        public function getAdvancedMeta($post_id, $meta = 'title') {
                            global $wpdb;
                            $field = '';
                            $cond = '';
                    
                    Severity: Minor
                    Found in models/SQ_Frontend.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 getOtherPluginsMeta has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function getOtherPluginsMeta($post_id, $meta = 'title') {
                            global $wpdb;
                            $field = '';
                            $cond = '';
                    
                    Severity: Minor
                    Found in models/SQ_Frontend.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 setMetaInBuffer has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                    Open

                        private function setMetaInBuffer($buffer) {
                            global $wp_query;
                            $this->post = $wp_query->get_queried_object();
                    
                            if (is_home() || (isset($wp_query->query) && empty($wp_query->query)) || is_single() || is_preview() || is_page() || is_archive() || is_author() || is_category() || is_tag() || is_search()) {
                    Severity: Minor
                    Found in models/SQ_Frontend.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 getOtherPluginsMeta has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function getOtherPluginsMeta($post_id, $meta = 'title') {
                            global $wpdb;
                            $field = '';
                            $cond = '';
                    
                    Severity: Minor
                    Found in models/SQ_Frontend.php - About 1 hr to fix

                      Method getAdvancedMeta has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function getAdvancedMeta($post_id, $meta = 'title') {
                              global $wpdb;
                              $field = '';
                              $cond = '';
                      
                      Severity: Minor
                      Found in models/SQ_Frontend.php - About 1 hr to fix

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

                            function setHeader() {
                                global $wp_query;
                                $ret = '';
                                $this->post = $wp_query->get_queried_object();
                                $this->meta['blogname'] = get_bloginfo('name');
                        Severity: Minor
                        Found in models/SQ_Frontend.php - About 1 hr to fix

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

                              private function getCustomKeyword() {
                                  global $wp_query;
                                  $keywords = '';
                          
                                  if ($this->checkPostsPage() && SQ_Tools::$options['sq_auto_description'] == 1) {
                          Severity: Minor
                          Found in models/SQ_Frontend.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 grabDescriptionFromPost has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                          Open

                              function grabDescriptionFromPost($id = null) {
                                  global $wp_query;
                                  $post = null;
                                  $description = '';
                                  $advdescription = '';
                          Severity: Minor
                          Found in models/SQ_Frontend.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 getImageFromContent has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                          Open

                              public function getImageFromContent() {
                                  global $wp_query;
                                  $match = array();
                                  $post = $this->post;
                          
                          Severity: Minor
                          Found in models/SQ_Frontend.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

                          Consider simplifying this complex logical expression.
                          Open

                                  if (get_query_var('m')) {
                                      $m = @preg_replace('/[^0-9]/', '', get_query_var('m'));
                                      switch (strlen($m)) {
                                          case 4:
                                              $link = get_year_link($m);
                          Severity: Major
                          Found in models/SQ_Frontend.php - About 1 hr to fix

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

                                function getUniqueKeywords($keywords) {
                                    $all = array();
                                    if (is_array($keywords))
                                        foreach ($keywords as $word) {
                                            if (function_exists('mb_strtolower'))
                            Severity: Minor
                            Found in models/SQ_Frontend.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 grabTitleFromPost has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                            Open

                                private function grabTitleFromPost($id = null) {
                                    global $wp_query;
                                    $post = null;
                                    $title = '';
                                    $advtitle = '';
                            Severity: Minor
                            Found in models/SQ_Frontend.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 getPublisher has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                            Open

                                private function getPublisher() {
                                    $author = SQ_Tools::$options['sq_google_plus'];
                                    if ($author == '')
                                        $author = $this->getAuthorLinkFromBlog();
                                    elseif (!$author)
                            Severity: Minor
                            Found in models/SQ_Frontend.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 getAuthorLinkFromBlog has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                            Open

                                function getAuthorLinkFromBlog() {
                                    global $wp_query, $wp_version;
                            
                                    if ($wp_query->is_author && count($wp_query->posts) > 0) {
                                        if ($wp_version >= '2') {
                            Severity: Minor
                            Found in models/SQ_Frontend.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

                            Consider simplifying this complex logical expression.
                            Open

                                    if ($this->isHomePage() &&
                                            SQ_Tools::$options['sq_auto_description'] == 1 &&
                                            SQ_Tools::$options['sq_auto_seo'] == 0 &&
                                            SQ_Tools::$options['sq_fp_description'] <> '' &&
                                            (!isset($post) || !$this->getAdvancedMeta($post->ID, 'description'))) {
                            Severity: Major
                            Found in models/SQ_Frontend.php - About 40 mins to fix

                              Consider simplifying this complex logical expression.
                              Open

                                      } else if ($wp_query->is_tag && $haspost) {
                                          $tag = get_term_by('slug', get_query_var('tag'), 'post_tag');
                                          if (!empty($tag->term_id)) {
                                              $link = get_tag_link($tag->term_id);
                                          }
                              Severity: Major
                              Found in models/SQ_Frontend.php - About 40 mins to fix

                                Consider simplifying this complex logical expression.
                                Open

                                        if ($this->isHomePage() &&
                                                SQ_Tools::$options['sq_auto_title'] == 1 &&
                                                SQ_Tools::$options['sq_auto_seo'] == 0 &&
                                                SQ_Tools::$options['sq_fp_title'] <> '' &&
                                                (!isset($post) || !$this->getAdvancedMeta($post->ID, 'title'))) {
                                Severity: Major
                                Found in models/SQ_Frontend.php - About 40 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                          return $link;
                                  Severity: Major
                                  Found in models/SQ_Frontend.php - About 30 mins to fix

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

                                        function searchPhrase($text) {
                                            $words = explode(".", strtolower($text));
                                            //print_r($words);
                                            $frequencies = array();
                                            foreach ($words as $str) {
                                    Severity: Minor
                                    Found in models/SQ_Frontend.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 3 locations. Consider refactoring.
                                    Open

                                        function yoastGetPaged($link) {
                                            $page = get_query_var('paged');
                                            if ($page && $page > 1) {
                                                $link = trailingslashit($link) . "page/" . "$page";
                                                if ($has_ut) {
                                    Severity: Major
                                    Found in models/SQ_Frontend.php and 2 other locations - About 40 mins to fix
                                    controllers/SQ_Post.php on lines 201..212
                                    controllers/SQ_PostsList.php on lines 378..389

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

                                    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