@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @param string $url |
60 | 60 | * @param string $version |
61 | 61 | */ |
62 | - public function __construct( $url, $version = null ) { |
|
62 | + public function __construct($url, $version = null) { |
|
63 | 63 | $this->url = $url; |
64 | 64 | $this->version = $version; |
65 | 65 | } |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @param bool $debug |
71 | 71 | */ |
72 | - public function set_debug( $debug ) { |
|
73 | - if ( $debug ) { |
|
72 | + public function set_debug($debug) { |
|
73 | + if ($debug) { |
|
74 | 74 | $this->min = '.min'; |
75 | 75 | } else { |
76 | 76 | $this->min = ''; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @param array $script |
84 | 84 | */ |
85 | - public function register_script( $script ) { |
|
85 | + public function register_script($script) { |
|
86 | 86 | $this->scripts[] = $script; |
87 | 87 | } |
88 | 88 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * |
92 | 92 | * @param array $style |
93 | 93 | */ |
94 | - public function register_style( $style ) { |
|
94 | + public function register_style($style) { |
|
95 | 95 | $this->styles[] = $style; |
96 | 96 | } |
97 | 97 | |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | * {@inheritDoc} |
100 | 100 | */ |
101 | 101 | public function enqueue_web_scripts() { |
102 | - foreach ( $this->scripts as $script ) { |
|
103 | - if ( in_array( $script['type'], array( 'web', 'shared' ) ) ) { |
|
104 | - $this->enqueue_script( $script ); |
|
102 | + foreach ($this->scripts as $script) { |
|
103 | + if (in_array($script['type'], array('web', 'shared'))) { |
|
104 | + $this->enqueue_script($script); |
|
105 | 105 | } |
106 | 106 | } |
107 | 107 | } |
@@ -110,9 +110,9 @@ discard block |
||
110 | 110 | * {@inheritDoc} |
111 | 111 | */ |
112 | 112 | public function enqueue_web_styles() { |
113 | - foreach ( $this->styles as $style ) { |
|
114 | - if ( in_array( $style['type'], array( 'web', 'shared' ) ) ) { |
|
115 | - $this->enqueue_style( $style ); |
|
113 | + foreach ($this->styles as $style) { |
|
114 | + if (in_array($style['type'], array('web', 'shared'))) { |
|
115 | + $this->enqueue_style($style); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | } |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | * {@inheritDoc} |
122 | 122 | */ |
123 | 123 | public function enqueue_admin_scripts() { |
124 | - foreach ( $this->scripts as $script ) { |
|
125 | - if ( in_array( $script['type'], array( 'admin', 'shared' ) ) ) { |
|
126 | - $this->enqueue_script( $script ); |
|
124 | + foreach ($this->scripts as $script) { |
|
125 | + if (in_array($script['type'], array('admin', 'shared'))) { |
|
126 | + $this->enqueue_script($script); |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 | } |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | * {@inheritDoc} |
133 | 133 | */ |
134 | 134 | public function enqueue_admin_styles() { |
135 | - foreach ( $this->styles as $style ) { |
|
136 | - if ( in_array( $style['type'], array( 'admin', 'shared' ) ) ) { |
|
137 | - $this->enqueue_style( $style ); |
|
135 | + foreach ($this->styles as $style) { |
|
136 | + if (in_array($style['type'], array('admin', 'shared'))) { |
|
137 | + $this->enqueue_style($style); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | } |
@@ -170,17 +170,17 @@ discard block |
||
170 | 170 | * |
171 | 171 | * @param array $script |
172 | 172 | */ |
173 | - protected function enqueue_script( $script ) { |
|
174 | - if ( $script['condition']() ) { |
|
173 | + protected function enqueue_script($script) { |
|
174 | + if ($script['condition']()) { |
|
175 | 175 | wp_enqueue_script( |
176 | 176 | $script['handle'], |
177 | 177 | $this->url . $script['src'] . '.js', |
178 | - isset( $script['deps'] ) ? $script['deps'] : array(), |
|
178 | + isset($script['deps']) ? $script['deps'] : array(), |
|
179 | 179 | $this->version, |
180 | - isset( $script['footer'] ) ? $script['footer'] : false |
|
180 | + isset($script['footer']) ? $script['footer'] : false |
|
181 | 181 | ); |
182 | 182 | |
183 | - if ( isset( $script['localize'] ) ) { |
|
183 | + if (isset($script['localize'])) { |
|
184 | 184 | wp_localize_script( |
185 | 185 | $script['handle'], |
186 | 186 | $script['localize']['name'], |
@@ -195,14 +195,14 @@ discard block |
||
195 | 195 | * |
196 | 196 | * @param array $style |
197 | 197 | */ |
198 | - protected function enqueue_style( $style ) { |
|
199 | - if ( $style['condition']() ) { |
|
198 | + protected function enqueue_style($style) { |
|
199 | + if ($style['condition']()) { |
|
200 | 200 | wp_enqueue_style( |
201 | 201 | $style['handle'], |
202 | 202 | $this->url . $style['src'] . '.css', |
203 | - isset( $style['deps'] ) ? $style['deps'] : array(), |
|
203 | + isset($style['deps']) ? $style['deps'] : array(), |
|
204 | 204 | $this->version, |
205 | - isset( $style['media'] ) ? $style['media'] : 'all' |
|
205 | + isset($style['media']) ? $style['media'] : 'all' |
|
206 | 206 | ); |
207 | 207 | } |
208 | 208 | } |
@@ -8,13 +8,13 @@ discard block |
||
8 | 8 | /** |
9 | 9 | * {@inheritDoc} |
10 | 10 | */ |
11 | - public function register( Container $container ) { |
|
11 | + public function register(Container $container) { |
|
12 | 12 | $container->define( |
13 | - array( 'register' => 'Intraxia\Jaxion\Contract\Assets\Register' ), |
|
14 | - $register = new Register( $container->fetch( 'url' ), $container->fetch( 'version' ) ) |
|
13 | + array('register' => 'Intraxia\Jaxion\Contract\Assets\Register'), |
|
14 | + $register = new Register($container->fetch('url'), $container->fetch('version')) |
|
15 | 15 | ); |
16 | 16 | |
17 | - $this->add_assets( $register ); |
|
17 | + $this->add_assets($register); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @codeCoverageIgnore |
29 | 29 | */ |
30 | - protected function add_assets( Register $register ) { |
|
30 | + protected function add_assets(Register $register) { |
|
31 | 31 | // no-op |
32 | 32 | } |
33 | 33 | } |
34 | 34 | \ No newline at end of file |
@@ -19,9 +19,9 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @return bool |
21 | 21 | */ |
22 | - public static function starts_with( $haystack, $needles ) { |
|
23 | - foreach ( (array) $needles as $needle ) { |
|
24 | - if ( $needle != '' && strpos( $haystack, $needle ) === 0 ) { |
|
22 | + public static function starts_with($haystack, $needles) { |
|
23 | + foreach ((array) $needles as $needle) { |
|
24 | + if ($needle != '' && strpos($haystack, $needle) === 0) { |
|
25 | 25 | return true; |
26 | 26 | } |
27 | 27 | } |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @return bool |
39 | 39 | */ |
40 | - public static function ends_with( $haystack, $needles ) { |
|
41 | - foreach ( (array) $needles as $needle ) { |
|
42 | - if ( (string) $needle === substr( $haystack, - strlen( $needle ) ) ) { |
|
40 | + public static function ends_with($haystack, $needles) { |
|
41 | + foreach ((array) $needles as $needle) { |
|
42 | + if ((string) $needle === substr($haystack, - strlen($needle))) { |
|
43 | 43 | return true; |
44 | 44 | } |
45 | 45 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @param string $vendor |
73 | 73 | */ |
74 | - public function set_vendor( $vendor ) { |
|
74 | + public function set_vendor($vendor) { |
|
75 | 75 | $this->vendor = $vendor; |
76 | 76 | } |
77 | 77 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @param int $version |
82 | 82 | */ |
83 | - public function set_version( $version ) { |
|
83 | + public function set_version($version) { |
|
84 | 84 | $this->version = $version; |
85 | 85 | } |
86 | 86 | |
@@ -94,15 +94,15 @@ discard block |
||
94 | 94 | * @throws VersionNotSetException |
95 | 95 | */ |
96 | 96 | public function register() { |
97 | - if ( ! $this->vendor ) { |
|
97 | + if (!$this->vendor) { |
|
98 | 98 | throw new VendorNotSetException; |
99 | 99 | } |
100 | 100 | |
101 | - if ( ! $this->version ) { |
|
101 | + if (!$this->version) { |
|
102 | 102 | throw new VersionNotSetException; |
103 | 103 | } |
104 | 104 | |
105 | - foreach ( $this->endpoints as $endpoint ) { |
|
105 | + foreach ($this->endpoints as $endpoint) { |
|
106 | 106 | register_rest_route( |
107 | 107 | $this->get_namespace(), |
108 | 108 | $endpoint->get_route(), |
@@ -120,13 +120,13 @@ discard block |
||
120 | 120 | * @param array $options |
121 | 121 | * @param callable $callback |
122 | 122 | */ |
123 | - public function group( array $options, $callback ) { |
|
123 | + public function group(array $options, $callback) { |
|
124 | 124 | $router = new static; |
125 | 125 | |
126 | - call_user_func( $callback, $router ); |
|
126 | + call_user_func($callback, $router); |
|
127 | 127 | |
128 | - foreach ( $router->get_endpoints() as $endpoint ) { |
|
129 | - $this->endpoints[] = $this->set_options( $endpoint, $options ); |
|
128 | + foreach ($router->get_endpoints() as $endpoint) { |
|
129 | + $this->endpoints[] = $this->set_options($endpoint, $options); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
@@ -145,26 +145,26 @@ discard block |
||
145 | 145 | * @throws MissingArgumentException |
146 | 146 | * @throws InvalidArgumentException |
147 | 147 | */ |
148 | - public function __call( $name, $arguments ) { |
|
149 | - if ( ! in_array( $name, array_keys( $this->methods ) ) ) { |
|
148 | + public function __call($name, $arguments) { |
|
149 | + if (!in_array($name, array_keys($this->methods))) { |
|
150 | 150 | throw new UnknownMethodException; |
151 | 151 | } |
152 | 152 | |
153 | 153 | // array_merge ensures we have 3 elements |
154 | - list( $route, $callback, $options ) = array_merge( $arguments, array( null, null, null ) ); |
|
154 | + list($route, $callback, $options) = array_merge($arguments, array(null, null, null)); |
|
155 | 155 | |
156 | - if ( ! $route || ! $callback ) { |
|
156 | + if (!$route || !$callback) { |
|
157 | 157 | throw new MissingArgumentException; |
158 | 158 | } |
159 | 159 | |
160 | - if ( ! is_callable( $callback ) ) { |
|
160 | + if (!is_callable($callback)) { |
|
161 | 161 | throw new InvalidArgumentException; |
162 | 162 | } |
163 | 163 | |
164 | - $endpoint = new Endpoint( $route, $this->methods[ $name ], $callback ); |
|
164 | + $endpoint = new Endpoint($route, $this->methods[$name], $callback); |
|
165 | 165 | |
166 | - if ( $options && is_array( $options ) ) { |
|
167 | - $endpoint = $this->set_options( $endpoint, $options ); |
|
166 | + if ($options && is_array($options)) { |
|
167 | + $endpoint = $this->set_options($endpoint, $options); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | return $this->endpoints[] = $endpoint; |
@@ -181,17 +181,17 @@ discard block |
||
181 | 181 | * @return Endpoint |
182 | 182 | * @throws MalformedRouteException |
183 | 183 | */ |
184 | - protected function set_options( Endpoint $endpoint, array $options ) { |
|
185 | - if ( isset( $options['guard'] ) ) { |
|
186 | - $endpoint->set_guard( $options['guard'] ); |
|
184 | + protected function set_options(Endpoint $endpoint, array $options) { |
|
185 | + if (isset($options['guard'])) { |
|
186 | + $endpoint->set_guard($options['guard']); |
|
187 | 187 | } |
188 | 188 | |
189 | - if ( isset( $options['filter'] ) ) { |
|
190 | - $endpoint->set_filter( $options['filter'] ); |
|
189 | + if (isset($options['filter'])) { |
|
190 | + $endpoint->set_filter($options['filter']); |
|
191 | 191 | } |
192 | 192 | |
193 | - if ( isset( $options['prefix'] ) ) { |
|
194 | - $endpoint->set_prefix( $options['prefix'] ); |
|
193 | + if (isset($options['prefix'])) { |
|
194 | + $endpoint->set_prefix($options['prefix']); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | return $endpoint; |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @param array $rules |
26 | 26 | */ |
27 | - public function __construct( $rules = array() ) { |
|
27 | + public function __construct($rules = array()) { |
|
28 | 28 | $this->rules = $rules; |
29 | 29 | } |
30 | 30 | |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | public function rules() { |
40 | 40 | $args = array(); |
41 | 41 | |
42 | - foreach ( $this->rules as $arg => $validation ) { |
|
43 | - if ( ! $validation || ! is_string( $validation ) ) { |
|
42 | + foreach ($this->rules as $arg => $validation) { |
|
43 | + if (!$validation || !is_string($validation)) { |
|
44 | 44 | continue; |
45 | 45 | } |
46 | 46 | |
47 | - $args[ $arg ] = $this->parse_validation( $validation ); |
|
47 | + $args[$arg] = $this->parse_validation($validation); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | return $args; |
@@ -57,25 +57,25 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @return array |
59 | 59 | */ |
60 | - protected function parse_validation( $validation ) { |
|
61 | - $validation = explode( '|', $validation ); |
|
60 | + protected function parse_validation($validation) { |
|
61 | + $validation = explode('|', $validation); |
|
62 | 62 | |
63 | 63 | $rules = array(); |
64 | 64 | |
65 | - foreach ( $validation as $rule ) { |
|
66 | - if ( 0 === strpos( $rule, 'default' ) ) { |
|
67 | - $ruleArr = explode( ':', $rule ); |
|
65 | + foreach ($validation as $rule) { |
|
66 | + if (0 === strpos($rule, 'default')) { |
|
67 | + $ruleArr = explode(':', $rule); |
|
68 | 68 | |
69 | - $rules['default'] = count( $ruleArr ) === 2 ? array_pop( $ruleArr ) : ''; |
|
69 | + $rules['default'] = count($ruleArr) === 2 ? array_pop($ruleArr) : ''; |
|
70 | 70 | } |
71 | 71 | |
72 | - switch ( $rule ) { |
|
72 | + switch ($rule) { |
|
73 | 73 | case 'required': |
74 | 74 | $rules['required'] = true; |
75 | 75 | break; |
76 | 76 | case 'integer': |
77 | - $rules['validate_callback'] = array( $this, 'validate_integer' ); |
|
78 | - $rules['sanitize_callback'] = array( $this, 'make_integer' ); |
|
77 | + $rules['validate_callback'] = array($this, 'validate_integer'); |
|
78 | + $rules['sanitize_callback'] = array($this, 'make_integer'); |
|
79 | 79 | break; |
80 | 80 | } |
81 | 81 | } |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | * |
91 | 91 | * @return bool |
92 | 92 | */ |
93 | - public function validate_integer( $value ) { |
|
94 | - return filter_var( $value, FILTER_VALIDATE_INT ) !== false; |
|
93 | + public function validate_integer($value) { |
|
94 | + return filter_var($value, FILTER_VALIDATE_INT) !== false; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @return int |
103 | 103 | */ |
104 | - public function make_integer( $value ) { |
|
104 | + public function make_integer($value) { |
|
105 | 105 | return (int) $value; |
106 | 106 | } |
107 | 107 | } |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @param array $options |
39 | 39 | */ |
40 | - public function __construct( array $options = array() ) { |
|
41 | - $this->options = $this->set_defaults( $options ); |
|
40 | + public function __construct(array $options = array()) { |
|
41 | + $this->options = $this->set_defaults($options); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -48,24 +48,24 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function authorized() { |
50 | 50 | // if the rule is public, always authorized |
51 | - if ( 'public' === $this->options['rule'] ) { |
|
51 | + if ('public' === $this->options['rule']) { |
|
52 | 52 | return true; |
53 | 53 | } |
54 | 54 | |
55 | 55 | // enable passing in callback |
56 | - if ( 'callback' === $this->options['rule'] && is_callable( $this->options['callback'] ) ) { |
|
57 | - return call_user_func( $this->options['callback'] ); |
|
56 | + if ('callback' === $this->options['rule'] && is_callable($this->options['callback'])) { |
|
57 | + return call_user_func($this->options['callback']); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // map rule to method |
61 | - if ( method_exists( $this, $method = $this->options['rule'] ) ) { |
|
61 | + if (method_exists($this, $method = $this->options['rule'])) { |
|
62 | 62 | return $this->{$method}(); |
63 | 63 | } |
64 | 64 | |
65 | 65 | // disable in rule is misconfigused |
66 | 66 | // @todo set up internal translations |
67 | 67 | // @todo also, this error message kinda sucks |
68 | - return new WP_Error( '500', __( 'Guard failure', 'jaxion' ) ); |
|
68 | + return new WP_Error('500', __('Guard failure', 'jaxion')); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @return bool |
75 | 75 | */ |
76 | 76 | protected function can_edit_others_posts() { |
77 | - return current_user_can( 'edit_others_posts' ) ?: new WP_Error( '401', __( 'Unauthorized user', 'jaxion' ) ); |
|
77 | + return current_user_can('edit_others_posts') ?: new WP_Error('401', __('Unauthorized user', 'jaxion')); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @return array |
86 | 86 | */ |
87 | - protected function set_defaults( $options ) { |
|
87 | + protected function set_defaults($options) { |
|
88 | 88 | // these are the valid options |
89 | - return wp_parse_args( $options, $this->defaults ); |
|
89 | + return wp_parse_args($options, $this->defaults); |
|
90 | 90 | } |
91 | 91 | } |
@@ -8,10 +8,10 @@ discard block |
||
8 | 8 | /** |
9 | 9 | * {@inheritDoc} |
10 | 10 | */ |
11 | - public function register( Container $container ) { |
|
12 | - $container->define( array( 'router' => 'Intraxia\Jaxion\Http\Router' ), $router = new Router ); |
|
11 | + public function register(Container $container) { |
|
12 | + $container->define(array('router' => 'Intraxia\Jaxion\Http\Router'), $router = new Router); |
|
13 | 13 | |
14 | - $this->add_routes( $router ); |
|
14 | + $this->add_routes($router); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @codeCoverageIgnore |
26 | 26 | */ |
27 | - protected function add_routes( Router $router ) { |
|
27 | + protected function add_routes(Router $router) { |
|
28 | 28 | // no-op |
29 | 29 | } |
30 | 30 | } |
31 | 31 | \ No newline at end of file |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @throws MalformedRouteException |
67 | 67 | */ |
68 | - public function __construct( $route, $method, $callback ) { |
|
69 | - if ( ! Str::starts_with( $route, '/' ) || Str::ends_with( $route, '/' ) ) { |
|
68 | + public function __construct($route, $method, $callback) { |
|
69 | + if (!Str::starts_with($route, '/') || Str::ends_with($route, '/')) { |
|
70 | 70 | throw new MalformedRouteException; |
71 | 71 | } |
72 | 72 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * @return string |
84 | 84 | */ |
85 | 85 | public function get_route() { |
86 | - return ( $this->prefix ?: '' ) . $this->route; |
|
86 | + return ($this->prefix ?: '') . $this->route; |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -97,11 +97,11 @@ discard block |
||
97 | 97 | 'callback' => $this->callback, |
98 | 98 | ); |
99 | 99 | |
100 | - if ( $this->guard ) { |
|
101 | - $options['permission_callback'] = array( $this->guard, 'authorized' ); |
|
100 | + if ($this->guard) { |
|
101 | + $options['permission_callback'] = array($this->guard, 'authorized'); |
|
102 | 102 | } |
103 | 103 | |
104 | - if ( $this->filter ) { |
|
104 | + if ($this->filter) { |
|
105 | 105 | $options['args'] = $this->filter->rules(); |
106 | 106 | } |
107 | 107 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @return $this |
117 | 117 | */ |
118 | - public function set_guard( GuardContract $guard ) { |
|
118 | + public function set_guard(GuardContract $guard) { |
|
119 | 119 | $this->guard = $guard; |
120 | 120 | |
121 | 121 | return $this; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @return $this |
130 | 130 | */ |
131 | - public function set_filter( FilterContract $filter ) { |
|
131 | + public function set_filter(FilterContract $filter) { |
|
132 | 132 | $this->filter = $filter; |
133 | 133 | |
134 | 134 | return $this; |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | * @return $this |
143 | 143 | * @throws MalformedRouteException |
144 | 144 | */ |
145 | - public function set_prefix( $prefix ) { |
|
146 | - if ( ! Str::starts_with( $prefix, '/' ) || Str::ends_with( $prefix, '/' ) ) { |
|
145 | + public function set_prefix($prefix) { |
|
146 | + if (!Str::starts_with($prefix, '/') || Str::ends_with($prefix, '/')) { |
|
147 | 147 | throw new MalformedRouteException; |
148 | 148 | } |
149 | 149 |