| @@ -2,7 +2,6 @@ | ||
| 2 | 2 | namespace Intraxia\Jaxion\Http; | 
| 3 | 3 | |
| 4 | 4 | use Intraxia\Jaxion\Contract\Http\Guard as GuardContract; | 
| 5 | -use Intraxia\Jaxion\Utility\Str; | |
| 6 | 5 | use WP_Error; | 
| 7 | 6 | |
| 8 | 7 | /** | 
| @@ -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|WP_Error | 
| 75 | 75 | */ | 
| 76 | 76 |  	protected function can_edit_others_posts() { | 
| 77 | - return current_user_can( 'edit_others_posts' ) ?: new WP_Error( 'unauthorized', __( 'Unauthorized user', 'jaxion' ), array( 'status' => 401 ) ); | |
| 77 | +		return current_user_can('edit_others_posts') ?: new WP_Error('unauthorized', __('Unauthorized user', 'jaxion'), array('status' => 401)); | |
| 78 | 78 | } | 
| 79 | 79 | |
| 80 | 80 | /** | 
| @@ -83,7 +83,7 @@ discard block | ||
| 83 | 83 | * @return bool|WP_Error | 
| 84 | 84 | */ | 
| 85 | 85 |  	protected function user_logged_in() { | 
| 86 | - return is_user_logged_in() ?: new WP_Error( 'unauthorized', __( 'Unauthorized user', 'jaxion' ), array( 'status' => 401 ) ); | |
| 86 | +		return is_user_logged_in() ?: new WP_Error('unauthorized', __('Unauthorized user', 'jaxion'), array('status' => 401)); | |
| 87 | 87 | } | 
| 88 | 88 | |
| 89 | 89 | /** | 
| @@ -93,8 +93,8 @@ discard block | ||
| 93 | 93 | * | 
| 94 | 94 | * @return array | 
| 95 | 95 | */ | 
| 96 | -	protected function set_defaults( $options ) { | |
| 96 | +	protected function set_defaults($options) { | |
| 97 | 97 | // these are the valid options | 
| 98 | - return wp_parse_args( $options, $this->defaults ); | |
| 98 | + return wp_parse_args($options, $this->defaults); | |
| 99 | 99 | } | 
| 100 | 100 | } | 
| @@ -20,7 +20,7 @@ discard block | ||
| 20 | 20 | * | 
| 21 | 21 | * @return $this | 
| 22 | 22 | */ | 
| 23 | - public function define( $alias, $definition ); | |
| 23 | + public function define($alias, $definition); | |
| 24 | 24 | |
| 25 | 25 | /** | 
| 26 | 26 | * Defines a new singleton on the Container. | 
| @@ -33,7 +33,7 @@ discard block | ||
| 33 | 33 | * | 
| 34 | 34 | * @return $this | 
| 35 | 35 | */ | 
| 36 | - public function share( $alias, $definition ); | |
| 36 | + public function share($alias, $definition); | |
| 37 | 37 | |
| 38 | 38 | /** | 
| 39 | 39 | * Fetches the value for the provided alias. | 
| @@ -42,7 +42,7 @@ discard block | ||
| 42 | 42 | * | 
| 43 | 43 | * @return mixed | 
| 44 | 44 | */ | 
| 45 | - public function fetch( $alias ); | |
| 45 | + public function fetch($alias); | |
| 46 | 46 | |
| 47 | 47 | /** | 
| 48 | 48 | * Checks whether the provided alias exists on the container. | 
| @@ -51,7 +51,7 @@ discard block | ||
| 51 | 51 | * | 
| 52 | 52 | * @return bool | 
| 53 | 53 | */ | 
| 54 | - public function has( $alias ); | |
| 54 | + public function has($alias); | |
| 55 | 55 | |
| 56 | 56 | /** | 
| 57 | 57 | * Removes the provided alias from the container. | 
| @@ -60,7 +60,7 @@ discard block | ||
| 60 | 60 | * | 
| 61 | 61 | * @return bool | 
| 62 | 62 | */ | 
| 63 | - public function remove( $alias ); | |
| 63 | + public function remove($alias); | |
| 64 | 64 | |
| 65 | 65 | /** | 
| 66 | 66 | * Registers a service provider with the container. | 
| @@ -72,5 +72,5 @@ discard block | ||
| 72 | 72 | * | 
| 73 | 73 | * @param ServiceProvider $provider | 
| 74 | 74 | */ | 
| 75 | - public function register( ServiceProvider $provider ); | |
| 75 | + public function register(ServiceProvider $provider); | |
| 76 | 76 | } | 
| @@ -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; | 
| @@ -59,43 +59,43 @@ discard block | ||
| 59 | 59 | * | 
| 60 | 60 | * @todo The next rule added needs to refactor this process. | 
| 61 | 61 | */ | 
| 62 | -	protected function parse_validation( $validation ) { | |
| 63 | - $validation = explode( '|', $validation ); | |
| 62 | +	protected function parse_validation($validation) { | |
| 63 | +		$validation = explode('|', $validation); | |
| 64 | 64 | |
| 65 | 65 | $rules = array(); | 
| 66 | 66 | |
| 67 | -		foreach ( $validation as $rule ) { | |
| 68 | -			if ( 0 === strpos( $rule, 'default' ) ) { | |
| 69 | - $rule_arr = explode( ':', $rule ); | |
| 67 | +		foreach ($validation as $rule) { | |
| 68 | +			if (0 === strpos($rule, 'default')) { | |
| 69 | +				$rule_arr = explode(':', $rule); | |
| 70 | 70 | |
| 71 | - $rules['default'] = count( $rule_arr ) === 2 ? array_pop( $rule_arr ) : ''; | |
| 71 | + $rules['default'] = count($rule_arr) === 2 ? array_pop($rule_arr) : ''; | |
| 72 | 72 | } | 
| 73 | 73 | |
| 74 | -			if ( 0 === strpos( $rule, 'oneof' ) ) { | |
| 75 | - list( $rule, $values ) = explode( ':', $rule ); | |
| 74 | +			if (0 === strpos($rule, 'oneof')) { | |
| 75 | +				list($rule, $values) = explode(':', $rule); | |
| 76 | 76 | |
| 77 | - $values = explode( ',', $values ); | |
| 78 | -				$callback = function ( $value ) use ( $values ) { | |
| 79 | -					if ( in_array( $value, $values, true ) ) { | |
| 77 | +				$values   = explode(',', $values); | |
| 78 | +				$callback = function($value) use ($values) { | |
| 79 | +					if (in_array($value, $values, true)) { | |
| 80 | 80 | return true; | 
| 81 | 81 | } | 
| 82 | 82 | |
| 83 | 83 | return false; | 
| 84 | 84 | }; | 
| 85 | 85 | |
| 86 | - $rules['validate_callback'] = isset( $rules['validate_callback'] ) ? $this->add_callback( $rules['validate_callback'], $callback ) : $callback; | |
| 86 | + $rules['validate_callback'] = isset($rules['validate_callback']) ? $this->add_callback($rules['validate_callback'], $callback) : $callback; | |
| 87 | 87 | } | 
| 88 | 88 | |
| 89 | -			switch ( $rule ) { | |
| 89 | +			switch ($rule) { | |
| 90 | 90 | case 'required': | 
| 91 | 91 | $rules['required'] = true; | 
| 92 | 92 | break; | 
| 93 | 93 | case 'integer': | 
| 94 | - $callback = array( $this, 'validate_integer' ); | |
| 95 | - $rules['validate_callback'] = isset( $rules['validate_callback'] ) ? $this->add_callback( $rules['validate_callback'], $callback ) : $callback; | |
| 94 | + $callback = array($this, 'validate_integer'); | |
| 95 | + $rules['validate_callback'] = isset($rules['validate_callback']) ? $this->add_callback($rules['validate_callback'], $callback) : $callback; | |
| 96 | 96 | |
| 97 | - $callback = array( $this, 'make_integer' ); | |
| 98 | - $rules['sanitize_callback'] = isset( $rules['sanitize_callback'] ) ? $this->add_callback( $rules['sanitize_callback'], $callback ) : $callback; | |
| 97 | + $callback = array($this, 'make_integer'); | |
| 98 | + $rules['sanitize_callback'] = isset($rules['sanitize_callback']) ? $this->add_callback($rules['sanitize_callback'], $callback) : $callback; | |
| 99 | 99 | break; | 
| 100 | 100 | } | 
| 101 | 101 | } | 
| @@ -110,8 +110,8 @@ discard block | ||
| 110 | 110 | * | 
| 111 | 111 | * @return bool | 
| 112 | 112 | */ | 
| 113 | -	public function validate_integer( $value ) { | |
| 114 | - return filter_var( $value, FILTER_VALIDATE_INT ) !== false; | |
| 113 | +	public function validate_integer($value) { | |
| 114 | + return filter_var($value, FILTER_VALIDATE_INT) !== false; | |
| 115 | 115 | } | 
| 116 | 116 | |
| 117 | 117 | /** | 
| @@ -121,7 +121,7 @@ discard block | ||
| 121 | 121 | * | 
| 122 | 122 | * @return int | 
| 123 | 123 | */ | 
| 124 | -	public function make_integer( $value ) { | |
| 124 | +	public function make_integer($value) { | |
| 125 | 125 | return (int) $value; | 
| 126 | 126 | } | 
| 127 | 127 | |
| @@ -133,10 +133,10 @@ discard block | ||
| 133 | 133 | * | 
| 134 | 134 | * @return \Closure; | 
| 135 | 135 | */ | 
| 136 | -	private function add_callback( $previous, $next ) { | |
| 137 | -		return function ( $value ) use ( $previous, $next ) { | |
| 138 | -			if ( call_user_func( $previous, $value ) ) { | |
| 139 | - return call_user_func( $next, $value ); | |
| 136 | +	private function add_callback($previous, $next) { | |
| 137 | +		return function($value) use ($previous, $next) { | |
| 138 | +			if (call_user_func($previous, $value)) { | |
| 139 | + return call_user_func($next, $value); | |
| 140 | 140 | } | 
| 141 | 141 | |
| 142 | 142 | return false; | 
| @@ -23,12 +23,12 @@ discard block | ||
| 23 | 23 | * | 
| 24 | 24 | * @param Container $container | 
| 25 | 25 | */ | 
| 26 | -	public function register( Container $container ) { | |
| 26 | +	public function register(Container $container) { | |
| 27 | 27 | $this->container = $container; | 
| 28 | 28 | |
| 29 | - $this->container->define( array( 'router' => 'Intraxia\Jaxion\Http\Router' ), $router = new Router ); | |
| 29 | +		$this->container->define(array('router' => 'Intraxia\Jaxion\Http\Router'), $router = new Router); | |
| 30 | 30 | |
| 31 | - $this->add_routes( $router ); | |
| 31 | + $this->add_routes($router); | |
| 32 | 32 | } | 
| 33 | 33 | |
| 34 | 34 | /** | 
| @@ -41,7 +41,7 @@ discard block | ||
| 41 | 41 | * | 
| 42 | 42 | * @codeCoverageIgnore | 
| 43 | 43 | */ | 
| 44 | -	protected function add_routes( Router $router ) { | |
| 44 | +	protected function add_routes(Router $router) { | |
| 45 | 45 | // no-op | 
| 46 | 46 | } | 
| 47 | 47 | } | 
| @@ -15,5 +15,5 @@ | ||
| 15 | 15 | * @param array $atts | 
| 16 | 16 | * @param string $content | 
| 17 | 17 | */ | 
| 18 | - public function do_shortcode( array $atts, $content = '' ); | |
| 18 | + public function do_shortcode(array $atts, $content = ''); | |
| 19 | 19 | } | 
| @@ -18,7 +18,7 @@ discard block | ||
| 18 | 18 | * | 
| 19 | 19 | * @param HasActions $service | 
| 20 | 20 | */ | 
| 21 | - public function register_actions( HasActions $service ); | |
| 21 | + public function register_actions(HasActions $service); | |
| 22 | 22 | |
| 23 | 23 | /** | 
| 24 | 24 | * Registers the service's filters with the loader. | 
| @@ -28,7 +28,7 @@ discard block | ||
| 28 | 28 | * | 
| 29 | 29 | * @param HasFilters $service | 
| 30 | 30 | */ | 
| 31 | - public function register_filters( HasFilters $service ); | |
| 31 | + public function register_filters(HasFilters $service); | |
| 32 | 32 | |
| 33 | 33 | /** | 
| 34 | 34 | * Registers the service's shortcode with the loader. | 
| @@ -38,5 +38,5 @@ discard block | ||
| 38 | 38 | * | 
| 39 | 39 | * @param HasShortcode $service | 
| 40 | 40 | */ | 
| 41 | - public function register_shortcode( HasShortcode $service ); | |
| 41 | + public function register_shortcode(HasShortcode $service); | |
| 42 | 42 | } | 
| @@ -10,5 +10,5 @@ | ||
| 10 | 10 | * | 
| 11 | 11 | * @param Container $container | 
| 12 | 12 | */ | 
| 13 | - public function register( Container $container ); | |
| 13 | + public function register(Container $container); | |
| 14 | 14 | } | 
| @@ -23,15 +23,15 @@ discard block | ||
| 23 | 23 | * | 
| 24 | 24 | * @param Container $container | 
| 25 | 25 | */ | 
| 26 | -	public function register( Container $container ) { | |
| 26 | +	public function register(Container $container) { | |
| 27 | 27 | $this->container = $container; | 
| 28 | 28 | |
| 29 | 29 | $container->define( | 
| 30 | - array( 'assets' => 'Intraxia\Jaxion\Contract\Assets\Register' ), | |
| 31 | - $register = new Register( $container->fetch( 'url' ), $container->fetch( 'version' ) ) | |
| 30 | +			array('assets' => 'Intraxia\Jaxion\Contract\Assets\Register'), | |
| 31 | +			$register = new Register($container->fetch('url'), $container->fetch('version')) | |
| 32 | 32 | ); | 
| 33 | 33 | |
| 34 | - $this->add_assets( $register ); | |
| 34 | + $this->add_assets($register); | |
| 35 | 35 | } | 
| 36 | 36 | |
| 37 | 37 | /** | 
| @@ -44,7 +44,7 @@ discard block | ||
| 44 | 44 | * | 
| 45 | 45 | * @codeCoverageIgnore | 
| 46 | 46 | */ | 
| 47 | -	protected function add_assets( Register $register ) { | |
| 47 | +	protected function add_assets(Register $register) { | |
| 48 | 48 | // no-op | 
| 49 | 49 | } | 
| 50 | 50 | } | 
| @@ -33,19 +33,19 @@ discard block | ||
| 33 | 33 |  	 * {@inheritDoc} | 
| 34 | 34 | */ | 
| 35 | 35 |  	public function run() { | 
| 36 | -		foreach ( $this->actions as $action ) { | |
| 36 | +		foreach ($this->actions as $action) { | |
| 37 | 37 | add_action( | 
| 38 | 38 | $action['hook'], | 
| 39 | - array( $action['service'], $action['method'] ), | |
| 39 | + array($action['service'], $action['method']), | |
| 40 | 40 | $action['priority'], | 
| 41 | 41 | $action['args'] | 
| 42 | 42 | ); | 
| 43 | 43 | } | 
| 44 | 44 | |
| 45 | -		foreach ( $this->filters as $filter ) { | |
| 45 | +		foreach ($this->filters as $filter) { | |
| 46 | 46 | add_filter( | 
| 47 | 47 | $filter['hook'], | 
| 48 | - array( $filter['service'], $filter['method'] ), | |
| 48 | + array($filter['service'], $filter['method']), | |
| 49 | 49 | $filter['priority'], | 
| 50 | 50 | $filter['args'] | 
| 51 | 51 | ); | 
| @@ -57,15 +57,15 @@ discard block | ||
| 57 | 57 | * | 
| 58 | 58 | * @param HasActions $service | 
| 59 | 59 | */ | 
| 60 | -	public function register_actions( HasActions $service ) { | |
| 61 | -		foreach ( $service->action_hooks() as $action ) { | |
| 60 | +	public function register_actions(HasActions $service) { | |
| 61 | +		foreach ($service->action_hooks() as $action) { | |
| 62 | 62 | $this->actions = $this->add( | 
| 63 | 63 | $this->actions, | 
| 64 | 64 | $action['hook'], | 
| 65 | 65 | $service, | 
| 66 | 66 | $action['method'], | 
| 67 | - isset( $action['priority'] ) ? $action['priority'] : 10, | |
| 68 | - isset( $action['args'] ) ? $action['args'] : 1 | |
| 67 | + isset($action['priority']) ? $action['priority'] : 10, | |
| 68 | + isset($action['args']) ? $action['args'] : 1 | |
| 69 | 69 | ); | 
| 70 | 70 | } | 
| 71 | 71 | } | 
| @@ -75,15 +75,15 @@ discard block | ||
| 75 | 75 | * | 
| 76 | 76 | * @param HasFilters $service | 
| 77 | 77 | */ | 
| 78 | -	public function register_filters( HasFilters $service ) { | |
| 79 | -		foreach ( $service->filter_hooks() as $filter ) { | |
| 78 | +	public function register_filters(HasFilters $service) { | |
| 79 | +		foreach ($service->filter_hooks() as $filter) { | |
| 80 | 80 | $this->filters = $this->add( | 
| 81 | 81 | $this->filters, | 
| 82 | 82 | $filter['hook'], | 
| 83 | 83 | $service, | 
| 84 | 84 | $filter['method'], | 
| 85 | - isset( $filter['priority'] ) ? $filter['priority'] : 10, | |
| 86 | - isset( $filter['args'] ) ? $filter['args'] : 1 | |
| 85 | + isset($filter['priority']) ? $filter['priority'] : 10, | |
| 86 | + isset($filter['args']) ? $filter['args'] : 1 | |
| 87 | 87 | ); | 
| 88 | 88 | } | 
| 89 | 89 | } | 
| @@ -93,8 +93,8 @@ discard block | ||
| 93 | 93 | * | 
| 94 | 94 | * @param HasShortcode $service | 
| 95 | 95 | */ | 
| 96 | -	public function register_shortcode( HasShortcode $service ) { | |
| 97 | - add_shortcode( $service->shortcode_name(), array( $service, 'do_shortcode' ) ); | |
| 96 | +	public function register_shortcode(HasShortcode $service) { | |
| 97 | + add_shortcode($service->shortcode_name(), array($service, 'do_shortcode')); | |
| 98 | 98 | } | 
| 99 | 99 | |
| 100 | 100 | /** | 
| @@ -109,7 +109,7 @@ discard block | ||
| 109 | 109 | * | 
| 110 | 110 | * @return array | 
| 111 | 111 | */ | 
| 112 | -	protected function add( $hooks, $hook, $service, $method, $priority, $accepted_args ) { | |
| 112 | +	protected function add($hooks, $hook, $service, $method, $priority, $accepted_args) { | |
| 113 | 113 | $hooks[] = array( | 
| 114 | 114 | 'hook' => $hook, | 
| 115 | 115 | 'service' => $service, |