Completed
Pull Request — 2.x (#4187)
by Scott Kingsley
06:00
created

Pods_I18n_Polylang   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 52.5 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
dl 21
loc 40
rs 10
c 0
b 0
f 0
wmc 6
lcom 2
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A pods_component_i18n_admin_data() 10 10 3
A pods_component_i18n_admin_ui_fields() 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php 
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 3 and the first side effect is on line 44.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
class Pods_I18n_Polylang {
4
5
	public $languages = array();
6
	public $textdomain = 'polylang';
7
8
	public function __construct() {
9
10
		if ( function_exists( 'pll_languages_list' ) ) {
11
			$this->languages = pll_languages_list( array( 'fields' => 'locale' ) );
12
13
			add_filter( 'pods_component_i18n_admin_data', array( $this, 'pods_component_i18n_admin_data' ) );
14
			add_filter( 'pods_component_i18n_admin_ui_fields', array( $this, 'pods_component_i18n_admin_ui_fields' ), 10, 2 );
15
		}
16
17
	}
18
19 View Code Duplication
	public function pods_component_i18n_admin_data( $data ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
		foreach ( $data as $lang => $field_data ) {
21
			if ( in_array( $lang, $this->languages ) ) {
22
				$data[$lang]['polylang'] = true;
23
			} else {
24
				$data[$lang]['polylang'] = false;
25
			}
26
		}
27
		return $data;
28
	}
29
30 View Code Duplication
	public function pods_component_i18n_admin_ui_fields( $fields, $data ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
		$fields['manage']['polylang'] = array(
32
			'label' => __( 'Polylang' , $this->textdomain ),
33
			'type' => 'boolean',
34
			/*'options' => array(
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
35
				'text_allow_html' => 1,
36
				'text_allowed_html_tags' => 'br a',
37
			)*/
38
		);
39
		return $fields;
40
	}
41
42
}
43
44
new Pods_I18n_Polylang();