Showing 1,420 of 1,425 total issues
Similar blocks of code found in 4 locations. Consider refactoring. Open
<?php $i = 1; while ( $i <= 24 ) : ?>
<option value="<?php echo esc_attr( $i ); ?>"<?php selected( $i, ( $plan && 'month' === $period ) ? $plan->get( 'length' ) : '' ); ?>><?php printf( esc_html( _n( 'for %s month', 'for %s months', $i, 'lifterlms' ) ), esc_html( $i ) ); ?></option>
<?php
++$i;
endwhile;
- 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 103.
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
Function bind_controllers
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
this.bind_controllers = function( $controllers ) {
$controllers = $controllers || $( '[data-is-controller]' );
$controllers.each( function() {
Function writeChangelog
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
function writeChangelog( log ) {
const { dir } = log;
let { title } = log;
delete log.dir;
delete log.title;
Function render_editor
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
render_editor: function( field ) {
var self = this,
wpEditor = _.getEditor();
Method gateways
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function gateways() {
$id = 'no-gateways';
if ( ! apply_filters( 'llms_admin_notice_no_payment_gateways', llms()->payment_gateways()->has_gateways( true ) ) ) {
$html = __( 'No LifterLMS Payment Gateways are currently enabled. Students will only be able to enroll in courses or memberships with free access plans.', 'lifterlms' ) . '<br><br>';
Method admin_print_scripts
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function admin_print_scripts() {
$screen = get_current_screen();
global $post;
Method output
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function output() {
global $post;
parent::output(); ?>
Method register_meta_boxes
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function register_meta_boxes() {
add_meta_box(
'llms_dashboard_welcome_video',
__( 'Welcome to LifterLMS', 'lifterlms' ),
Method generate_csv
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function generate_csv() {
$csv = array();
$orders = new WP_Query(
Method add_elements
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function add_elements( $elements ) {
// Accent Background.
$elements['content']['accent']['background-color'] = array_merge(
$elements['content']['accent']['background-color'],
Method get_enrollment_status
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function get_enrollment_status( $product_id, $use_cache = true ) {
$status = false;
$product_type = get_post_type( $product_id );
Method unenroll
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function unenroll( $product_id, $trigger = 'any', $new_status = 'expired' ) {
// Can only unenroll those that are a currently enrolled.
if ( ! $this->is_enrolled( $product_id, 'all', false ) ) {
return false;
Method llms_update_access_plans
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function llms_update_access_plans( $request ) {
if ( empty( $request['plans'] ) || ! is_array( $request['plans'] ) || empty( $request['post_id'] ) ) {
return new WP_Error( 'error', __( 'Missing Required Parameters.', 'lifterlms' ) );
}
Method get_core_forms
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function get_core_forms( $return = 'posts', $use_cache = true ) {
global $wpdb;
$forms_cache_key = 'posts' === $return ? 'llms_core_forms' : 'llms_core_form_ids';
Method get_password_reset_fields
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function get_password_reset_fields( $key = '', $login = '' ) {
$fields = array();
foreach ( array( 'checkout', 'registration' ) as $location ) {
$fields = self::find_password_fields( $location );
Method enqueue_scripts
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function enqueue_scripts() {
// I don't think we need these next 3 scripts.
wp_enqueue_script( 'jquery-ui-tooltip' );
wp_enqueue_script( 'jquery-ui-datepicker' );
Method prepare
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function prepare() {
if ( empty( $this->settings['id'] ) ) {
$this->settings['id'] = uniqid( 'llms-field-' );
}
Method explode_options_to_fields
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function explode_options_to_fields( $is_hidden = false ) {
$fields = array();
$value = ! empty( $this->settings['value'] ) || is_array( $this->settings['value'] )
? $this->settings['value']
Method validate_matching_fields
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function validate_matching_fields( $posted_data, $fields ) {
$err = new WP_Error();
$err_data = array();
Method get_core_caps
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function get_core_caps( $role ) {
$all_caps = array_fill_keys( array_values( self::get_all_core_caps() ), true );
switch ( $role ) {