Completed
Push — master ( 48e484...cedfdf )
by
unknown
03:10
created

helpers.php ➔ lasso_get_supported_theme_title_class()   C

Complexity

Conditions 11
Paths 10

Size

Total Lines 38
Code Lines 32

Duplication

Lines 38
Ratio 100 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 11
eloc 32
c 2
b 1
f 0
nc 10
nop 0
dl 38
loc 38
rs 5.2653

How to fix   Complexity   

Long Method

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:

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 15 and the first side effect is on line 389.

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
/**
4
 * Grab an option from our settings
5
 *
6
 * If we're on multsite we'll grab the site option which is stored in the main blogs site option tables, otherwise
7
 * we'll grab the option which is stored on the single blogs option tables
8
 *
9
 * @param unknown $option  string name of the option
10
 * @param unknown $section string name of the section
11
 * @param unknown $default string/int default option value
12
 * @return the option value
13
 * @since 1.0
14
 */
15
function lasso_editor_get_option( $option, $section, $default = '' ) {
16
17
	if ( empty( $option ) )
18
		return;
19
20
	if ( function_exists( 'is_multisite' ) && is_multisite() ) {
21
22
		$options = get_site_option( $section );
23
24
	} else {
25
26
		$options = get_option( $section );
27
	}
28
29
	if ( isset( $options[$option] ) ) {
30
		return $options[$option];
31
	}
32
33
	return $default;
34
}
35
36
/**
37
 * Check to see if any Lasso galleries exist
38
 *
39
 * @since 1.0
40
 */
41
function lasso_editor_galleries_exist() {
42
43
	$q = new wp_query( array( 'post_type' => 'ai_galleries', 'post_status' => 'publish' ) );
44
45
	if ( $q->have_posts() )
46
		return true;
47
	else
48
		return false;
49
}
50
51
/**
52
 * Return a CSS class of an automatically supported theme
53
 *
54
 * @since 0.8.6
55
 * @return a css class if the theme is supported, false if nothing
56
 */
57 View Code Duplication
function lasso_get_supported_theme_class() {
0 ignored issues
show
Duplication introduced by
This function 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...
58
59
	$name  	= wp_get_theme()->get('Name');
60
	$slug  	= lasso_clean_string( $name );
61
62
	switch ( $slug ) {
63
		case 'aesop-story-theme': // aesop
64
			$out = '.aesop-entry-content';
65
			break;
66
		case 'jorgen': // aesop
67
			$out = '.jorgen-entry-content';
68
			break;
69
		case 'novella': // aesop
70
			$out = '.novella-entry-content';
71
			break;
72
		case 'genji': // aesop
73
			$out = '.genji-entry-content';
74
			break;
75
		case 'kerouac': // aesop
76
			$out = '.kerouac-entry-content';
77
			break;
78
		case 'zealot': // aesop
79
			$out = '.zealot-entry-content';
80
			break;
81
		case 'fable': // aesop
82
			$out = '.fable--entry-content';
83
			break;
84
		case 'canvas': // wootheme..err...Automattic
85
			$out = '.entry';
86
			break;
87
		case 'kleo': // 
88
			$out = '.article-content';
89
			break;
90
		//case 'exposure': // 
91
		//	$out = '.entry-content';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
92
		//	break;
93
		//case 'lore': // 
94
		//	$out = '.entry-content';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
95
		//	break;
96
		//case 'worldview': // upthemes
97
		//	$out = '.entry-content';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
98
		//	break;
99
		//case 'genesis': // genesis
100
		//	$out = '.entry-content';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
101
		//	break;
102
		//case 'camera': // array.is
103
		//	$out = '.entry-content';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
104
		//	break;
105
		case 'longform': 
106
			$out = '.entry-content-wrapper';
107
			break;
108
109
	}
110
111
	return apply_filters('lasso_content_class', !empty( $out ) ? $out : false);
112
	//return !empty( $out ) ? $out : false;
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
113
}
114
115 View Code Duplication
function lasso_get_supported_theme_title_class() {
0 ignored issues
show
Duplication introduced by
This function 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...
116
117
	$name  	= wp_get_theme()->get('Name');
118
	$slug  	= lasso_clean_string( $name );
119
120
	switch ( $slug ) {
121
122
		case 'aesop-story-theme': // aesop
123
			$out = '.aesop-entry-title';
124
			break;
125
		case 'jorgen': // aesop
126
			$out = '.jorgen-entry-title';
127
			break;
128
		case 'novella': // aesop
129
			$out = '.novella-entry-title';
130
			break;
131
		case 'genji': // aesop
132
			$out = '.genji-entry-title';
133
			break;
134
		case 'kerouac': // aesop
135
			$out = '.kerouac-entry-title';
136
			break;
137
		case 'zealot': // aesop
138
			$out = '.zealot-entry-title';
139
			break;
140
		case 'fable': // aesop
141
			$out = '.fable--entry-title';
142
			break;
143
		case 'kleo': // 
144
			$out = '.page-title';
145
			break;
146
		case 'longform': // 
147
			$out = '.entry-title';
148
			break;
149
	}
150
151
	return apply_filters('lasso_title_class', !empty( $out ) ? $out : false);
152
}
153
154
//since 0.9.9.6
155
function lasso_get_supported_theme_featured_image_class() {
156
157
	$name  	= wp_get_theme()->get('Name');
158
	$slug  	= lasso_clean_string( $name );
0 ignored issues
show
Unused Code introduced by
$slug is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
159
160
	return apply_filters('lasso_featured_image_class', !empty( $out ) ? $out : false);
0 ignored issues
show
Bug introduced by
The variable $out seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
161
}
162
163
164
/**
165
*	Return a string of classes with items that Lasso will remove when entering the editor
166
*	so that we don't save them as HTML
167
*
168
*	@since 0.8.7
169
*	@return string of comma separated classes
170
*/
171
function lasso_supported_no_save(){
172
173
	return apply_filters('lasso_dont_save', '.lasso--ignore, .sharedaddy, .us_wrapper, .twitter-tweet, .meta, .edit-link');
174
}
175
176
/**
177
 * Generic sanitization, useful for sanitization of arrays.
178
 *
179
 * @since 0.9.2
180
 *
181
 * @param array|object|string $data Data to sanatize.
182
 *
183
 * @return array|mixed|object|string|void
184
 */
