@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Contract; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | 6 | * |
@@ -12,12 +12,12 @@ discard block |
||
| 12 | 12 | /** |
| 13 | 13 | * @return bool |
| 14 | 14 | */ |
| 15 | - public function contains( $key = null, $value = null ); |
|
| 15 | + public function contains($key = null, $value = null); |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * @return bool |
| 19 | 19 | */ |
| 20 | - public function has( $key = null ); |
|
| 20 | + public function has($key = null); |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * @return bool |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * @return string|null |
| 29 | 29 | */ |
| 30 | - public function escape( $key, callable $callback = null ); |
|
| 30 | + public function escape($key, callable $callback = null); |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * @return |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * @access private |
| 109 | 109 | * |
| 110 | 110 | * @param array $array |
| 111 | - * @param string|array $callback |
|
| 111 | + * @param callable $callback |
|
| 112 | 112 | * @return array |
| 113 | 113 | */ |
| 114 | 114 | protected function transform_array_leafs( array $array, $callback ) { |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * @since 0.10.0 |
| 125 | 125 | * @access private |
| 126 | 126 | * |
| 127 | - * @param string|array $callback |
|
| 127 | + * @param callable $callback |
|
| 128 | 128 | * @param string (optional) $input The input string |
| 129 | 129 | * @return |
| 130 | 130 | */ |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Abstraction; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Contract\CollectionInterface; |
| 6 | 6 | |
@@ -29,11 +29,11 @@ discard block |
||
| 29 | 29 | * @param string $value |
| 30 | 30 | * @return bool |
| 31 | 31 | */ |
| 32 | - public function contains( $key = null, $value = null ) { |
|
| 33 | - if( $this->has( $key ) ) { |
|
| 34 | - return ( is_array( $this->data[ $key ] ) ) |
|
| 35 | - ? in_array( $value, $this->data[ $key ] ) |
|
| 36 | - : $this->data[ $key ] === $value; |
|
| 32 | + public function contains($key = null, $value = null) { |
|
| 33 | + if ($this->has($key)) { |
|
| 34 | + return (is_array($this->data[$key])) |
|
| 35 | + ? in_array($value, $this->data[$key]) |
|
| 36 | + : $this->data[$key] === $value; |
|
| 37 | 37 | } |
| 38 | 38 | return false; |
| 39 | 39 | } |
@@ -47,10 +47,10 @@ discard block |
||
| 47 | 47 | * @param string|array (optional) $callback Context appropriate callable. |
| 48 | 48 | * @return string|null |
| 49 | 49 | */ |
| 50 | - public function escape( $key, callable $callback = null ) { |
|
| 51 | - if( is_string( $key ) ) { |
|
| 52 | - $callback = ( null === $callback ) ? 'esc_html' : $callback; |
|
| 53 | - return ( true === $this->has( $key ) ) ? $this->call_func( $callback, $this->data[ $key ] ) : null; |
|
| 50 | + public function escape($key, callable $callback = null) { |
|
| 51 | + if (is_string($key)) { |
|
| 52 | + $callback = (null === $callback) ? 'esc_html' : $callback; |
|
| 53 | + return (true === $this->has($key)) ? $this->call_func($callback, $this->data[$key]) : null; |
|
| 54 | 54 | } |
| 55 | 55 | return null; |
| 56 | 56 | } |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | * @param string $key |
| 64 | 64 | * @return bool |
| 65 | 65 | */ |
| 66 | - public function has( $key = null ) { |
|
| 67 | - return array_key_exists( $key, $this->data ); |
|
| 66 | + public function has($key = null) { |
|
| 67 | + return array_key_exists($key, $this->data); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @return bool |
| 76 | 76 | */ |
| 77 | 77 | public function is_populated() { |
| 78 | - return count( $this->data ) > 0; |
|
| 78 | + return count($this->data) > 0; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -88,11 +88,11 @@ discard block |
||
| 88 | 88 | * @param callable $callback |
| 89 | 89 | * @return array |
| 90 | 90 | */ |
| 91 | - public function transform( $key = null, callable $callback ) { |
|
| 91 | + public function transform($key = null, callable $callback) { |
|
| 92 | 92 | // WIP |
| 93 | - if( true === $this->has( $key ) ) { |
|
| 94 | - if( is_array( $this->data[ $key ] ) ) { |
|
| 95 | - return $this->transform_array_leafs( $this->data[ $key ], $callback ); |
|
| 93 | + if (true === $this->has($key)) { |
|
| 94 | + if (is_array($this->data[$key])) { |
|
| 95 | + return $this->transform_array_leafs($this->data[$key], $callback); |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -109,9 +109,9 @@ discard block |
||
| 109 | 109 | * @param string|array $callback |
| 110 | 110 | * @return array |
| 111 | 111 | */ |
| 112 | - protected function transform_array_leafs( array $array, $callback ) { |
|
| 113 | - array_walk_recursive( $array, function( &$item ) use( $callback ) { |
|
| 114 | - $item = $this->call_func( $callback, $item ); |
|
| 112 | + protected function transform_array_leafs(array $array, $callback) { |
|
| 113 | + array_walk_recursive($array, function(&$item) use($callback) { |
|
| 114 | + $item = $this->call_func($callback, $item); |
|
| 115 | 115 | } ); |
| 116 | 116 | return $array; |
| 117 | 117 | } |
@@ -126,16 +126,16 @@ discard block |
||
| 126 | 126 | * @param string (optional) $input The input string |
| 127 | 127 | * @return |
| 128 | 128 | */ |
| 129 | - private function call_func( $callback, $input = null ) { |
|
| 129 | + private function call_func($callback, $input = null) { |
|
| 130 | 130 | // WIP - simplify |
| 131 | - if( is_array( $callback ) ) { |
|
| 131 | + if (is_array($callback)) { |
|
| 132 | 132 | $method = $callback[0]; |
| 133 | 133 | $args = $callback[1]; |
| 134 | - if ( $input ) { |
|
| 135 | - array_unshift( $args, $input ); |
|
| 134 | + if ($input) { |
|
| 135 | + array_unshift($args, $input); |
|
| 136 | 136 | } |
| 137 | - return call_user_func_array( $method, $args ); |
|
| 137 | + return call_user_func_array($method, $args); |
|
| 138 | 138 | } |
| 139 | - return $callback( $input ); |
|
| 139 | + return $callback($input); |
|
| 140 | 140 | } |
| 141 | 141 | } |
@@ -143,7 +143,7 @@ |
||
| 143 | 143 | * @access protected |
| 144 | 144 | * |
| 145 | 145 | * @param string $rule |
| 146 | - * @return bool |
|
| 146 | + * @return integer |
|
| 147 | 147 | */ |
| 148 | 148 | protected function string_has_params( $rule ) { |
| 149 | 149 | return strpos( $rule, ':' ); |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Collection; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Abstraction\Collectable; |
| 6 | 6 | |
@@ -18,8 +18,8 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @param array $form |
| 20 | 20 | */ |
| 21 | - public function __construct( array $form ) { |
|
| 22 | - $this->data = $this->parse_rules( $form ); |
|
| 21 | + public function __construct(array $form) { |
|
| 22 | + $this->data = $this->parse_rules($form); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -32,8 +32,8 @@ discard block |
||
| 32 | 32 | * @param bool (optional) $flat |
| 33 | 33 | * @return array |
| 34 | 34 | */ |
| 35 | - public function get_array( $flat = false ) { |
|
| 36 | - return ( $flat ) ? $this->remove_params() : $this->data; |
|
| 35 | + public function get_array($flat = false) { |
|
| 36 | + return ($flat) ? $this->remove_params() : $this->data; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -45,9 +45,9 @@ discard block |
||
| 45 | 45 | * @param int $index |
| 46 | 46 | * @return array|bool |
| 47 | 47 | */ |
| 48 | - public function get_params( $field, $index ) { |
|
| 49 | - return ( $this->has_params( $field, $index ) ) |
|
| 50 | - ? $this->data[ $field ][ $index ]['params'] |
|
| 48 | + public function get_params($field, $index) { |
|
| 49 | + return ($this->has_params($field, $index)) |
|
| 50 | + ? $this->data[$field][$index]['params'] |
|
| 51 | 51 | : false; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -59,9 +59,9 @@ discard block |
||
| 59 | 59 | * @param string $field |
| 60 | 60 | * @return bool |
| 61 | 61 | */ |
| 62 | - public function is_optional( $field ) { |
|
| 63 | - if( $this->has( $field ) ){ |
|
| 64 | - return in_array('optional', $this->data[ $field ] ); |
|
| 62 | + public function is_optional($field) { |
|
| 63 | + if ($this->has($field)) { |
|
| 64 | + return in_array('optional', $this->data[$field]); |
|
| 65 | 65 | } |
| 66 | 66 | return false; |
| 67 | 67 | } |
@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | * @return array |
| 75 | 75 | */ |
| 76 | 76 | public function unique() { |
| 77 | - $flat = $this->flatten( $this->remove_params() ); |
|
| 78 | - return array_values( array_unique( $flat ) ); |
|
| 77 | + $flat = $this->flatten($this->remove_params()); |
|
| 78 | + return array_values(array_unique($flat)); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | * @param string $rule |
| 88 | 88 | * @return string |
| 89 | 89 | */ |
| 90 | - protected function extract_name( $rule ) { |
|
| 91 | - return strstr( $rule, ':', true ); |
|
| 90 | + protected function extract_name($rule) { |
|
| 91 | + return strstr($rule, ':', true); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -100,8 +100,8 @@ discard block |
||
| 100 | 100 | * @param string $rule |
| 101 | 101 | * @return string |
| 102 | 102 | */ |
| 103 | - protected function extract_params( $rule ) { |
|
| 104 | - return ltrim( strstr($rule, ':'), ':'); |
|
| 103 | + protected function extract_params($rule) { |
|
| 104 | + return ltrim(strstr($rule, ':'), ':'); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -113,9 +113,9 @@ discard block |
||
| 113 | 113 | * @param array $form |
| 114 | 114 | * @return array |
| 115 | 115 | */ |
| 116 | - protected function extract_rules( array $form ) { |
|
| 117 | - foreach( $form as $field => $options ) { |
|
| 118 | - $rules[ $field ] = $options['rules']; |
|
| 116 | + protected function extract_rules(array $form) { |
|
| 117 | + foreach ($form as $field => $options) { |
|
| 118 | + $rules[$field] = $options['rules']; |
|
| 119 | 119 | } |
| 120 | 120 | return $rules; |
| 121 | 121 | } |
@@ -129,11 +129,11 @@ discard block |
||
| 129 | 129 | * @param array $array |
| 130 | 130 | * @return array |
| 131 | 131 | */ |
| 132 | - protected function flatten( array $array ) { |
|
| 132 | + protected function flatten(array $array) { |
|
| 133 | 133 | $flat = array(); |
| 134 | - foreach( $array as $rule ) { |
|
| 135 | - if( is_array( $rule ) ){ |
|
| 136 | - $flat = array_merge( $flat, $this->flatten( $rule ) ); |
|
| 134 | + foreach ($array as $rule) { |
|
| 135 | + if (is_array($rule)) { |
|
| 136 | + $flat = array_merge($flat, $this->flatten($rule)); |
|
| 137 | 137 | } else { |
| 138 | 138 | $flat[] = $rule; |
| 139 | 139 | } |
@@ -151,8 +151,8 @@ discard block |
||
| 151 | 151 | * @param int $index |
| 152 | 152 | * @return bool |
| 153 | 153 | */ |
| 154 | - protected function has_params( $field, $index ) { |
|
| 155 | - return is_array( $this->data[ $field ][ $index ] ); |
|
| 154 | + protected function has_params($field, $index) { |
|
| 155 | + return is_array($this->data[$field][$index]); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
@@ -165,22 +165,22 @@ discard block |
||
| 165 | 165 | * @param array $form |
| 166 | 166 | * @return array |
| 167 | 167 | */ |
| 168 | - protected function parse_rules( array $form ) { |
|
| 168 | + protected function parse_rules(array $form) { |
|
| 169 | 169 | // WIP - works, but confusing - simplify or breakdown into small methods |
| 170 | - $rules = $this->extract_rules( $form ); |
|
| 170 | + $rules = $this->extract_rules($form); |
|
| 171 | 171 | |
| 172 | 172 | $parsed = array(); |
| 173 | - $this->split_rules( $rules ); |
|
| 174 | - foreach( $rules as $field => $ruleset ) { |
|
| 175 | - $parsed[ $field ] = array_map( function( $rule ) { |
|
| 176 | - if ( $this->string_has_params( $rule ) ) { |
|
| 173 | + $this->split_rules($rules); |
|
| 174 | + foreach ($rules as $field => $ruleset) { |
|
| 175 | + $parsed[$field] = array_map(function($rule) { |
|
| 176 | + if ($this->string_has_params($rule)) { |
|
| 177 | 177 | return array( |
| 178 | - 'rule' => $this->extract_name( $rule ), |
|
| 179 | - 'params' => explode( ',', $this->extract_params( $rule ) ) |
|
| 178 | + 'rule' => $this->extract_name($rule), |
|
| 179 | + 'params' => explode(',', $this->extract_params($rule)) |
|
| 180 | 180 | ); |
| 181 | 181 | } |
| 182 | 182 | return $rule; |
| 183 | - }, $ruleset ); |
|
| 183 | + }, $ruleset); |
|
| 184 | 184 | } |
| 185 | 185 | return $parsed; |
| 186 | 186 | } |
@@ -195,14 +195,14 @@ discard block |
||
| 195 | 195 | * @return array |
| 196 | 196 | */ |
| 197 | 197 | protected function remove_params() { |
| 198 | - return array_map( function( $item ) { |
|
| 199 | - foreach( $item as $index => $rule ) { |
|
| 200 | - if( $rule !== 'optional' ) { |
|
| 201 | - $rules[ $index ] = ( is_string( $rule ) ) ? $rule : $rule['rule']; |
|
| 198 | + return array_map(function($item) { |
|
| 199 | + foreach ($item as $index => $rule) { |
|
| 200 | + if ($rule !== 'optional') { |
|
| 201 | + $rules[$index] = (is_string($rule)) ? $rule : $rule['rule']; |
|
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | return $rules; |
| 205 | - }, $this->data ); |
|
| 205 | + }, $this->data); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -213,11 +213,11 @@ discard block |
||
| 213 | 213 | * |
| 214 | 214 | * @param array $rules |
| 215 | 215 | */ |
| 216 | - protected function split_rules( array &$rules ) { |
|
| 216 | + protected function split_rules(array &$rules) { |
|
| 217 | 217 | // perhaps the $rules array structure should be validated here?... |
| 218 | - $rules = array_map( function( $item ) { |
|
| 219 | - return explode( '|', $item ); |
|
| 220 | - }, $rules ); |
|
| 218 | + $rules = array_map(function($item) { |
|
| 219 | + return explode('|', $item); |
|
| 220 | + }, $rules); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | * @param string $rule |
| 230 | 230 | * @return bool |
| 231 | 231 | */ |
| 232 | - protected function string_has_params( $rule ) { |
|
| 233 | - return strpos( $rule, ':' ); |
|
| 232 | + protected function string_has_params($rule) { |
|
| 233 | + return strpos($rule, ':'); |
|
| 234 | 234 | } |
| 235 | 235 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Contract; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -14,5 +14,5 @@ discard block |
||
| 14 | 14 | /** |
| 15 | 15 | * @return bool |
| 16 | 16 | */ |
| 17 | - public function validate( $input = null, $optional = false ); |
|
| 17 | + public function validate($input = null, $optional = false); |
|
| 18 | 18 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Collection; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Abstraction\Collectable; |
| 6 | 6 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @param array $labels Human friendly labels for the fields |
| 28 | 28 | */ |
| 29 | - function __construct( array $labels = [] ) { |
|
| 29 | + function __construct(array $labels = []) { |
|
| 30 | 30 | $this->labels = $labels; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | * @param string $field |
| 39 | 39 | * @return string|null |
| 40 | 40 | */ |
| 41 | - public function first( $field ) { |
|
| 42 | - return ( isset( $this->data[ $field ] ) ) |
|
| 43 | - ? array_values( $this->data[ $field ] )[0] |
|
| 41 | + public function first($field) { |
|
| 42 | + return (isset($this->data[$field])) |
|
| 43 | + ? array_values($this->data[$field])[0] |
|
| 44 | 44 | : null; |
| 45 | 45 | } |
| 46 | 46 | |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | * @param string $field |
| 53 | 53 | * @return array|null |
| 54 | 54 | */ |
| 55 | - public function get( $field ) { |
|
| 56 | - return ( isset( $this->data[ $field ] ) ) |
|
| 57 | - ? $this->data[ $field ] |
|
| 55 | + public function get($field) { |
|
| 56 | + return (isset($this->data[$field])) |
|
| 57 | + ? $this->data[$field] |
|
| 58 | 58 | : null; |
| 59 | 59 | } |
| 60 | 60 | |
@@ -66,10 +66,10 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @param array $errors |
| 68 | 68 | */ |
| 69 | - public function set_errors( array $errors = [] ) { |
|
| 70 | - $this->data = ( $this->is_populated() ) |
|
| 69 | + public function set_errors(array $errors = []) { |
|
| 70 | + $this->data = ($this->is_populated()) |
|
| 71 | 71 | ? $this->data |
| 72 | - : $this->with_labels( $errors ); |
|
| 72 | + : $this->with_labels($errors); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -82,9 +82,9 @@ discard block |
||
| 82 | 82 | * @param string $field |
| 83 | 83 | * @return string |
| 84 | 84 | */ |
| 85 | - protected function label( $field ) { |
|
| 86 | - return ( isset( $this->labels[ $field ] ) ) |
|
| 87 | - ? $this->labels[ $field ] |
|
| 85 | + protected function label($field) { |
|
| 86 | + return (isset($this->labels[$field])) |
|
| 87 | + ? $this->labels[$field] |
|
| 88 | 88 | : $field; |
| 89 | 89 | } |
| 90 | 90 | |
@@ -97,11 +97,11 @@ discard block |
||
| 97 | 97 | * @param array $errors |
| 98 | 98 | * @return array |
| 99 | 99 | */ |
| 100 | - protected function with_labels( $errors ) { |
|
| 100 | + protected function with_labels($errors) { |
|
| 101 | 101 | $labeled = array(); |
| 102 | - foreach( $errors as $field => $messages ) { |
|
| 103 | - $label = $this->label( $field ); |
|
| 104 | - $labeled[ $field ] = str_replace( '{label}', $label, $errors[ $field ] ); |
|
| 102 | + foreach ($errors as $field => $messages) { |
|
| 103 | + $label = $this->label($field); |
|
| 104 | + $labeled[$field] = str_replace('{label}', $label, $errors[$field]); |
|
| 105 | 105 | } |
| 106 | 106 | return $labeled; |
| 107 | 107 | } |
@@ -26,7 +26,6 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @since 0.10.0 |
| 28 | 28 | * |
| 29 | - * @param array $data |
|
| 30 | 29 | * @param bool $trim |
| 31 | 30 | */ |
| 32 | 31 | public function __construct( InspectionAgent $guard, $trim = true ) { |
@@ -67,6 +66,7 @@ discard block |
||
| 67 | 66 | * @since 0.11.0 |
| 68 | 67 | * @access protected |
| 69 | 68 | * |
| 69 | + * @param boolean $trim |
|
| 70 | 70 | */ |
| 71 | 71 | protected function populate( $trim ) { |
| 72 | 72 | if( $this->guard->safe_submit() ) { |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Collection; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Abstraction\Collectable; |
| 6 | 6 | use WFV\Agent\InspectionAgent; |
@@ -29,9 +29,9 @@ discard block |
||
| 29 | 29 | * @param array $data |
| 30 | 30 | * @param bool $trim |
| 31 | 31 | */ |
| 32 | - public function __construct( InspectionAgent $guard, $trim = true ) { |
|
| 32 | + public function __construct(InspectionAgent $guard, $trim = true) { |
|
| 33 | 33 | $this->guard = $guard; |
| 34 | - $this->populate( $trim ); |
|
| 34 | + $this->populate($trim); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | * @param bool $neat With or without token and action attributes. |
| 43 | 43 | * @return array |
| 44 | 44 | */ |
| 45 | - public function get_array( $neat = true ) { |
|
| 46 | - return ( $neat ) ? $this->neat_array() : $this->data; |
|
| 45 | + public function get_array($neat = true) { |
|
| 46 | + return ($neat) ? $this->neat_array() : $this->data; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | protected function neat_array() { |
| 58 | 58 | $input = $this->data; |
| 59 | - unset( $input[ $input['action'] .'_token'] ); |
|
| 60 | - unset( $input['action'] ); |
|
| 59 | + unset($input[$input['action'].'_token']); |
|
| 60 | + unset($input['action']); |
|
| 61 | 61 | return $input; |
| 62 | 62 | } |
| 63 | 63 | |
@@ -68,12 +68,12 @@ discard block |
||
| 68 | 68 | * @access protected |
| 69 | 69 | * |
| 70 | 70 | */ |
| 71 | - protected function populate( $trim ) { |
|
| 72 | - if( $this->guard->safe_submit() ) { |
|
| 73 | - $data = $this->transform_array_leafs( $_POST, 'stripslashes' ); |
|
| 71 | + protected function populate($trim) { |
|
| 72 | + if ($this->guard->safe_submit()) { |
|
| 73 | + $data = $this->transform_array_leafs($_POST, 'stripslashes'); |
|
| 74 | 74 | |
| 75 | - $this->data = ( $trim ) |
|
| 76 | - ? $this->transform_array_leafs( $data, 'trim' ) |
|
| 75 | + $this->data = ($trim) |
|
| 76 | + ? $this->transform_array_leafs($data, 'trim') |
|
| 77 | 77 | : $data; |
| 78 | 78 | } |
| 79 | 79 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Agent; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @param string $action |
| 28 | 28 | */ |
| 29 | - public function __construct( $action ) { |
|
| 29 | + public function __construct($action) { |
|
| 30 | 30 | $this->action = $action; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -40,8 +40,8 @@ discard block |
||
| 40 | 40 | * @return bool |
| 41 | 41 | */ |
| 42 | 42 | public function safe_submit() { |
| 43 | - if( $this->submit_has_action() ) { |
|
| 44 | - return ( $_POST['action'] === $this->action ) ? $this->nonce() : false; |
|
| 43 | + if ($this->submit_has_action()) { |
|
| 44 | + return ($_POST['action'] === $this->action) ? $this->nonce() : false; |
|
| 45 | 45 | } |
| 46 | 46 | return false; |
| 47 | 47 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @return bool |
| 55 | 55 | */ |
| 56 | 56 | private function submit_has_action() { |
| 57 | - return isset( $_POST['action'] ); |
|
| 57 | + return isset($_POST['action']); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | * @return bool |
| 67 | 67 | */ |
| 68 | 68 | private function nonce() { |
| 69 | - $nonce = $_REQUEST[ $this->action.'_token' ]; |
|
| 70 | - return ( wp_verify_nonce( $nonce, $this->action ) ) ? true : false; |
|
| 69 | + $nonce = $_REQUEST[$this->action.'_token']; |
|
| 70 | + return (wp_verify_nonce($nonce, $this->action)) ? true : false; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Rules; |
| 6 | 6 | |
@@ -28,12 +28,12 @@ discard block |
||
| 28 | 28 | * @param string $rule |
| 29 | 29 | * @return ValidateInterface|bool |
| 30 | 30 | */ |
| 31 | - public function get( $rule ) { |
|
| 32 | - if ( !isset( $this->pool[ $rule ] ) ) { |
|
| 33 | - $class = $this->class_name( $rule ); |
|
| 34 | - $this->pool[ $rule ] = new $class(); |
|
| 31 | + public function get($rule) { |
|
| 32 | + if (!isset($this->pool[$rule])) { |
|
| 33 | + $class = $this->class_name($rule); |
|
| 34 | + $this->pool[$rule] = new $class(); |
|
| 35 | 35 | } |
| 36 | - return $this->pool[ $rule ]; |
|
| 36 | + return $this->pool[$rule]; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | * @param string $rule |
| 46 | 46 | * @return string |
| 47 | 47 | */ |
| 48 | - protected function class_name( $rule ){ |
|
| 49 | - $name = str_replace(' ', '', ucwords( str_replace('_', ' ', $rule ) ) ); |
|
| 48 | + protected function class_name($rule) { |
|
| 49 | + $name = str_replace(' ', '', ucwords(str_replace('_', ' ', $rule))); |
|
| 50 | 50 | return 'WFV\Rules\\'.$name; |
| 51 | 51 | } |
| 52 | 52 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Rules; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Rules\AbstractRule; |
| 6 | 6 | |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | * @param bool (optional) $optional |
| 33 | 33 | * @return bool |
| 34 | 34 | */ |
| 35 | - public function validate( $input = null, $optional = false ) { |
|
| 35 | + public function validate($input = null, $optional = false) { |
|
| 36 | 36 | $v = $this->validator->create(); |
| 37 | - return ( $optional ) |
|
| 38 | - ? $v->optional( $v->create()->boolVal() )->validate( $input ) |
|
| 39 | - : $v->boolVal()->validate( $input ); |
|
| 37 | + return ($optional) |
|
| 38 | + ? $v->optional($v->create()->boolVal())->validate($input) |
|
| 39 | + : $v->boolVal()->validate($input); |
|
| 40 | 40 | } |
| 41 | 41 | } |