@@ -2,12 +2,12 @@ discard block |
||
2 | 2 | |
3 | 3 | do_something( $_POST ); // Ok. |
4 | 4 | |
5 | -do_something_with( $_POST['hello'] ); // Error for no validation, Error for no sanitizing, Error for no unslashing. |
|
5 | +do_something_with( $_POST[ 'hello' ] ); // Error for no validation, Error for no sanitizing, Error for no unslashing. |
|
6 | 6 | |
7 | -echo sanitize_text_field( wp_unslash( $_POST['foo1'] ) ); // Error for no validation. |
|
7 | +echo sanitize_text_field( wp_unslash( $_POST[ 'foo1' ] ) ); // Error for no validation. |
|
8 | 8 | |
9 | -if ( isset( $_POST['foo2'] ) ) { |
|
10 | - bar( wp_unslash( $_POST['foo2'] ) ); // Error for no sanitizing. |
|
9 | +if ( isset( $_POST[ 'foo2' ] ) ) { |
|
10 | + bar( wp_unslash( $_POST[ 'foo2' ] ) ); // Error for no sanitizing. |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | // @TODO: Cover non-parenthesis'd conditions |
@@ -15,100 +15,100 @@ discard block |
||
15 | 15 | // bar( $_POST['foo'] ); |
16 | 16 | |
17 | 17 | |
18 | -if ( isset( $_POST['foo3'] ) ) { |
|
19 | - bar( sanitize_text_field( wp_unslash( $_POST['foo3'] ) ) ); // Good, validated and sanitized. |
|
20 | - bar( wp_unslash( $_POST['foo3'] ) ); // Error, validated but not sanitized. |
|
21 | - bar( sanitize_text_field( wp_unslash( $_POST['foo3'] ) ) ); // Good, validated and sanitized. |
|
18 | +if ( isset( $_POST[ 'foo3' ] ) ) { |
|
19 | + bar( sanitize_text_field( wp_unslash( $_POST[ 'foo3' ] ) ) ); // Good, validated and sanitized. |
|
20 | + bar( wp_unslash( $_POST[ 'foo3' ] ) ); // Error, validated but not sanitized. |
|
21 | + bar( sanitize_text_field( wp_unslash( $_POST[ 'foo3' ] ) ) ); // Good, validated and sanitized. |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | // Should all be OK. |
25 | 25 | $empty = ( |
26 | - empty( $_GET['foo4'] ) |
|
26 | + empty( $_GET[ 'foo4' ] ) |
|
27 | 27 | || |
28 | - empty( $_REQUEST['foo4'] ) |
|
28 | + empty( $_REQUEST[ 'foo4' ] ) |
|
29 | 29 | || |
30 | - empty( $_POST['foo4'] ) |
|
30 | + empty( $_POST[ 'foo4' ] ) |
|
31 | 31 | ); |
32 | 32 | |
33 | -$foo = $_POST['bar']; // Bad x 3. |
|
33 | +$foo = $_POST[ 'bar' ]; // Bad x 3. |
|
34 | 34 | |
35 | 35 | function foo() { |
36 | 36 | // Ok, if WordPress_Sniffs_VIP_ValidatedSanitizedInputSniff::$check_validation_in_scope_only == false . |
37 | - if ( ! isset( $_REQUEST['bar1'] ) || ! foo( sanitize_text_field( wp_unslash( $_REQUEST['bar1'] ) ) ) ) { |
|
37 | + if ( ! isset( $_REQUEST[ 'bar1' ] ) || ! foo( sanitize_text_field( wp_unslash( $_REQUEST[ 'bar1' ] ) ) ) ) { |
|
38 | 38 | wp_die( 1 ); |
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
42 | 42 | // Ok, if WordPress_Sniffs_VIP_ValidatedSanitizedInputSniff::$check_validation_in_scope_only == false . |
43 | -if ( ! isset( $_REQUEST['bar2'] ) || ! foo( sanitize_text_field( wp_unslash( $_REQUEST['bar2'] ) ) ) ) { // Ok. |
|
43 | +if ( ! isset( $_REQUEST[ 'bar2' ] ) || ! foo( sanitize_text_field( wp_unslash( $_REQUEST[ 'bar2' ] ) ) ) ) { // Ok. |
|
44 | 44 | wp_die( 1 ); |
45 | 45 | } |
46 | 46 | |
47 | 47 | function bar() { |
48 | - if ( ! isset( $_GET['test'] ) ) { |
|
49 | - return ; |
|
48 | + if ( ! isset( $_GET[ 'test' ] ) ) { |
|
49 | + return; |
|
50 | 50 | } |
51 | - echo sanitize_text_field( wp_unslash( $_GET['test'] ) ); // Good. |
|
51 | + echo sanitize_text_field( wp_unslash( $_GET[ 'test' ] ) ); // Good. |
|
52 | 52 | } |
53 | 53 | |
54 | -$_REQUEST['wp_customize'] = 'on'; // Ok. |
|
54 | +$_REQUEST[ 'wp_customize' ] = 'on'; // Ok. |
|
55 | 55 | |
56 | 56 | // All OK. |
57 | 57 | $keys = array_keys( $_POST ); |
58 | 58 | $values = array_values( $_POST ); |
59 | -foreach( $_POST as $key => $value ) { |
|
59 | +foreach ( $_POST as $key => $value ) { |
|
60 | 60 | // .. |
61 | 61 | } |
62 | 62 | |
63 | -unset( $_GET['test'] ); // Ok. |
|
63 | +unset( $_GET[ 'test' ] ); // Ok. |
|
64 | 64 | |
65 | -output( "some string {$_POST['some_var']}" ); // Bad. |
|
65 | +output( "some string {$_POST[ 'some_var' ]}" ); // Bad. |
|
66 | 66 | |
67 | -echo (int) $_GET['test']; // Ok. |
|
68 | -some_func( $some_arg, (int) $_GET['test'] ); // Ok. |
|
67 | +echo (int) $_GET[ 'test' ]; // Ok. |
|
68 | +some_func( $some_arg, (int) $_GET[ 'test' ] ); // Ok. |
|
69 | 69 | |
70 | 70 | function zebra() { |
71 | - if ( isset( $_GET['foo'], $_POST['bar'] ) ) { |
|
72 | - echo sanitize_text_field( wp_unslash( $_POST['bar'] ) ); // Ok. |
|
71 | + if ( isset( $_GET[ 'foo' ], $_POST[ 'bar' ] ) ) { |
|
72 | + echo sanitize_text_field( wp_unslash( $_POST[ 'bar' ] ) ); // Ok. |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
76 | -echo $_GET['test']; // WPCS: sanitization OK. |
|
76 | +echo $_GET[ 'test' ]; // WPCS: sanitization OK. |
|
77 | 77 | |
78 | -echo array_map( 'sanitize_text_field', wp_unslash( $_GET['test'] ) ); // Ok. |
|
79 | -echo array_map( 'foo', wp_unslash( $_GET['test'] ) ); // Bad. |
|
80 | -echo array_map( $something, wp_unslash( $_GET['test'] ) ); // Bad. |
|
81 | -echo array_map( array( $obj, 'func' ), wp_unslash( $_GET['test'] ) ); // Bad. |
|
82 | -echo array_map( array( $obj, 'sanitize_text_field' ), wp_unslash( $_GET['test'] ) ); // Bad. |
|
78 | +echo array_map( 'sanitize_text_field', wp_unslash( $_GET[ 'test' ] ) ); // Ok. |
|
79 | +echo array_map( 'foo', wp_unslash( $_GET[ 'test' ] ) ); // Bad. |
|
80 | +echo array_map( $something, wp_unslash( $_GET[ 'test' ] ) ); // Bad. |
|
81 | +echo array_map( array( $obj, 'func' ), wp_unslash( $_GET[ 'test' ] ) ); // Bad. |
|
82 | +echo array_map( array( $obj, 'sanitize_text_field' ), wp_unslash( $_GET[ 'test' ] ) ); // Bad. |
|
83 | 83 | |
84 | 84 | // Sanitized but not validated. |
85 | -$foo = (int) $_POST['foo6']; // Bad. |
|
85 | +$foo = (int) $_POST[ 'foo6' ]; // Bad. |
|
86 | 86 | |
87 | 87 | // Non-assignment checks are OK. |
88 | -if ( 'bar' === $_POST['foo'] ) {} // Ok. |
|
89 | -if ( $_GET['test'] != 'a' ) {} // Ok. |
|
90 | -if ( 'bar' === do_something( wp_unslash( $_POST['foo'] ) ) ) {} // Bad. |
|
88 | +if ( 'bar' === $_POST[ 'foo' ] ) {} // Ok. |
|
89 | +if ( $_GET[ 'test' ] != 'a' ) {} // Ok. |
|
90 | +if ( 'bar' === do_something( wp_unslash( $_POST[ 'foo' ] ) ) ) {} // Bad. |
|
91 | 91 | |
92 | -switch ( $_POST['foo'] ) {} // Ok. |
|
93 | -switch ( do_something( wp_unslash( $_POST['foo'] ) ) ) {} // Bad. |
|
92 | +switch ( $_POST[ 'foo' ] ) {} // Ok. |
|
93 | +switch ( do_something( wp_unslash( $_POST[ 'foo' ] ) ) ) {} // Bad. |
|
94 | 94 | |
95 | 95 | // Sanitization is required even when the value is being escaped. |
96 | -echo esc_html( wp_unslash( $_POST['foo'] ) ); // Bad. |
|
97 | -echo esc_html( sanitize_text_field( wp_unslash( $_POST['foo'] ) ) ); // Ok. |
|
96 | +echo esc_html( wp_unslash( $_POST[ 'foo' ] ) ); // Bad. |
|
97 | +echo esc_html( sanitize_text_field( wp_unslash( $_POST[ 'foo' ] ) ) ); // Ok. |
|
98 | 98 | |
99 | -$current_tax_slug = isset( $_GET['a'] ) ? sanitize_key( $_GET['a'] ) : false; // Ok. |
|
100 | -$current_tax_slug = isset( $_GET['a'] ) ? $_GET['a'] : false; // Bad x 2 |
|
101 | -$current_tax_slug = isset( $_GET['a'] ) ? wp_unslash( $_GET['a'] ) : false; // Bad. |
|
102 | -$current_tax_slug = isset( $_GET['a'] ) ? sanitize_text_field( wp_unslash( $_GET['a'] ) ) : false; // Ok. |
|
99 | +$current_tax_slug = isset( $_GET[ 'a' ] ) ? sanitize_key( $_GET[ 'a' ] ) : false; // Ok. |
|
100 | +$current_tax_slug = isset( $_GET[ 'a' ] ) ? $_GET[ 'a' ] : false; // Bad x 2 |
|
101 | +$current_tax_slug = isset( $_GET[ 'a' ] ) ? wp_unslash( $_GET[ 'a' ] ) : false; // Bad. |
|
102 | +$current_tax_slug = isset( $_GET[ 'a' ] ) ? sanitize_text_field( wp_unslash( $_GET[ 'a' ] ) ) : false; // Ok. |
|
103 | 103 | |
104 | -echo sanitize_text_field( $_POST['foo545'] ); // Error for no validation, unslashing. |
|
105 | -echo array_map( 'sanitize_text_field', $_GET['test'] ); // Bad, no unslashing. |
|
106 | -echo array_map( 'sanitize_key', $_GET['test'] ); // Ok. |
|
104 | +echo sanitize_text_field( $_POST[ 'foo545' ] ); // Error for no validation, unslashing. |
|
105 | +echo array_map( 'sanitize_text_field', $_GET[ 'test' ] ); // Bad, no unslashing. |
|
106 | +echo array_map( 'sanitize_key', $_GET[ 'test' ] ); // Ok. |
|
107 | 107 | |
108 | -foo( absint( $_GET['foo'] ) ); // Ok. |
|
109 | -$ids = array_map( 'absint', $_GET['test'] ); // Ok. |
|
108 | +foo( absint( $_GET[ 'foo' ] ) ); // Ok. |
|
109 | +$ids = array_map( 'absint', $_GET[ 'test' ] ); // Ok. |
|
110 | 110 | |
111 | -if ( is_array( $_GET['test'] ) ) {} // Ok. |
|
111 | +if ( is_array( $_GET[ 'test' ] ) ) {} // Ok. |
|
112 | 112 | |
113 | 113 | output( "some string \$_POST[some_var]" ); // Ok. |
114 | -output( "some string \\$_POST[some_var] $_GET[evil]" ); // Bad x2. |
|
114 | +output( "some string \\$_POST[ some_var ] $_GET[ evil ]" ); // Bad x2. |
@@ -40,7 +40,8 @@ |
||
40 | 40 | } |
41 | 41 | |
42 | 42 | // Ok, if WordPress_Sniffs_VIP_ValidatedSanitizedInputSniff::$check_validation_in_scope_only == false . |
43 | -if ( ! isset( $_REQUEST['bar2'] ) || ! foo( sanitize_text_field( wp_unslash( $_REQUEST['bar2'] ) ) ) ) { // Ok. |
|
43 | +if ( ! isset( $_REQUEST['bar2'] ) || ! foo( sanitize_text_field( wp_unslash( $_REQUEST['bar2'] ) ) ) ) { |
|
44 | +// Ok. |
|
44 | 45 | wp_die( 1 ); |
45 | 46 | } |
46 | 47 |
@@ -18,8 +18,8 @@ |
||
18 | 18 | |
19 | 19 | $query = 'foo=bar&meta_key=foo&meta_value=bar'; |
20 | 20 | |
21 | -if ( ! isset( $widget['params'][0] ) ) { |
|
22 | - $widget['params'][0] = array(); |
|
21 | +if ( ! isset( $widget[ 'params' ][ 0 ] ) ) { |
|
22 | + $widget[ 'params' ][ 0 ] = array(); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 |
@@ -2,6 +2,6 @@ |
||
2 | 2 | |
3 | 3 | add_menu_page( $page_title, $menu_title, $capability, __FILE__, $function, $icon_url, $position ); // Bad. |
4 | 4 | |
5 | -add_dashboard_page( $page_title, $menu_title, $capability, __FILE__, $function); // Bad. |
|
5 | +add_dashboard_page( $page_title, $menu_title, $capability, __FILE__, $function ); // Bad. |
|
6 | 6 | |
7 | 7 | add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, 'awesome-submenu-page', $function ); // Ok. |
@@ -8,6 +8,6 @@ |
||
8 | 8 | |
9 | 9 | _query_posts( 'orderby=rand' ); // Bad. |
10 | 10 | |
11 | -$query_args['orderby'] = 'rand'; // Bad. |
|
11 | +$query_args[ 'orderby' ] = 'rand'; // Bad. |
|
12 | 12 | |
13 | -$query_args['orderby'] = 'date'; // Ok. |
|
13 | +$query_args[ 'orderby' ] = 'date'; // Ok. |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | $posts = get_posts( 'cat=3' ); |
4 | 4 | // Bad, no operator spacing. |
5 | -for ( $i=0; $i<sizeof( $posts ); $i++ ) { |
|
5 | +for ( $i = 0; $i < sizeof( $posts ); $i++ ) { |
|
6 | 6 | // ... |
7 | 7 | } |
8 | 8 | |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | // ... |
16 | 16 | } |
17 | 17 | // Bad. |
18 | -if ( !$var ) { |
|
18 | +if ( ! $var ) { |
|
19 | 19 | // ... |
20 | 20 | } |
21 | 21 | |
@@ -30,22 +30,22 @@ discard block |
||
30 | 30 | // All OK. |
31 | 31 | if ( 'bb' !== 'bb' ) { |
32 | 32 | if ( |
33 | - empty($_GET['refid']) && |
|
34 | - empty($_GET['nolinks']) && |
|
35 | - ! is_page_template('page_strategy-center.php') && |
|
36 | - ! is_page_template('page_confirmation.php') && |
|
37 | - ! is_page_template('page_debartolo.php') && |
|
38 | - ! is_singular('offer') |
|
33 | + empty( $_GET[ 'refid' ] ) && |
|
34 | + empty( $_GET[ 'nolinks' ] ) && |
|
35 | + ! is_page_template( 'page_strategy-center.php' ) && |
|
36 | + ! is_page_template( 'page_confirmation.php' ) && |
|
37 | + ! is_page_template( 'page_debartolo.php' ) && |
|
38 | + ! is_singular( 'offer' ) |
|
39 | 39 | ) { |
40 | 40 | hello(); |
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | 44 | // Bad. |
45 | -for ( $i = 0; $i < sizeof( $posts ); $i++ ) { |
|
45 | +for ( $i = 0; $i < sizeof( $posts ); $i++ ) { |
|
46 | 46 | // ... |
47 | 47 | } |
48 | 48 | // Bad. |
49 | -if ( ! $var ) { |
|
49 | +if ( ! $var ) { |
|
50 | 50 | // ... |
51 | 51 | } |
@@ -1,22 +1,22 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -$array1 = (array)$array; |
|
3 | +$array1 = (array) $array; |
|
4 | 4 | $array2 = (array) $array; |
5 | 5 | |
6 | -$bool1 = (bool)$bool; |
|
6 | +$bool1 = (bool) $bool; |
|
7 | 7 | $bool2 = (bool) $bool; |
8 | 8 | |
9 | -$int1 = (int)$int; |
|
9 | +$int1 = (int) $int; |
|
10 | 10 | $int2 = (int) $int; |
11 | 11 | |
12 | -$obj1 = ( object )$object; |
|
12 | +$obj1 = (object) $object; |
|
13 | 13 | $obj2 = (object) $object; |
14 | 14 | |
15 | -$str1 = (string)$string; |
|
15 | +$str1 = (string) $string; |
|
16 | 16 | $str2 = (string) $string; |
17 | 17 | |
18 | -$unset1 = (unset)$unset; |
|
18 | +$unset1 = (unset) $unset; |
|
19 | 19 | $unset2 = (unset) $unset; |
20 | 20 | |
21 | -$float1 = (float)$float; |
|
21 | +$float1 = (float) $float; |
|
22 | 22 | $float2 = (float) $float; |
@@ -30,11 +30,11 @@ |
||
30 | 30 | |
31 | 31 | |
32 | 32 | if ( true ) { |
33 | - while ( false ) { |
|
33 | + while ( false ) { |
|
34 | 34 | |
35 | - echo 'OK'; |
|
35 | + echo 'OK'; |
|
36 | 36 | |
37 | - } |
|
37 | + } |
|
38 | 38 | |
39 | 39 | } |
40 | 40 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Bad, no space after opening control structure. |
4 | -while( have_posts() ) { // Okay, comments are okay here. |
|
4 | +while ( have_posts() ) { // Okay, comments are okay here. |
|
5 | 5 | // Okay, comments are okay here as well. |
6 | 6 | } // Okay, comments are okay here. |
7 | 7 | |
@@ -14,19 +14,19 @@ discard block |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | // Bad. |
17 | -if ( 'update' === $option_operation['operation'] ) |
|
17 | +if ( 'update' === $option_operation[ 'operation' ] ) |
|
18 | 18 | { |
19 | - update_option( $option_operation['option_name'], $option_operation['old_value'] ); |
|
19 | + update_option( $option_operation[ 'option_name' ], $option_operation[ 'old_value' ] ); |
|
20 | 20 | |
21 | 21 | } |
22 | 22 | |
23 | 23 | // Good. |
24 | -if ( 'update' === $option_operation['operation'] ) { |
|
25 | - update_option( $option_operation['option_name'], $option_operation['old_value'] ); |
|
24 | +if ( 'update' === $option_operation[ 'operation' ] ) { |
|
25 | + update_option( $option_operation[ 'option_name' ], $option_operation[ 'old_value' ] ); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | // Bad. |
29 | -if(true){} |
|
29 | +if ( true ) {} |
|
30 | 30 | |
31 | 31 | |
32 | 32 | if ( true ) { |
@@ -46,16 +46,16 @@ discard block |
||
46 | 46 | else : |
47 | 47 | endif; |
48 | 48 | // @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 |
49 | -function($arg){} // Bad. |
|
50 | -function ( $arg ) { |
|
49 | +function( $arg ) {} // Bad. |
|
50 | +function( $arg ) { |
|
51 | 51 | // Ok. |
52 | 52 | } |
53 | 53 | |
54 | -function () { |
|
54 | +function() { |
|
55 | 55 | // Ok. |
56 | 56 | } |
57 | 57 | |
58 | -function something($arg){} // Bad. |
|
58 | +function something( $arg ) {} // Bad. |
|
59 | 59 | function foo( $arg ) { |
60 | 60 | // Ok. |
61 | 61 | } |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | // Ok. |
65 | 65 | } |
66 | 66 | |
67 | -function another () {} // Bad, space before open parenthesis prohibited. |
|
67 | +function another() {} // Bad, space before open parenthesis prohibited. |
|
68 | 68 | function and_another() {} // Bad, space before function name prohibited. |
69 | 69 | function |
70 | 70 | bar() {} // Bad. |
71 | -function baz() {} // Bad. |
|
71 | +function baz() {} // Bad. |
|
72 | 72 | function test() |
73 | 73 | {} // Bad. |
74 | 74 | |
@@ -78,24 +78,24 @@ discard block |
||
78 | 78 | |
79 | 79 | function() {} // Ok. |
80 | 80 | function( $arg ) {} // Ok. |
81 | -function($arg){} // Bad. |
|
82 | -function () {} // Bad. |
|
81 | +function( $arg ) {} // Bad. |
|
82 | +function() {} // Bad. |
|
83 | 83 | |
84 | 84 | $closureWithArgsAndVars = function( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Ok. |
85 | -$closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Bad. |
|
85 | +$closureWithArgsAndVars = function( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Bad. |
|
86 | 86 | |
87 | 87 | // @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 |
88 | 88 | |
89 | -$closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Ok. |
|
89 | +$closureWithArgsAndVars = function( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Ok. |
|
90 | 90 | |
91 | -$closureWithArgsAndVars = function ( $arg1, $arg2 ) use( $var1, $var2 ) {}; // Bad, no space before open parenthesis prohibited. |
|
92 | -$closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Bad, expected exactly one space before opening parenthesis. |
|
91 | +$closureWithArgsAndVars = function( $arg1, $arg2 ) use( $var1, $var2 ) {}; // Bad, no space before open parenthesis prohibited. |
|
92 | +$closureWithArgsAndVars = function( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Bad, expected exactly one space before opening parenthesis. |
|
93 | 93 | |
94 | -$closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ){}; // Bad, space between closing parenthesis and control structure required. |
|
95 | -$closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Bad, expected exactly one space between closing parenthesis and control structure. |
|
94 | +$closureWithArgsAndVars = function( $arg1, $arg2 ) use ( $var1, $var2 ){}; // Bad, space between closing parenthesis and control structure required. |
|
95 | +$closureWithArgsAndVars = function( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Bad, expected exactly one space between closing parenthesis and control structure. |
|
96 | 96 | |
97 | -$closureWithArgsAndVars = function ( $arg1, $arg2 )use ( $var1, $var2 ) {}; // Bad, expected exactly one space between closing parenthesis and control structure. |
|
98 | -$closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Bad, expected exactly one space between closing parenthesis and control structure. |
|
97 | +$closureWithArgsAndVars = function( $arg1, $arg2 )use ( $var1, $var2 ) {}; // Bad, expected exactly one space between closing parenthesis and control structure. |
|
98 | +$closureWithArgsAndVars = function( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Bad, expected exactly one space between closing parenthesis and control structure. |
|
99 | 99 | |
100 | 100 | // Namespaces. |
101 | 101 | use Foo\Admin; |
@@ -103,10 +103,10 @@ discard block |
||
103 | 103 | // @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren -1 |
104 | 104 | |
105 | 105 | function( $arg ) {} // Ok. |
106 | -function ( $arg ) {} // Ok. |
|
106 | +function( $arg ) {} // Ok. |
|
107 | 107 | |
108 | 108 | $closureWithArgsAndVars = function( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Ok. |
109 | -$closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Ok. |
|
109 | +$closureWithArgsAndVars = function( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Ok. |
|
110 | 110 | |
111 | 111 | /** |
112 | 112 | * Test for bug where this sniff was triggering a "Blank line found after control structure" error |
@@ -1,7 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Bad, no space after opening control structure. |
4 | -while( have_posts() ) { // Okay, comments are okay here. |
|
4 | +while( have_posts() ) { |
|
5 | +// Okay, comments are okay here. |
|
5 | 6 | // Okay, comments are okay here as well. |
6 | 7 | } // Okay, comments are okay here. |
7 | 8 | |
@@ -9,13 +10,13 @@ discard block |
||
9 | 10 | if ( true ) { |
10 | 11 | |
11 | 12 | // code. |
12 | -} else { // Are we allowed to comment here? If not, message is wrong. |
|
13 | +} else { |
|
14 | +// Are we allowed to comment here? If not, message is wrong. |
|
13 | 15 | // ... |
14 | 16 | } |
15 | 17 | |
16 | 18 | // Bad. |
17 | -if ( 'update' === $option_operation['operation'] ) |
|
18 | -{ |
|
19 | +if ( 'update' === $option_operation['operation'] ) { |
|
19 | 20 | update_option( $option_operation['option_name'], $option_operation['old_value'] ); |
20 | 21 | |
21 | 22 | } |
@@ -39,12 +40,16 @@ discard block |
||
39 | 40 | } |
40 | 41 | |
41 | 42 | if ( false ): |
42 | -else: |
|
43 | +else { |
|
44 | + : |
|
43 | 45 | endif; |
46 | +} |
|
44 | 47 | |
45 | 48 | if ( false ) : |
46 | -else : |
|
49 | +else { |
|
50 | + : |
|
47 | 51 | endif; |
52 | +} |
|
48 | 53 | // @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 |
49 | 54 | function($arg){} // Bad. |
50 | 55 | function ( $arg ) { |
@@ -20,6 +20,6 @@ |
||
20 | 20 | |
21 | 21 | FOO::$static; // Matches: 'FOO::$static'. |
22 | 22 | |
23 | -$foo['test']; // Matches: '$foo['test']'. |
|
23 | +$foo[ 'test' ]; // Matches: '$foo['test']'. |
|
24 | 24 | |
25 | -$foo["test"]; // Matches: '$foo['test']' AND $foo['test']. |
|
25 | +$foo[ "test" ]; // Matches: '$foo['test']' AND $foo['test']. |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -$GLOBALS['wpdb'] = 'test'; |
|
3 | +$GLOBALS[ 'wpdb' ] = 'test'; |
|
4 | 4 | |
5 | 5 | global $wpdb; |
6 | 6 | $wpdb = 'test'; |