185
function lasso_sanitize_data( $data ) {
186
	return \lasso\sanatize::do_sanitize( $data );
187
188
}
189
190
/**
191
 *	Return a comma delimited list of categories for a specific post object
192
 *
193
 *	@since 0.9.3
194
 *	@return string of comma delimited category slugs
195
*/
196
function lasso_get_post_objects( $postid = '', $taxonomy = 'category') {
197
198
	if ( empty( $postid ) )
199
		$postid = get_the_ID();
200
201
	$objects = 'category' == $taxonomy ? get_the_category( $postid ) : get_the_tags( $postid );
202
203
	if ( empty( $objects) )
204
		return;
205
206
	$out = '';
207
	foreach( $objects as $object ) {
208
		$out .= $object->slug.', ';
209
	}
210
211
	return rtrim($out, ', ');
212
213
}
214
215
/**
216
 *	Return an array of categories for autocomplete
217
 *
218
 *	@since 0.9.3
219
 *	@return array all categoiries
220
*/
221
function lasso_get_objects( $taxonomy = 'category' ) {
222
223
	$objects = 'category' == $taxonomy ? get_categories(array('hide_empty' => 0)) : get_tags(array('hide_empty' => 0));
224
225
	if ( empty( $objects) )
226
		return;
227
228
	$out = array();
229
	foreach( $objects as $object ) {
230
		$out[] = $object->slug;
231
	}
232
233
	return $out;
234
}
235
236
237
/**
238
 * Get allowed post types for the post chooser modal.
239
 *
240
 *
241
 * @since 0.9.4
242
 */
