@@ -86,7 +86,6 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @since 0.10.0 |
| 88 | 88 | * |
| 89 | - * @param string|array $value |
|
| 90 | 89 | * @param string $callback |
| 91 | 90 | * @return string|array |
| 92 | 91 | */ |
@@ -108,7 +107,7 @@ discard block |
||
| 108 | 107 | * @access private |
| 109 | 108 | * |
| 110 | 109 | * @param array $array |
| 111 | - * @param string|array $callback |
|
| 110 | + * @param callable $callback |
|
| 112 | 111 | * @return array |
| 113 | 112 | */ |
| 114 | 113 | protected function transform_array_leafs( array $array, $callback ) { |
@@ -124,7 +123,7 @@ discard block |
||
| 124 | 123 | * @since 0.10.0 |
| 125 | 124 | * @access private |
| 126 | 125 | * |
| 127 | - * @param string|array $callback |
|
| 126 | + * @param callable $callback |
|
| 128 | 127 | * @param string (optional) $input The input string |
| 129 | 128 | * @return |
| 130 | 129 | */ |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Abstraction; |
| 3 | -defined( 'ABSPATH' ) or die(); |
|
| 3 | +defined('ABSPATH') or die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Contract\CollectionInterface; |
| 6 | 6 | |
@@ -27,13 +27,13 @@ discard block |
||
| 27 | 27 | * |
| 28 | 28 | * @return bool |
| 29 | 29 | */ |
| 30 | - public function contains( $key = null, $value = null ) { |
|
| 30 | + public function contains($key = null, $value = null) { |
|
| 31 | 31 | // WIP |
| 32 | - if( $this->has( $key ) ) { |
|
| 33 | - if ( is_array( $this->data[ $key ] ) ) { |
|
| 34 | - return ( in_array( $value, $this->data[ $key ] ) ) ? true : false; |
|
| 32 | + if ($this->has($key)) { |
|
| 33 | + if (is_array($this->data[$key])) { |
|
| 34 | + return (in_array($value, $this->data[$key])) ? true : false; |
|
| 35 | 35 | } |
| 36 | - return ( $this->data[ $key ] === $value ) ? true : false; |
|
| 36 | + return ($this->data[$key] === $value) ? true : false; |
|
| 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,10 +63,10 @@ discard block |
||
| 63 | 63 | * @param string $key |
| 64 | 64 | * @return bool |
| 65 | 65 | */ |
| 66 | - public function has( $key = null ) { |
|
| 66 | + public function has($key = null) { |
|
| 67 | 67 | /*array_walk( $this->data, function( $item, $key ) { |
| 68 | 68 | });*/ |
| 69 | - return array_key_exists( $key, $this->data ); |
|
| 69 | + return array_key_exists($key, $this->data); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * @return bool |
| 78 | 78 | */ |
| 79 | 79 | public function is_populated() { |
| 80 | - return ( count( $this->data ) > 0 ) ? true : false; |
|
| 80 | + return (count($this->data) > 0) ? true : false; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -90,11 +90,11 @@ discard block |
||
| 90 | 90 | * @param string $callback |
| 91 | 91 | * @return string|array |
| 92 | 92 | */ |
| 93 | - public function transform( $key = null, callable $callback ) { |
|
| 93 | + public function transform($key = null, callable $callback) { |
|
| 94 | 94 | // WIP |
| 95 | - if( true === $this->has( $key ) ) { |
|
| 96 | - if( is_array( $this->data[ $key ] ) ) { |
|
| 97 | - return $this->transform_array_leafs( $this->data[ $key ], $callback ); |
|
| 95 | + if (true === $this->has($key)) { |
|
| 96 | + if (is_array($this->data[$key])) { |
|
| 97 | + return $this->transform_array_leafs($this->data[$key], $callback); |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -111,9 +111,9 @@ discard block |
||
| 111 | 111 | * @param string|array $callback |
| 112 | 112 | * @return array |
| 113 | 113 | */ |
| 114 | - protected function transform_array_leafs( array $array, $callback ) { |
|
| 115 | - array_walk_recursive( $array, function( &$item, $key ) use( $callback ) { |
|
| 116 | - $item = $this->call_func( $callback, $item ); |
|
| 114 | + protected function transform_array_leafs(array $array, $callback) { |
|
| 115 | + array_walk_recursive($array, function(&$item, $key) use($callback) { |
|
| 116 | + $item = $this->call_func($callback, $item); |
|
| 117 | 117 | } ); |
| 118 | 118 | return $array; |
| 119 | 119 | } |
@@ -128,16 +128,16 @@ discard block |
||
| 128 | 128 | * @param string (optional) $input The input string |
| 129 | 129 | * @return |
| 130 | 130 | */ |
| 131 | - private function call_func( $callback, $input = null ) { |
|
| 131 | + private function call_func($callback, $input = null) { |
|
| 132 | 132 | // WIP - simplify |
| 133 | - if( is_array( $callback ) ) { |
|
| 133 | + if (is_array($callback)) { |
|
| 134 | 134 | $method = $callback[0]; |
| 135 | 135 | $args = $callback[1]; |
| 136 | - if ( $input ) { |
|
| 137 | - array_unshift( $args, $input ); |
|
| 136 | + if ($input) { |
|
| 137 | + array_unshift($args, $input); |
|
| 138 | 138 | } |
| 139 | - return call_user_func_array( $method, $args ); |
|
| 139 | + return call_user_func_array($method, $args); |
|
| 140 | 140 | } |
| 141 | - return $callback( $input ); |
|
| 141 | + return $callback($input); |
|
| 142 | 142 | } |
| 143 | 143 | } |
@@ -45,6 +45,7 @@ |
||
| 45 | 45 | * @since 0.10.0 |
| 46 | 46 | * |
| 47 | 47 | * @param string (optional) $identity |
| 48 | + * @param string $identity |
|
| 48 | 49 | */ |
| 49 | 50 | function __construct( $identity = null ) { |
| 50 | 51 | $this->entity = $identity; |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @param string (optional) $identity |
| 48 | 48 | */ |
| 49 | 49 | function __construct( $identity = null ) { |
| 50 | - $this->entity = $identity; |
|
| 50 | + $this->entity = $identity; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | * @return self |
| 61 | 61 | */ |
| 62 | 62 | public function describe( $attribute, $characteristic ) { |
| 63 | - $this->scribe[ $attribute ] = $characteristic; |
|
| 64 | - return $this; |
|
| 63 | + $this->scribe[ $attribute ] = $characteristic; |
|
| 64 | + return $this; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -73,10 +73,10 @@ discard block |
||
| 73 | 73 | * @return Composite |
| 74 | 74 | */ |
| 75 | 75 | public function compose( ArtisanInterface $artisan ) { |
| 76 | - $this->orchestrate( $this->aspect, $artisan ); |
|
| 77 | - return $artisan |
|
| 78 | - ->create( $this->entity ) |
|
| 79 | - ->actualize(); |
|
| 76 | + $this->orchestrate( $this->aspect, $artisan ); |
|
| 77 | + return $artisan |
|
| 78 | + ->create( $this->entity ) |
|
| 79 | + ->actualize(); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | * @return self |
| 90 | 90 | */ |
| 91 | 91 | public function with( $quality, $attributes = null ) { |
| 92 | - $this->aspect[ $quality ] = $attributes; |
|
| 93 | - return $this; |
|
| 92 | + $this->aspect[ $quality ] = $attributes; |
|
| 93 | + return $this; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -103,9 +103,9 @@ discard block |
||
| 103 | 103 | * @param ArtisanInterface $artisan |
| 104 | 104 | */ |
| 105 | 105 | private function orchestrate( array $aspect, ArtisanInterface &$artisan ) { |
| 106 | - foreach( $aspect as $component => $params ) { |
|
| 107 | - $artisan->$component( $params ); |
|
| 108 | - } |
|
| 106 | + foreach( $aspect as $component => $params ) { |
|
| 107 | + $artisan->$component( $params ); |
|
| 108 | + } |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Artisan; |
| 3 | -defined( 'ABSPATH' ) or die( 'envois' ); |
|
| 3 | +defined('ABSPATH') or die('envois'); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Contract\ArtisanInterface; |
| 6 | 6 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @param string (optional) $identity |
| 48 | 48 | */ |
| 49 | - function __construct( $identity = null ) { |
|
| 49 | + function __construct($identity = null) { |
|
| 50 | 50 | $this->entity = $identity; |
| 51 | 51 | } |
| 52 | 52 | |
@@ -59,8 +59,8 @@ discard block |
||
| 59 | 59 | * @param mixed $characteristic |
| 60 | 60 | * @return self |
| 61 | 61 | */ |
| 62 | - public function describe( $attribute, $characteristic ) { |
|
| 63 | - $this->scribe[ $attribute ] = $characteristic; |
|
| 62 | + public function describe($attribute, $characteristic) { |
|
| 63 | + $this->scribe[$attribute] = $characteristic; |
|
| 64 | 64 | return $this; |
| 65 | 65 | } |
| 66 | 66 | |
@@ -72,10 +72,10 @@ discard block |
||
| 72 | 72 | * @param ArtisanInterface $artisan |
| 73 | 73 | * @return Composite |
| 74 | 74 | */ |
| 75 | - public function compose( ArtisanInterface $artisan ) { |
|
| 76 | - $this->orchestrate( $this->aspect, $artisan ); |
|
| 75 | + public function compose(ArtisanInterface $artisan) { |
|
| 76 | + $this->orchestrate($this->aspect, $artisan); |
|
| 77 | 77 | return $artisan |
| 78 | - ->create( $this->entity ) |
|
| 78 | + ->create($this->entity) |
|
| 79 | 79 | ->actualize(); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | * @param string|array (optional) $attributes |
| 89 | 89 | * @return self |
| 90 | 90 | */ |
| 91 | - public function with( $quality, $attributes = null ) { |
|
| 92 | - $this->aspect[ $quality ] = $attributes; |
|
| 91 | + public function with($quality, $attributes = null) { |
|
| 92 | + $this->aspect[$quality] = $attributes; |
|
| 93 | 93 | return $this; |
| 94 | 94 | } |
| 95 | 95 | |
@@ -102,9 +102,9 @@ discard block |
||
| 102 | 102 | * @param array $aspect |
| 103 | 103 | * @param ArtisanInterface $artisan |
| 104 | 104 | */ |
| 105 | - private function orchestrate( array $aspect, ArtisanInterface &$artisan ) { |
|
| 106 | - foreach( $aspect as $component => $params ) { |
|
| 107 | - $artisan->$component( $params ); |
|
| 105 | + private function orchestrate(array $aspect, ArtisanInterface&$artisan) { |
|
| 106 | + foreach ($aspect as $component => $params) { |
|
| 107 | + $artisan->$component($params); |
|
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @param |
| 118 | 118 | */ |
| 119 | - private function adapt( $interface ) { |
|
| 119 | + private function adapt($interface) { |
|
| 120 | 120 | |
| 121 | 121 | } |
| 122 | 122 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @since 0.10.0 |
| 91 | 91 | * |
| 92 | 92 | * @param string $action |
| 93 | - * @return WFV\Artisan\FormArtisan |
|
| 93 | + * @return FormArtisan |
|
| 94 | 94 | */ |
| 95 | 95 | public function create( $action ) { |
| 96 | 96 | $this->form = new FormComposite( $this, $action ); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * @since 0.10.0 |
| 105 | 105 | * |
| 106 | - * @return WFV\Artisan\FormArtisan |
|
| 106 | + * @return FormArtisan |
|
| 107 | 107 | */ |
| 108 | 108 | public function errors() { |
| 109 | 109 | $this->collection['errors'] = new ErrorCollection( $this->labels() ); |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | * @since 0.10.0 |
| 133 | 133 | * |
| 134 | 134 | * @param array $data |
| 135 | - * @return WFV\Artisan\FormArtisan |
|
| 135 | + * @return FormArtisan |
|
| 136 | 136 | */ |
| 137 | 137 | public function input( array $data = [] ) { |
| 138 | 138 | $input = $data[0]; |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | * |
| 148 | 148 | * @since 0.10.0 |
| 149 | 149 | * |
| 150 | - * @return WFV\Artisan\FormArtisan |
|
| 150 | + * @return FormArtisan |
|
| 151 | 151 | */ |
| 152 | 152 | public function rules() { |
| 153 | 153 | foreach( $this->config as $field => $options ) { |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | * |
| 165 | 165 | * @since 0.11.0 |
| 166 | 166 | * |
| 167 | - * @return WFV\Artisan\FormArtisan |
|
| 167 | + * @return FormArtisan |
|
| 168 | 168 | */ |
| 169 | 169 | public function validator() { |
| 170 | 170 | $this->validator = new Validator(); |
@@ -8,7 +8,6 @@ |
||
| 8 | 8 | use WFV\Collection\ErrorCollection; |
| 9 | 9 | use WFV\Collection\InputCollection; |
| 10 | 10 | use WFV\Collection\RuleCollection; |
| 11 | - |
|
| 12 | 11 | use WFV\FormComposite; |
| 13 | 12 | use WFV\Validators; |
| 14 | 13 | use WFV\Validator; |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Artisan; |
| 3 | -defined( 'ABSPATH' ) or die(); |
|
| 3 | +defined('ABSPATH') or die(); |
|
| 4 | 4 | |
| 5 | 5 | use \Respect\Validation\Validator as RespectValidator; |
| 6 | 6 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * |
| 70 | 70 | * @param array $config |
| 71 | 71 | */ |
| 72 | - function __construct( array $config ) { |
|
| 72 | + function __construct(array $config) { |
|
| 73 | 73 | $this->config = $config; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | * @param string $action |
| 93 | 93 | * @return WFV\Artisan\FormArtisan |
| 94 | 94 | */ |
| 95 | - public function create( $action ) { |
|
| 96 | - $this->form = new FormComposite( $this, $action ); |
|
| 95 | + public function create($action) { |
|
| 96 | + $this->form = new FormComposite($this, $action); |
|
| 97 | 97 | return $this; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * @return WFV\Artisan\FormArtisan |
| 107 | 107 | */ |
| 108 | 108 | public function errors() { |
| 109 | - $this->collection['errors'] = new ErrorCollection( $this->labels() ); |
|
| 109 | + $this->collection['errors'] = new ErrorCollection($this->labels()); |
|
| 110 | 110 | return $this; |
| 111 | 111 | } |
| 112 | 112 | |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * @return array |
| 121 | 121 | */ |
| 122 | 122 | protected function labels() { |
| 123 | - return array_map( function( $item ) { |
|
| 123 | + return array_map(function($item) { |
|
| 124 | 124 | return $item['label']; |
| 125 | 125 | }, $this->config); |
| 126 | 126 | } |
@@ -134,10 +134,10 @@ discard block |
||
| 134 | 134 | * @param array $data |
| 135 | 135 | * @return WFV\Artisan\FormArtisan |
| 136 | 136 | */ |
| 137 | - public function input( array $data = [] ) { |
|
| 137 | + public function input(array $data = []) { |
|
| 138 | 138 | $input = $data[0]; |
| 139 | 139 | $trim = $data[1]; |
| 140 | - $this->collection['input'] = new InputCollection( $input, $trim ); |
|
| 140 | + $this->collection['input'] = new InputCollection($input, $trim); |
|
| 141 | 141 | return $this; |
| 142 | 142 | } |
| 143 | 143 | |
@@ -150,10 +150,10 @@ discard block |
||
| 150 | 150 | * @return WFV\Artisan\FormArtisan |
| 151 | 151 | */ |
| 152 | 152 | public function rules() { |
| 153 | - foreach( $this->config as $field => $options ) { |
|
| 154 | - $rules[ $field ] = $options['rules']; |
|
| 153 | + foreach ($this->config as $field => $options) { |
|
| 154 | + $rules[$field] = $options['rules']; |
|
| 155 | 155 | } |
| 156 | - $this->collection['rules'] = new RuleCollection( $rules ); |
|
| 156 | + $this->collection['rules'] = new RuleCollection($rules); |
|
| 157 | 157 | $this->resolve_strategies(); |
| 158 | 158 | return $this; |
| 159 | 159 | } |
@@ -186,25 +186,25 @@ discard block |
||
| 186 | 186 | $optional = false; |
| 187 | 187 | $rules = $this->collection['rules']->get_array(); |
| 188 | 188 | |
| 189 | - foreach( $rules as $field => $ruleset ) { |
|
| 189 | + foreach ($rules as $field => $ruleset) { |
|
| 190 | 190 | |
| 191 | 191 | $optional = in_array("optional", $ruleset); |
| 192 | 192 | |
| 193 | - foreach( $ruleset as $rule ) { |
|
| 193 | + foreach ($ruleset as $rule) { |
|
| 194 | 194 | |
| 195 | - if( 'optional' !== $rule ){ |
|
| 195 | + if ('optional' !== $rule) { |
|
| 196 | 196 | |
| 197 | - $rule_name = ( is_string( $rule ) ) ? $rule : $rule['rule']; |
|
| 198 | - $class = str_replace(' ', '', ucwords( str_replace('_', ' ', $rule_name ) ) ); |
|
| 197 | + $rule_name = (is_string($rule)) ? $rule : $rule['rule']; |
|
| 198 | + $class = str_replace(' ', '', ucwords(str_replace('_', ' ', $rule_name))); |
|
| 199 | 199 | $class = 'WFV\Validators\\'.$class; |
| 200 | 200 | |
| 201 | - $message = ( isset( $this->config[ $field ]['messages'][ $rule_name ] ) ) |
|
| 202 | - ? $this->config[ $field ]['messages'][ $rule_name ] |
|
| 201 | + $message = (isset($this->config[$field]['messages'][$rule_name])) |
|
| 202 | + ? $this->config[$field]['messages'][$rule_name] |
|
| 203 | 203 | : false; |
| 204 | 204 | |
| 205 | - $strategies[ $field ][ $rule_name ] = ( is_string( $rule ) ) |
|
| 206 | - ? new $class( new RespectValidator(), $field, $optional, $message ) |
|
| 207 | - : new $class( new RespectValidator(), $field, $optional, $message, $rule['params'] ); |
|
| 205 | + $strategies[$field][$rule_name] = (is_string($rule)) |
|
| 206 | + ? new $class(new RespectValidator(), $field, $optional, $message) |
|
| 207 | + : new $class(new RespectValidator(), $field, $optional, $message, $rule['params']); |
|
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @since 0.10.0 |
| 41 | 41 | * |
| 42 | 42 | * @param string $rule |
| 43 | - * @return bool |
|
| 43 | + * @return boolean|null |
|
| 44 | 44 | */ |
| 45 | 45 | public function is_custom( $rule ) { |
| 46 | 46 | // WIP - needs adjusting to new rule string format |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @access protected |
| 57 | 57 | * |
| 58 | 58 | * @param string $rule |
| 59 | - * @return bool |
|
| 59 | + * @return string |
|
| 60 | 60 | */ |
| 61 | 61 | protected function extract_name( $rule ) { |
| 62 | 62 | return strstr( $rule, ':', true ); |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @access protected |
| 70 | 70 | * |
| 71 | 71 | * @param string $rule |
| 72 | - * @return bool |
|
| 72 | + * @return string |
|
| 73 | 73 | */ |
| 74 | 74 | protected function extract_params( $rule ) { |
| 75 | 75 | return ltrim( strstr($rule, ':'), ':'); |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * @access protected |
| 83 | 83 | * |
| 84 | 84 | * @param string $rule |
| 85 | - * @return bool |
|
| 85 | + * @return integer |
|
| 86 | 86 | */ |
| 87 | 87 | protected function has_parameters( $rule ) { |
| 88 | 88 | return strpos( $rule, ':' ); |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Collection; |
| 3 | -defined( 'ABSPATH' ) or die(); |
|
| 3 | +defined('ABSPATH') or die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Abstraction\Collectable; |
| 6 | 6 | |
@@ -18,8 +18,8 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @param array $rules |
| 20 | 20 | */ |
| 21 | - public function __construct( array $rules ) { |
|
| 22 | - $this->data = $this->parse_rules( $rules ); |
|
| 21 | + public function __construct(array $rules) { |
|
| 22 | + $this->data = $this->parse_rules($rules); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | * @param string $rule |
| 43 | 43 | * @return bool |
| 44 | 44 | */ |
| 45 | - public function is_custom( $rule ) { |
|
| 45 | + public function is_custom($rule) { |
|
| 46 | 46 | // WIP - needs adjusting to new rule string format |
| 47 | - if ( false === is_array( $rule ) ){ |
|
| 48 | - return ( false !== strpos( $rule, 'custom:' ) ) ? true : false; |
|
| 47 | + if (false === is_array($rule)) { |
|
| 48 | + return (false !== strpos($rule, 'custom:')) ? true : false; |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
@@ -58,8 +58,8 @@ discard block |
||
| 58 | 58 | * @param string $rule |
| 59 | 59 | * @return bool |
| 60 | 60 | */ |
| 61 | - protected function extract_name( $rule ) { |
|
| 62 | - return strstr( $rule, ':', true ); |
|
| 61 | + protected function extract_name($rule) { |
|
| 62 | + return strstr($rule, ':', true); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | * @param string $rule |
| 72 | 72 | * @return bool |
| 73 | 73 | */ |
| 74 | - protected function extract_params( $rule ) { |
|
| 75 | - return ltrim( strstr($rule, ':'), ':'); |
|
| 74 | + protected function extract_params($rule) { |
|
| 75 | + return ltrim(strstr($rule, ':'), ':'); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | * @param string $rule |
| 85 | 85 | * @return bool |
| 86 | 86 | */ |
| 87 | - protected function has_parameters( $rule ) { |
|
| 88 | - return strpos( $rule, ':' ); |
|
| 87 | + protected function has_parameters($rule) { |
|
| 88 | + return strpos($rule, ':'); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -98,19 +98,19 @@ discard block |
||
| 98 | 98 | * @param array $rules |
| 99 | 99 | * @return array |
| 100 | 100 | */ |
| 101 | - protected function parse_rules( array $rules ) { |
|
| 101 | + protected function parse_rules(array $rules) { |
|
| 102 | 102 | // WIP - works, but confusing - simplify or breakdown into small methods |
| 103 | - $this->split_rules( $rules ); |
|
| 104 | - foreach( $rules as $field => $ruleset ) { |
|
| 105 | - $parsed[ $field ] = array_map( function( $rule ) { |
|
| 106 | - if ( $this->has_parameters( $rule ) ) { |
|
| 103 | + $this->split_rules($rules); |
|
| 104 | + foreach ($rules as $field => $ruleset) { |
|
| 105 | + $parsed[$field] = array_map(function($rule) { |
|
| 106 | + if ($this->has_parameters($rule)) { |
|
| 107 | 107 | return array( |
| 108 | - 'rule' => $this->extract_name( $rule ), |
|
| 109 | - 'params' => explode( ',', $this->extract_params( $rule ) ) |
|
| 108 | + 'rule' => $this->extract_name($rule), |
|
| 109 | + 'params' => explode(',', $this->extract_params($rule)) |
|
| 110 | 110 | ); |
| 111 | 111 | } |
| 112 | 112 | return $rule; |
| 113 | - }, $ruleset ); |
|
| 113 | + }, $ruleset); |
|
| 114 | 114 | } |
| 115 | 115 | return $parsed; |
| 116 | 116 | } |
@@ -124,10 +124,10 @@ discard block |
||
| 124 | 124 | * @param array $rules |
| 125 | 125 | * @return array |
| 126 | 126 | */ |
| 127 | - protected function split_rules( array &$rules ) { |
|
| 127 | + protected function split_rules(array &$rules) { |
|
| 128 | 128 | // perhaps the $rules array structure should be validated here?... |
| 129 | - $rules = array_map( function( $item ) { |
|
| 130 | - return explode( '|', $item ); |
|
| 131 | - }, $rules ); |
|
| 129 | + $rules = array_map(function($item) { |
|
| 130 | + return explode('|', $item); |
|
| 131 | + }, $rules); |
|
| 132 | 132 | } |
| 133 | 133 | } |
@@ -177,6 +177,8 @@ |
||
| 177 | 177 | * @param string $response |
| 178 | 178 | * @param string (optional) $field |
| 179 | 179 | * @param string (optional) $value |
| 180 | + * @param string $field |
|
| 181 | + * @param string $value |
|
| 180 | 182 | * @return string|null |
| 181 | 183 | */ |
| 182 | 184 | protected function string_or_null( $response, $field = null, $value = null ) { |
@@ -4,7 +4,6 @@ |
||
| 4 | 4 | |
| 5 | 5 | use WFV\Abstraction\Composable; |
| 6 | 6 | use WFV\Contract\ArtisanInterface; |
| 7 | -use WFV\Contract\ValidateInterface; |
|
| 8 | 7 | |
| 9 | 8 | /** |
| 10 | 9 | * Form Composition |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV; |
| 3 | -defined( 'ABSPATH' ) or die(); |
|
| 3 | +defined('ABSPATH') or die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Abstraction\Composable; |
| 6 | 6 | use WFV\Contract\ArtisanInterface; |
@@ -39,9 +39,9 @@ discard block |
||
| 39 | 39 | * @param ArtisanInterface $builder |
| 40 | 40 | * @param string $action |
| 41 | 41 | */ |
| 42 | - function __construct( ArtisanInterface $builder, $action ) { |
|
| 42 | + function __construct(ArtisanInterface $builder, $action) { |
|
| 43 | 43 | $this->alias = $action; |
| 44 | - $this->install( $builder->collection ); |
|
| 44 | + $this->install($builder->collection); |
|
| 45 | 45 | $this->strategies = $builder->strategies; |
| 46 | 46 | $this->validator = $builder->validator; |
| 47 | 47 | } |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | * @param string $value Value to compare against. |
| 56 | 56 | * @return string|null |
| 57 | 57 | */ |
| 58 | - public function checked_if( $field = null, $value = null ) { |
|
| 59 | - return $this->string_or_null( 'checked', $field, $value ); |
|
| 58 | + public function checked_if($field = null, $value = null) { |
|
| 59 | + return $this->string_or_null('checked', $field, $value); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | * @param callable (optional) $callback |
| 71 | 71 | * @return string |
| 72 | 72 | */ |
| 73 | - public function display( $field = null, callable $callback = null ) { |
|
| 74 | - echo $input = $this->utilize('input')->escape( $field ); |
|
| 73 | + public function display($field = null, callable $callback = null) { |
|
| 74 | + echo $input = $this->utilize('input')->escape($field); |
|
| 75 | 75 | return $input; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -107,8 +107,8 @@ discard block |
||
| 107 | 107 | * @param string $value Value to compare against. |
| 108 | 108 | * @return string|null |
| 109 | 109 | */ |
| 110 | - public function selected_if( $field = null, $value = null ) { |
|
| 111 | - return $this->string_or_null( 'selected', $field, $value ); |
|
| 110 | + public function selected_if($field = null, $value = null) { |
|
| 111 | + return $this->string_or_null('selected', $field, $value); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -120,9 +120,9 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public function token_fields() { |
| 122 | 122 | // TODO - Move markup into something - perhaps a renderable interface? |
| 123 | - $token_name = $this->alias . '_token'; |
|
| 124 | - echo $nonce_field = wp_nonce_field( $this->alias, $token_name, false, false ); |
|
| 125 | - echo $action_field = '<input type="hidden" name="action" value="'. $this->alias .'">'; |
|
| 123 | + $token_name = $this->alias.'_token'; |
|
| 124 | + echo $nonce_field = wp_nonce_field($this->alias, $token_name, false, false); |
|
| 125 | + echo $action_field = '<input type="hidden" name="action" value="'.$this->alias.'">'; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -134,14 +134,14 @@ discard block |
||
| 134 | 134 | * @return bool |
| 135 | 135 | */ |
| 136 | 136 | public function validate() { |
| 137 | - $input = $this->utilize('input')->get_array( false ); |
|
| 137 | + $input = $this->utilize('input')->get_array(false); |
|
| 138 | 138 | $rules = $this->utilize('rules')->get_array(); |
| 139 | 139 | |
| 140 | - foreach( array_keys($rules) as $field ) { |
|
| 141 | - if( $this->strategies[ $field ] ) { |
|
| 142 | - foreach( $this->strategies[ $field ] as $rule ) { |
|
| 143 | - $value = ( isset( $input[ $field ] ) ) ? $input[ $field ] : null; |
|
| 144 | - $this->validator->validate( $rule, $value ); |
|
| 140 | + foreach (array_keys($rules) as $field) { |
|
| 141 | + if ($this->strategies[$field]) { |
|
| 142 | + foreach ($this->strategies[$field] as $rule) { |
|
| 143 | + $value = (isset($input[$field])) ? $input[$field] : null; |
|
| 144 | + $this->validator->validate($rule, $value); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -161,10 +161,10 @@ discard block |
||
| 161 | 161 | protected function is_valid() { |
| 162 | 162 | |
| 163 | 163 | $is_valid = $this->validator->is_valid(); |
| 164 | - if( false === $is_valid ) { |
|
| 165 | - $this->utilize('errors')->set_errors( $this->validator->errors() ); |
|
| 164 | + if (false === $is_valid) { |
|
| 165 | + $this->utilize('errors')->set_errors($this->validator->errors()); |
|
| 166 | 166 | } |
| 167 | - $this->trigger_post_validate_action( $is_valid ); |
|
| 167 | + $this->trigger_post_validate_action($is_valid); |
|
| 168 | 168 | return $is_valid; |
| 169 | 169 | } |
| 170 | 170 | |
@@ -179,8 +179,8 @@ discard block |
||
| 179 | 179 | * @param string (optional) $value |
| 180 | 180 | * @return string|null |
| 181 | 181 | */ |
| 182 | - protected function string_or_null( $response, $field = null, $value = null ) { |
|
| 183 | - return ( $this->input( $field )->contains( $field, $value ) ) ? $response : null; |
|
| 182 | + protected function string_or_null($response, $field = null, $value = null) { |
|
| 183 | + return ($this->input($field)->contains($field, $value)) ? $response : null; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -191,8 +191,8 @@ discard block |
||
| 191 | 191 | * |
| 192 | 192 | * @param bool $is_valid |
| 193 | 193 | */ |
| 194 | - protected function trigger_post_validate_action( $is_valid = false ) { |
|
| 195 | - $action = ( true === $is_valid ) ? $this->alias : $this->alias .'_fail'; |
|
| 196 | - do_action( $action, $this ); |
|
| 194 | + protected function trigger_post_validate_action($is_valid = false) { |
|
| 195 | + $action = (true === $is_valid) ? $this->alias : $this->alias.'_fail'; |
|
| 196 | + do_action($action, $this); |
|
| 197 | 197 | } |
| 198 | 198 | } |
@@ -123,7 +123,6 @@ discard block |
||
| 123 | 123 | * |
| 124 | 124 | * @since 0.11.0 |
| 125 | 125 | * |
| 126 | - * @param string|array $input |
|
| 127 | 126 | * @return bool |
| 128 | 127 | */ |
| 129 | 128 | public function validate( $value ) { |
@@ -137,6 +136,7 @@ discard block |
||
| 137 | 136 | * @since 0.11.0 |
| 138 | 137 | * |
| 139 | 138 | * @param |
| 139 | + * @param boolean $message |
|
| 140 | 140 | */ |
| 141 | 141 | protected function set_message( $message ) { |
| 142 | 142 | $this->template['message'] = $message; |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Validators; |
| 3 | -defined( 'ABSPATH' ) or die(); |
|
| 3 | +defined('ABSPATH') or die(); |
|
| 4 | 4 | |
| 5 | 5 | use \Respect\Validation\Validator as RespectValidator; |
| 6 | 6 | use \Respect\Validation\Exceptions\NestedValidationException; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * @param bool (optional) $optional |
| 68 | 68 | * @param string (optional) $message |
| 69 | 69 | */ |
| 70 | - function __construct( RespectValidator $validator, $field, $optional = false, $message = false ) { |
|
| 70 | + function __construct(RespectValidator $validator, $field, $optional = false, $message = false) { |
|
| 71 | 71 | // WIP - simplify - parameter overload... |
| 72 | 72 | |
| 73 | 73 | $this->optional = $optional; |
@@ -76,10 +76,10 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | $args = func_get_args(); |
| 78 | 78 | |
| 79 | - $this->params = ( isset( $args[4] ) ) ? $args[4] : null; |
|
| 79 | + $this->params = (isset($args[4])) ? $args[4] : null; |
|
| 80 | 80 | |
| 81 | - if( $message ) { |
|
| 82 | - $this->set_message( $message ); |
|
| 81 | + if ($message) { |
|
| 82 | + $this->set_message($message); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | $this->set_policy(); |
@@ -126,8 +126,8 @@ discard block |
||
| 126 | 126 | * @param string|array $input |
| 127 | 127 | * @return bool |
| 128 | 128 | */ |
| 129 | - public function validate( $value ) { |
|
| 130 | - $is_valid = $this->validator->validate( $value ); |
|
| 129 | + public function validate($value) { |
|
| 130 | + $is_valid = $this->validator->validate($value); |
|
| 131 | 131 | return $is_valid; |
| 132 | 132 | } |
| 133 | 133 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * |
| 139 | 139 | * @param |
| 140 | 140 | */ |
| 141 | - protected function set_message( $message ) { |
|
| 141 | + protected function set_message($message) { |
|
| 142 | 142 | $this->template['message'] = $message; |
| 143 | 143 | } |
| 144 | 144 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -defined( 'ABSPATH' ) or die(); |
|
| 2 | +defined('ABSPATH') or die(); |
|
| 3 | 3 | /* |
| 4 | 4 | Plugin Name: WFV - Form Validation |
| 5 | 5 | Plugin URI: https://macder.github.io/wfv/ |
@@ -11,12 +11,12 @@ discard block |
||
| 11 | 11 | License URI: https://github.com/macder/wp-form-validation/blob/master/LICENSE |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -define( 'WFV_VALIDATE_VERSION', '0.11.0' ); |
|
| 15 | -define( 'WFV_VALIDATE__MINIMUM_WP_VERSION', '3.7' ); |
|
| 16 | -define( 'WFV_VALIDATE__PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
|
| 17 | -define( 'WFV_VALIDATE__ACTION_POST', 'validate_form' ); |
|
| 14 | +define('WFV_VALIDATE_VERSION', '0.11.0'); |
|
| 15 | +define('WFV_VALIDATE__MINIMUM_WP_VERSION', '3.7'); |
|
| 16 | +define('WFV_VALIDATE__PLUGIN_DIR', plugin_dir_path(__FILE__)); |
|
| 17 | +define('WFV_VALIDATE__ACTION_POST', 'validate_form'); |
|
| 18 | 18 | |
| 19 | -require_once WFV_VALIDATE__PLUGIN_DIR . '/vendor/autoload.php'; |
|
| 19 | +require_once WFV_VALIDATE__PLUGIN_DIR.'/vendor/autoload.php'; |
|
| 20 | 20 | |
| 21 | 21 | use WFV\Agent\InspectionAgent; |
| 22 | 22 | use WFV\Artisan\Director; |
@@ -31,19 +31,19 @@ discard block |
||
| 31 | 31 | * @param array $form Form arguments |
| 32 | 32 | * @param bool $trim Trim whitespace from beginning and end of string |
| 33 | 33 | */ |
| 34 | -function wfv_create( $action, array &$form, $trim = true ) { |
|
| 35 | - $inspect = new InspectionAgent( $action ); |
|
| 36 | - $input = ( true === $inspect->safe_submit() ) ? $_POST : array(); |
|
| 34 | +function wfv_create($action, array &$form, $trim = true) { |
|
| 35 | + $inspect = new InspectionAgent($action); |
|
| 36 | + $input = (true === $inspect->safe_submit()) ? $_POST : array(); |
|
| 37 | 37 | |
| 38 | - $builder = new FormArtisan( $form ); |
|
| 39 | - $form = ( new Director( $action ) ) |
|
| 40 | - ->with( 'input', [ $input, $trim ] ) |
|
| 41 | - ->with( 'rules' ) |
|
| 42 | - ->with( 'errors' ) |
|
| 43 | - ->with( 'validator' ) |
|
| 44 | - ->compose( $builder ); |
|
| 38 | + $builder = new FormArtisan($form); |
|
| 39 | + $form = (new Director($action)) |
|
| 40 | + ->with('input', [$input, $trim]) |
|
| 41 | + ->with('rules') |
|
| 42 | + ->with('errors') |
|
| 43 | + ->with('validator') |
|
| 44 | + ->compose($builder); |
|
| 45 | 45 | |
| 46 | - if( $input ) { |
|
| 46 | + if ($input) { |
|
| 47 | 47 | $form->validate(); |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Collection; |
| 3 | -defined( 'ABSPATH' ) or die(); |
|
| 3 | +defined('ABSPATH') or die(); |
|
| 4 | 4 | |
| 5 | 5 | use WFV\Abstraction\Collectable; |
| 6 | 6 | |
@@ -20,9 +20,9 @@ discard block |
||
| 20 | 20 | * @param array $data |
| 21 | 21 | * @param bool $trim |
| 22 | 22 | */ |
| 23 | - function __construct( array $data = array(), $trim ) { |
|
| 24 | - $data = $this->transform_array_leafs( $data, 'stripslashes' ); |
|
| 25 | - $this->data = ( $trim ) ? $this->transform_array_leafs( $data, 'trim' ) : $data; |
|
| 23 | + function __construct(array $data = array(), $trim) { |
|
| 24 | + $data = $this->transform_array_leafs($data, 'stripslashes'); |
|
| 25 | + $this->data = ($trim) ? $this->transform_array_leafs($data, 'trim') : $data; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -33,8 +33,8 @@ discard block |
||
| 33 | 33 | * @param bool $tokens With or without token and action attributes. |
| 34 | 34 | * @return array |
| 35 | 35 | */ |
| 36 | - public function get_array( $tokens = true ) { |
|
| 37 | - return ( $tokens ) ? $this->data : $this->neat_array(); |
|
| 36 | + public function get_array($tokens = true) { |
|
| 37 | + return ($tokens) ? $this->data : $this->neat_array(); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -47,8 +47,8 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | protected function neat_array() { |
| 49 | 49 | $input = $this->data; |
| 50 | - unset( $input[ $input['action'] .'_token'] ); |
|
| 51 | - unset( $input['action'] ); |
|
| 50 | + unset($input[$input['action'].'_token']); |
|
| 51 | + unset($input['action']); |
|
| 52 | 52 | return $input; |
| 53 | 53 | } |
| 54 | 54 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Collection; |
| 3 | -defined( 'ABSPATH' ) or die(); |
|
| 3 | +defined('ABSPATH') or 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 ( $this->data[ $field ] ) |
|
| 43 | - ? array_values( $this->data[ $field ] )[0] |
|
| 41 | + public function first($field) { |
|
| 42 | + return ($this->data[$field]) |
|
| 43 | + ? array_values($this->data[$field])[0] |
|
| 44 | 44 | : null; |
| 45 | 45 | } |
| 46 | 46 | |
@@ -52,10 +52,10 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @param array $errors |
| 54 | 54 | */ |
| 55 | - public function set_errors( array $errors = [] ) { |
|
| 56 | - $this->data = ( $this->is_populated() ) |
|
| 55 | + public function set_errors(array $errors = []) { |
|
| 56 | + $this->data = ($this->is_populated()) |
|
| 57 | 57 | ? $this->data |
| 58 | - : $this->with_labels( $errors ); |
|
| 58 | + : $this->with_labels($errors); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | * @param string $field |
| 69 | 69 | * @return string |
| 70 | 70 | */ |
| 71 | - protected function label( $field ) { |
|
| 72 | - return ( isset( $this->labels[ $field ] ) ) |
|
| 73 | - ? $this->labels[ $field ] |
|
| 71 | + protected function label($field) { |
|
| 72 | + return (isset($this->labels[$field])) |
|
| 73 | + ? $this->labels[$field] |
|
| 74 | 74 | : $field; |
| 75 | 75 | } |
| 76 | 76 | |
@@ -83,10 +83,10 @@ discard block |
||
| 83 | 83 | * @param array $errors |
| 84 | 84 | * @return array |
| 85 | 85 | */ |
| 86 | - protected function with_labels( $errors ) { |
|
| 87 | - foreach( $errors as $field => $messages ) { |
|
| 88 | - $label = $this->label( $field ); |
|
| 89 | - $labeled[ $field ] = str_replace( '{label}', $label, $errors[ $field ] ); |
|
| 86 | + protected function with_labels($errors) { |
|
| 87 | + foreach ($errors as $field => $messages) { |
|
| 88 | + $label = $this->label($field); |
|
| 89 | + $labeled[$field] = str_replace('{label}', $label, $errors[$field]); |
|
| 90 | 90 | } |
| 91 | 91 | return $labeled; |
| 92 | 92 | } |