@@ -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 |
@@ -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 | * |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | /** |
| 14 | 14 | * @return |
| 15 | 15 | */ |
| 16 | - public function create( $action ); |
|
| 16 | + public function create($action); |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * @return |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Artisan; |
| 3 | -defined( 'ABSPATH' ) || die( 'envois' ); |
|
| 3 | +defined('ABSPATH') || 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 | - public function __construct( $identity = null ) { |
|
| 49 | + public 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 | } |
@@ -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 | } |
@@ -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 | use WFV\Abstraction\Collectable; |
| 5 | 5 | /** |
| 6 | 6 | * |
@@ -16,8 +16,8 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @param array $form Config array |
| 18 | 18 | */ |
| 19 | - public function __construct( array $form ) { |
|
| 20 | - $this->set_messages( $form ); |
|
| 19 | + public function __construct(array $form) { |
|
| 20 | + $this->set_messages($form); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -40,9 +40,9 @@ discard block |
||
| 40 | 40 | * @param string $rule |
| 41 | 41 | * @return array|null |
| 42 | 42 | */ |
| 43 | - public function get_msg( $field, $rule ) { |
|
| 44 | - return ( isset( $this->data[ $field ][ $rule ] ) ) |
|
| 45 | - ? $this->data[ $field ][ $rule ] |
|
| 43 | + public function get_msg($field, $rule) { |
|
| 44 | + return (isset($this->data[$field][$rule])) |
|
| 45 | + ? $this->data[$field][$rule] |
|
| 46 | 46 | : null; |
| 47 | 47 | } |
| 48 | 48 | |
@@ -56,9 +56,9 @@ discard block |
||
| 56 | 56 | * @param array $form |
| 57 | 57 | * @return array |
| 58 | 58 | */ |
| 59 | - protected function filter_config( array $form ) { |
|
| 60 | - return array_filter( $form, function( $item ) { |
|
| 61 | - return array_key_exists('messages', $item ); |
|
| 59 | + protected function filter_config(array $form) { |
|
| 60 | + return array_filter($form, function($item) { |
|
| 61 | + return array_key_exists('messages', $item); |
|
| 62 | 62 | }); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -70,10 +70,10 @@ discard block |
||
| 70 | 70 | * |
| 71 | 71 | * @param array |
| 72 | 72 | */ |
| 73 | - protected function make_array( array $filtered ) { |
|
| 73 | + protected function make_array(array $filtered) { |
|
| 74 | 74 | $messages = array(); |
| 75 | - foreach( $filtered as $field => $options ) { |
|
| 76 | - $messages[ $field ] = $options['messages']; |
|
| 75 | + foreach ($filtered as $field => $options) { |
|
| 76 | + $messages[$field] = $options['messages']; |
|
| 77 | 77 | } |
| 78 | 78 | return $messages; |
| 79 | 79 | } |
@@ -86,8 +86,8 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @param array $form |
| 88 | 88 | */ |
| 89 | - protected function set_messages( array $form ) { |
|
| 90 | - $filtered = $this->filter_config( $form ); |
|
| 91 | - $this->data = $this->make_array( $filtered ); |
|
| 89 | + protected function set_messages(array $form) { |
|
| 90 | + $filtered = $this->filter_config($form); |
|
| 91 | + $this->data = $this->make_array($filtered); |
|
| 92 | 92 | } |
| 93 | 93 | } |
@@ -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 | } |
@@ -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\Collection\MessageCollection; |
| 6 | 6 | use WFV\Contract\ValidateInterface; |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @param |
| 40 | 40 | */ |
| 41 | - public function __construct( MessageCollection $messages ) { |
|
| 41 | + public function __construct(MessageCollection $messages) { |
|
| 42 | 42 | $this->messages = $messages; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @return bool |
| 62 | 62 | */ |
| 63 | 63 | public function is_valid() { |
| 64 | - return empty( $this->errors ); |
|
| 64 | + return empty($this->errors); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -76,11 +76,11 @@ discard block |
||
| 76 | 76 | * @param array (optional) $params |
| 77 | 77 | * @return self |
| 78 | 78 | */ |
| 79 | - public function validate( ValidateInterface $rule, $field, $value, $optional, $params = false ) { |
|
| 80 | - $params[] = ( $params ) ? $field : false; |
|
| 81 | - $valid = $rule->validate( $value, $optional, $params ); |
|
| 82 | - if( !$valid ){ |
|
| 83 | - $this->add_error( $field, $rule->template() ); |
|
| 79 | + public function validate(ValidateInterface $rule, $field, $value, $optional, $params = false) { |
|
| 80 | + $params[] = ($params) ? $field : false; |
|
| 81 | + $valid = $rule->validate($value, $optional, $params); |
|
| 82 | + if (!$valid) { |
|
| 83 | + $this->add_error($field, $rule->template()); |
|
| 84 | 84 | } |
| 85 | 85 | return $this; |
| 86 | 86 | } |
@@ -94,10 +94,10 @@ discard block |
||
| 94 | 94 | * @param string $field |
| 95 | 95 | * @param array $template |
| 96 | 96 | */ |
| 97 | - protected function add_error( $field, array $template ) { |
|
| 98 | - $message = ( $this->messages->has( $field ) ) |
|
| 99 | - ? $this->messages->get_msg( $field, $template['name'] ) |
|
| 97 | + protected function add_error($field, array $template) { |
|
| 98 | + $message = ($this->messages->has($field)) |
|
| 99 | + ? $this->messages->get_msg($field, $template['name']) |
|
| 100 | 100 | : $template['message']; |
| 101 | - $this->errors[ $field ][ $template['name'] ] = $message; |
|
| 101 | + $this->errors[$field][$template['name']] = $message; |
|
| 102 | 102 | } |
| 103 | 103 | } |
@@ -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 | } |