Conditions | 9 |
Paths | 11 |
Total Lines | 66 |
Code Lines | 27 |
Lines | 10 |
Ratio | 15.15 % |
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 |
||
128 | public function __get( $var ) { |
||
129 | |||
130 | if ( 'sub_apps' === $var ) { |
||
131 | return $this->$var; |
||
132 | } |
||
133 | |||
134 | $sub = $this->sub_apps->get( $var, array( $this ) ); |
||
135 | |||
136 | if ( ! $sub ) { |
||
137 | return null; |
||
138 | } |
||
139 | |||
140 | if ( |
||
141 | empty( $this->did_init[ $var ] ) |
||
142 | && ! self::$main->silent |
||
143 | && $this->should_do_registry_init( $sub ) |
||
144 | ) { |
||
145 | |||
146 | $is_protected_property = array_key_exists( $var, get_object_vars( $this ) ); |
||
147 | |||
148 | // When the below action is called it is possible that some hooked code |
||
149 | // may attempt to access the property that is being initialized. However, |
||
150 | // the __get() function will not be called recursively, meaning that |
||
151 | // instead of the true value the code will get null. To solve this, we |
||
152 | // temporarily set this as a public property. However, we can't do this |
||
153 | // for properties that the class has declared, because otherwise it would |
||
154 | // be possible to modify and then unset protected class properties. |
||
155 | View Code Duplication | if ( ! $is_protected_property ) { |
|
|
|||
156 | $this->allow_set = true; |
||
157 | $this->$var = $sub; |
||
158 | $this->allow_set = false; |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * Initialization of an app registry. |
||
163 | * |
||
164 | * The $var is the slug of the registry. |
||
165 | * |
||
166 | * @since 1.0.0 |
||
167 | * |
||
168 | * @param WordPoints_Class_RegistryI|WordPoints_Class_Registry_ChildrenI |
||
169 | * $registry The registry object. |
||
170 | */ |
||
171 | do_action( "wordpoints_init_app_registry-{$this->full_slug}-{$var}", $sub ); |
||
172 | |||
173 | // Because this property was public, it's possible that it might have |
||
174 | // been modified inadvertently. If this happens we give a warning. |
||
175 | if ( $sub !== $this->$var ) { |
||
176 | _doing_it_wrong( |
||
177 | __METHOD__ |
||
178 | , esc_html( "Do not modify the {$var} property directly." ) |
||
179 | , '1.0.0' |
||
180 | ); |
||
181 | } |
||
182 | |||
183 | View Code Duplication | if ( ! $is_protected_property ) { |
|
184 | $this->allow_set = true; |
||
185 | unset( $this->$var ); |
||
186 | $this->allow_set = false; |
||
187 | } |
||
188 | |||
189 | $this->did_init[ $var ] = true; |
||
190 | } |
||
191 | |||
192 | return $sub; |
||
193 | } |
||
194 | |||
265 |
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.