File Backend.php
has 1398 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace Toplytics;
use Exception;
Function convertDataToPosts
has a Cognitive Complexity of 66 (exceeds 5 allowed). Consider refactoring. Open
private function convertDataToPosts($data, $when)
{
$new_data = [];
if ($this->checkSetting('ignore_posts_ids')) {
- 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
Backend
has 62 functions (exceeds 20 allowed). Consider refactoring. Open
class Backend
{
/**
* The ID of this plugin.
Method initSettings
has 214 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function initSettings()
{
$options = get_option('toplytics_settings');
if ($options == false) {
$options = $this->getDefaultSettings();
Method convertDataToPosts
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function convertDataToPosts($data, $when)
{
$new_data = [];
if ($this->checkSetting('ignore_posts_ids')) {
Function update_additional_posts_data
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
public function update_additional_posts_data()
{
// Fetch the widgets data from the database, if not already retrieved.
$this->_maybe_fetch_widgets_data();
- 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 getAnalyticsData
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getAnalyticsData( $extended_fetch = false )
{
$propertyId = get_option('toplytics_property_id', false);
if (!$propertyId) return false;
Method update_additional_posts_data
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function update_additional_posts_data()
{
// Fetch the widgets data from the database, if not already retrieved.
$this->_maybe_fetch_widgets_data();
Function _have_enough_results
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
private function _have_enough_results( $posts, $period )
{
// Fetch the widgets data from the database, if not already retrieved.
$this->_maybe_fetch_widgets_data();
- 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 printInput
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function printInput($args)
{
$option = 'toplytics_settings';
$settings = get_option($option);
- 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 getAnalyticsData
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private function getAnalyticsData( $extended_fetch = false )
{
$propertyId = get_option('toplytics_property_id', false);
if (!$propertyId) 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
Method privateAuthorization
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function privateAuthorization()
{
if (empty($_POST['ToplyticsSubmitPrivateAuthorization'])) {
return false;
}
Function updateAnalyticsDataResults
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function updateAnalyticsDataResults( $extended_fetch = false )
{
try {
$data = $this->getAnalyticsData( $extended_fetch );
} catch (Exception $e) {
- 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 serviceConnect
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
protected function serviceConnect()
{
if (!$this->client) {
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 openWindowToSettingsView
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function openWindowToSettingsView()
{
if (get_option('toplytics_google_token')) {
$profile = get_option('toplytics_profile_data');
- 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 serviceDisconnect
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function serviceDisconnect($programatic = false, $silent = false)
{
if (empty($_POST['ToplyticsSubmitAccountDisconnect']) && !$programatic) {
return;
}
Method serviceConnect
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function serviceConnect()
{
if (!$this->client) {
return false;
}
Method printInput
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function printInput($args)
{
$option = 'toplytics_settings';
$settings = get_option($option);
Method extraRowMeta
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function extraRowMeta($plugin_meta, $plugin_file = null)
{
global $toplytics_engine;
if ( ! is_null( $plugin_file ) && $plugin_file !== $this->plugin_basename ) {
Method getAnalyticsRealTimeData
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getAnalyticsRealTimeData( $extended_fetch = false )
{
if ( ! $this->checkSetting('fetch_realtime') ) {
return [];
}
Method openWindowToSettingsView
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function openWindowToSettingsView()
{
if (get_option('toplytics_google_token')) {
$profile = get_option('toplytics_profile_data');
Method getAuthConfig
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getAuthConfig()
{
$authType = get_option('toplytics_auth_type');
if ($authType == 'private') {
Method updateAnalyticsDataResults
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function updateAnalyticsDataResults( $extended_fetch = false )
{
try {
$data = $this->getAnalyticsData( $extended_fetch );
} catch (Exception $e) {
Function getAnalyticsRealTimeData
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function getAnalyticsRealTimeData( $extended_fetch = false )
{
if ( ! $this->checkSetting('fetch_realtime') ) {
return [];
}
- 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 getProfiles
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function getProfiles()
{
$profiles = [];
$accounts = $this->getAccounts();
foreach ($accounts as $account_id => $account_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
Consider simplifying this complex logical expression. Open
if (!empty($args['input']) && ($args['input'] == 'text' || $args['input'] == 'color')) {
echo "<input type='text' id='" . $args['id'] . "' name='" . $option . "[" . $args['id'] . "]' value='" . (!empty($settings[$args['id']]) ? $settings[$args['id']] : '') . "' placeholder='" . (!empty($args['placeholder']) ? $args['placeholder'] : '') . "' " . (!empty($args['disabled']) && $args['disabled'] ? 'readonly="readonly"' : '') . " />";
}
//Select
Function act_before_settings_update
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function act_before_settings_update($updated_settings)
{
// Fetch the current set of Toplytics settings from the DB.
$current_settings = get_option('toplytics_settings');
- 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 updateAnalyticsRealTimeDataResults
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function updateAnalyticsRealTimeDataResults( $extended_fetch = false )
{
try {
$realtime = $this->getAnalyticsRealTimeData( $extended_fetch );
} catch (Exception $e) {
- 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 _get_featured_image
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function _get_featured_image( $post_id )
{
$featured_image = $image_size = ''; // Sensible default.
if ( $this->checkSetting( 'include_featured_image_in_json' ) ) {
// Check if a value is set for the featured image size.
- 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 getAuthConfig
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function getAuthConfig()
{
$authType = get_option('toplytics_auth_type');
if ($authType == 'private') {
- 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 serviceDisconnect
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function serviceDisconnect($programatic = false, $silent = false)
{
if (empty($_POST['ToplyticsSubmitAccountDisconnect']) && !$programatic) {
return;
}
- 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 checkAuthorization
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function checkAuthorization()
{
if (isset($_GET['code']) && $_GET['page'] === 'toplytics') {
if (isset($_GET['status']) && $_GET['status'] && $_GET['status'] == 'error') {
$get_error = filter_input(INPUT_GET, 'code', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
- 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 profileSelect
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function profileSelect()
{
if (empty($_POST['ToplyticsProfileSelect']) || (empty($_POST['profile_id']) && empty($_POST['property_id']))) {
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 validateGoogleConfig
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function validateGoogleConfig($googleconfig, $skipUriCheck = false)
{
if (!is_object($googleconfig)) {
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 pluginUpgradeComplete
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function pluginUpgradeComplete( $upgraderObject, $options ) {
// If an update has taken place and the updated type is plugins and the plugins element exists
if( $options['action'] == 'update' && $options['type'] == 'plugin' && isset( $options['plugins'] ) ) {
// Iterate through the plugins being updated and check if ours is there
foreach( $options['plugins'] as $plugin ) {
- 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
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return $googleconfig;
Avoid too many return
statements within this method. Open
return true;
Similar blocks of code found in 3 locations. Consider refactoring. Open
add_settings_field(
'allowed_post_types',
$this->getLabel(__('Allowed post types', TOPLYTICS_DOMAIN), 'allowed_post_types'),
[$this, 'printInput'],
'toplytics',
- 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 99.
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
Similar blocks of code found in 3 locations. Consider refactoring. Open
add_settings_field(
'custom_output_post_variables',
$this->getLabel(__('Custom post variables in JSON output', TOPLYTICS_DOMAIN), 'custom_output_post_variables'),
[$this, 'printInput'],
'toplytics',
- 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 99.
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
Similar blocks of code found in 3 locations. Consider refactoring. Open
add_settings_field(
'ignore_posts_ids',
$this->getLabel(__('Ignore Post IDs', TOPLYTICS_DOMAIN), 'ignore_posts_ids'),
[$this, 'printInput'],
'toplytics',
- 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 99.
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