243
function lasso_post_types_names() {
244
	$post_types = get_post_types( array(
245
		'public' => true,
246
	), 'objects' );
247
	$post_types = array_combine( array_keys( $post_types ), wp_list_pluck( $post_types, 'label' ) );
248
    unset( $post_types[ 'attachment' ] );
249
250
	/**
251
	 * Set which post types are allowed
252
	 *
253
	 * @since 0.9.4
254
	 *
255
	 * @param array $allowed_post_types Array of names (not labels) of allowed post types. Must be registered.
256
	 */
257
	$allowed_post_types = apply_filters( 'lasso_allowed_post_types', array( 'post', 'page') );
258
	foreach( $post_types as $name => $label ) {
259
		if ( ! in_array( $name, $allowed_post_types ) ) {
260
			unset( $post_types[ $name ] );
261
		}
262
	}
263
	return $post_types;
264
}
265
266
267
function lasso_post_types() {
268
	$post_types = get_post_types( array(
269
		'public' => true,
270
	), 'names' );
271
	//$post_types = array_combine( array_keys( $post_types ), wp_list_pluck( $post_types, 'label' ) );
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% 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...
272
    unset( $post_types[ 'attachment' ] );
273
274
	/**
275
	 * Set which post types are allowed
276
	 *
277
	 * @since 0.9.4
278
	 *
279
	 * @param array $allowed_post_types Array of names (not labels) of allowed post types. Must be registered.
280
	 */
281
	$allowed_post_types = apply_filters( 'lasso_allowed_post_types', array( 'post', 'page') );
282
	foreach( $post_types as $name => $label ) {
283
		if ( ! in_array( $name, $allowed_post_types ) ) {
284
			unset( $post_types[ $name ] );
285
		}
286
	}
287
	return $post_types;
288
}
289
290
291
292
////////////////////
293
// INTERNAL
294
////////////////////
295
/**
296
*	Used internally as a callback to build a tab or content area for modal addons
297
*
298
*	@param $tab object
299
*	@param $type string tab or content
300
*	@uses lasso_modal_addons()
301
*	@since 0.9.4
302
*/
303
function lasso_modal_addons_content( $tab = '', $type ){
304
305
	$name = lasso_clean_string( $tab['name'] );
306
307
	if ( 'tab' == $type ) {
308
309
		$out = sprintf( '<li data-addon-name="%s">%s</li>', $name, $tab['name'] );
310
311
	} else if ( 'content' == $type ){
312
313
		$content = isset( $tab['content'] ) && is_callable( $tab['content'] ) ? call_user_func( $tab['content'] ) : false;
314
		$options = isset( $tab['options'] ) && is_callable( $tab['options'] ) ? call_user_func( $tab['options'] ) : false;
315
316
		$out = sprintf( '<div class="lasso--modal__content not-visible" data-addon-content="%s">
317
			%s%s
318
			</div>', $name, $content, lasso_option_form( $name, $options ) );
319
320
	}
321
322
	return $out;
0 ignored issues
show
Bug introduced by
The variable $out does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
323
}
324
325
/**
326
*	Helper function to clean a string and replace spaces with dash
327
*
328
*	@param $string string content
329
*	@since 0.9.4
330
*
331
* @return void|string
332
*/
333
function lasso_clean_string( $string = '' ) {
334
335
	if ( empty( $string ) )
336
		return;
337
338
	return sanitize_text_field( strtolower( preg_replace('/[\s_]/', '-', $string ) ) );
339
}
340
341
/**
342
 *	Helper function to switch - to _ after having.
343
 *
344
 * This is the evil twin of lasso_clean_string() and may or may not make your data forever unclean.
345
 *
346
 *	@param $string string content
347
 *	@since 0.9.5
348
 *
349
 * @return void|string
350
 */
351
function lasso_unclean_string( $string = '' ) {
352
353
	if ( empty( $string ) ) {
354
		return;
355
	}
356
357
	return sanitize_text_field( strtolower( str_replace( '-', '_', $string ) ) );
358
}
359
360
361
////////////////////
362
// PLUGGABLE
363
////////////////////
364
365
/**
366
 * Check if the user is logged in and has the correctly passed capability
367
 *
368
 * @param unknown $action string a capability such as edit_posts or publish_posts
369
 * @param unknown $postid int the id of the post object to check against
370
 * @since 0.9.9.7 added filter 'lasso_user_can_filter'
371
 */
372
if ( !function_exists( 'lasso_user_can' ) ):
373
	function lasso_user_can( $action = '', $postid = 0 ) {
374
        $result = false;
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
375
		if ( empty( $action ) )
376
			$action = 'edit_posts';
377
378
		if ( empty( $postid ) )
379
			$postid = get_the_ID();
380
381
		if ( is_user_logged_in() && current_user_can( $action, $postid ) ) {
382
			$result =  true;
383
		} else {
384
			$result = false;
385
		}
386
		
387
		return apply_filters( 'lasso_user_can_filter', $result,  $action, $postid);
388
	}
389
endif;
390
391
/**
392
*	Empty state message thats shown when no data available
393
*
394
*	@since 0.9.5
395
*/
396
if ( !function_exists('lasso_editor_empty_results') ):
397
398
	function lasso_editor_empty_results( $type = 'posts' ){
399
400
		if ( 'posts' == $type ) {
401
402
			$string = apply_filters('lasso_empty_state_message', __('No posts to show', 'lasso') );
403
			$icon = 'lasso-icon-file-text2';
404
			$button = false;
405
406
		} elseif ( 'revision' == $type ) {
407
408
			$string = apply_filters('lasso_empty_state_message', __('No revisions found', 'lasso') );
409
			$icon = 'lasso-icon-history';
410
			$button = sprintf('<a href="#" class="lasso--btn-secondary" id="lasso--close-modal">%s</a>', __('Close','lasso') );
411
412
		}
413
414
		return sprintf('<div id="lasso--empty-state" class="lasso--empty-state"><i class="lasso--empty-state-icon lasso-icon %s"></i><p>%s</p>%s</div>', $icon, $string, $button );
0 ignored issues
show
Bug introduced by
The variable $icon does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $string does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $button does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
415
	}
416
417
endif;
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432