File SQ_Frontend.php
has 882 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
class Model_SQ_Frontend {
/** @var string */
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)
- Read upRead up
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;
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;
- Read upRead up
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 = '';
- Read upRead up
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);
- Read upRead up
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 = '';
- Read upRead up
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;
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)
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');
- Read upRead up
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 = '';
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());
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);
Method getCustomTitle
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getCustomTitle() {
global $wp_query;
$count = 0;
$title = '';
$optitle = '';
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);
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 = '';
- Read upRead up
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 = '';
- Read upRead up
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()) {
- Read upRead up
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 = '';
Method getAdvancedMeta
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getAdvancedMeta($post_id, $meta = 'title') {
global $wpdb;
$field = '';
$cond = '';
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');
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) {
- Read upRead up
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 = '';
- Read upRead up
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;
- Read upRead up
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);
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'))
- Read upRead up
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 = '';
- Read upRead up
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)
- Read upRead up
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') {
- Read upRead up
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'))) {
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);
}
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'))) {
Avoid too many return
statements within this method. Open
return $link;
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) {
- Read upRead up
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) {
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76