Conditions | 11 |
Paths | 12 |
Total Lines | 62 |
Code Lines | 40 |
Lines | 14 |
Ratio | 22.58 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
41 | public function html() { |
||
42 | |||
43 | if ( ! empty( $this->options ) && count( (array) $this->options ) > 1 ) { |
||
44 | |||
45 | if ( ! empty( $this->description ) ) { |
||
46 | echo '<p class="description">' . wp_kses_post( $this->description ) . ' ' . $this->tooltip . '</p>'; |
||
47 | } |
||
48 | |||
49 | ?> |
||
50 | <fieldset class="<?php echo $this->class; ?>" <?php echo ! empty( $this->style ) ? 'style="' . $this->style . '"' : ''; ?>> |
||
51 | <?php |
||
52 | |||
53 | if ( ! empty( $this->title ) ) { |
||
54 | echo '<legend class="screen-reader-text"><span>' . $this->title . '</span></legend>'; |
||
55 | } |
||
56 | |||
57 | ?> |
||
58 | <ul> |
||
59 | View Code Duplication | <?php foreach ( $this->options as $option => $name ) : ?> |
|
|
|||
60 | <li> |
||
61 | <label for="<?php echo $this->id . '-' . trim( strval( $option ) ); ?>"> |
||
62 | <input name="<?php echo $this->name; ?>" |
||
63 | id="<?php echo $this->id . '-' . trim( strval( $option ) ); ?>" |
||
64 | class="simcal-field simcal-field-checkbox" |
||
65 | type="checkbox" |
||
66 | value="<?php echo trim( strval( $option ) ); ?>" |
||
67 | <?php checked( $this->value, 'yes', true ); ?> |
||
68 | <?php echo $this->attributes; ?> |
||
69 | /><?php echo esc_attr( $name ); ?> |
||
70 | </label> |
||
71 | </li> |
||
72 | <?php endforeach; ?> |
||
73 | </ul> |
||
74 | </fieldset> |
||
75 | <?php |
||
76 | |||
77 | } else { |
||
78 | |||
79 | ?> |
||
80 | <span class="simcal-field-bool" <?php echo $this->style ? 'style="' . $this->style . '"' : ''; ?>> |
||
81 | <?php if ( ! empty( $this->title ) ) : ?> |
||
82 | <span class="screen-reader-text"><?php echo $this->title; ?></span> |
||
83 | <?php endif; ?> |
||
84 | <input name="<?php echo $this->name; ?>" |
||
85 | type="checkbox" |
||
86 | id="<?php echo $this->id; ?>" |
||
87 | class="simcal-field simcal-field-checkbox <?php echo $this->class; ?>" |
||
88 | value="yes" |
||
89 | <?php checked( $this->value, 'yes', true ); ?> |
||
90 | <?php echo $this->attributes; ?>/><?php echo ( ! empty( $this->text ) ? $this->text : __( 'Yes', 'google-calendar-events' ) ); ?> |
||
91 | </span> |
||
92 | <?php |
||
93 | |||
94 | echo $this->tooltip; |
||
95 | |||
96 | if ( ! empty( $this->description ) ) { |
||
97 | echo '<p class="description">' . wp_kses_post( $this->description ) . '</p>'; |
||
98 | } |
||
99 | |||
100 | } |
||
101 | |||
102 | } |
||
103 | |||
105 |
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.