@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | * @param string $operation The operation being carries out. |
| 36 | 36 | * @return Ajax_Exception |
| 37 | 37 | */ |
| 38 | - public static function non_ajax_model( string $operation = 'unknown operation' ): Ajax_Exception { |
|
| 38 | + public static function non_ajax_model(string $operation = 'unknown operation'): Ajax_Exception { |
|
| 39 | 39 | $message = 'None Ajax Model passed to ' . $operation; |
| 40 | - return new Ajax_Exception( $message, 100 ); |
|
| 40 | + return new Ajax_Exception($message, 100); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -47,8 +47,8 @@ discard block |
||
| 47 | 47 | * @param string $class_string Ajax class |
| 48 | 48 | * @return Ajax_Exception |
| 49 | 49 | */ |
| 50 | - public static function undefined_action( string $class_string ): Ajax_Exception { |
|
| 50 | + public static function undefined_action(string $class_string): Ajax_Exception { |
|
| 51 | 51 | $message = "{$class_string} has no defined action property"; |
| 52 | - return new Ajax_Exception( $message, 101 ); |
|
| 52 | + return new Ajax_Exception($message, 101); |
|
| 53 | 53 | } |
| 54 | 54 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | protected Hook_Loader $loader; |
| 35 | 35 | protected Ajax_Controller $ajax_controller; |
| 36 | 36 | |
| 37 | - public function __construct( Ajax_Controller $ajax_controller ) { |
|
| 37 | + public function __construct(Ajax_Controller $ajax_controller) { |
|
| 38 | 38 | $this->loader = new Hook_Loader(); |
| 39 | 39 | $this->ajax_controller = $ajax_controller; |
| 40 | 40 | } |
@@ -46,15 +46,15 @@ discard block |
||
| 46 | 46 | * @return void |
| 47 | 47 | * @throws Ajax_Exception (code 101) If no action defined |
| 48 | 48 | */ |
| 49 | - public function add_ajax_call( Ajax $ajax ): void { |
|
| 49 | + public function add_ajax_call(Ajax $ajax): void { |
|
| 50 | 50 | |
| 51 | - if ( ! $ajax->has_valid_action() ) { |
|
| 52 | - throw Ajax_Exception::undefined_action( esc_attr( \get_class( $ajax ) ) ); |
|
| 51 | + if ( ! $ajax->has_valid_action()) { |
|
| 52 | + throw Ajax_Exception::undefined_action(esc_attr(\get_class($ajax))); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | $this->loader->ajax( |
| 56 | 56 | $ajax->get_action(), /* @phpstan-ignore-line, action existance checked above */ |
| 57 | - $this->ajax_controller->create_callback( $ajax ), |
|
| 57 | + $this->ajax_controller->create_callback($ajax), |
|
| 58 | 58 | $ajax->get_logged_out(), |
| 59 | 59 | $ajax->get_logged_in() |
| 60 | 60 | ); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | protected ServerRequestInterface $server_request; |
| 35 | 35 | |
| 36 | - public function __construct( ServerRequestInterface $server_request ) { |
|
| 36 | + public function __construct(ServerRequestInterface $server_request) { |
|
| 37 | 37 | $this->server_request = $server_request; |
| 38 | 38 | } |
| 39 | 39 | |
@@ -43,22 +43,22 @@ discard block |
||
| 43 | 43 | * @param \PinkCrab\Ajax\Ajax $ajax |
| 44 | 44 | * @return bool |
| 45 | 45 | */ |
| 46 | - public function validate( Ajax $ajax ): bool { |
|
| 47 | - if ( ! $ajax->has_nonce() ) { |
|
| 46 | + public function validate(Ajax $ajax): bool { |
|
| 47 | + if ( ! $ajax->has_nonce()) { |
|
| 48 | 48 | return true; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | // Find nonce value in request |
| 52 | - $nonce_value = $this->find_nonce( $ajax->get_nonce_field() ); |
|
| 52 | + $nonce_value = $this->find_nonce($ajax->get_nonce_field()); |
|
| 53 | 53 | |
| 54 | 54 | // If no nonce value found in request. |
| 55 | - if ( is_null( $nonce_value ) ) { |
|
| 55 | + if (is_null($nonce_value)) { |
|
| 56 | 56 | return false; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /* @phpstan-ignore-next-line, nonce handle checked at start of method*/ |
| 60 | - return ( new Nonce( $ajax->get_nonce_handle() ) ) |
|
| 61 | - ->validate( $nonce_value ); |
|
| 60 | + return (new Nonce($ajax->get_nonce_handle())) |
|
| 61 | + ->validate($nonce_value); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -67,11 +67,11 @@ discard block |
||
| 67 | 67 | * @param string $nonce_field |
| 68 | 68 | * @return string|null |
| 69 | 69 | */ |
| 70 | - protected function find_nonce( string $nonce_field ): ?string { |
|
| 71 | - $args = Ajax_Helper::extract_server_request_args( $this->server_request ); |
|
| 70 | + protected function find_nonce(string $nonce_field): ?string { |
|
| 71 | + $args = Ajax_Helper::extract_server_request_args($this->server_request); |
|
| 72 | 72 | |
| 73 | - return \array_key_exists( $nonce_field, $args ) |
|
| 74 | - ? $args[ $nonce_field ] |
|
| 73 | + return \array_key_exists($nonce_field, $args) |
|
| 74 | + ? $args[$nonce_field] |
|
| 75 | 75 | : null; |
| 76 | 76 | } |
| 77 | 77 | } |
@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | * @param \PinkCrab\Ajax\Ajax $ajax_class |
| 58 | 58 | * @return bool |
| 59 | 59 | */ |
| 60 | - public function validate_request( Ajax $ajax_class ): bool { |
|
| 61 | - return $this->request_validator->validate( $ajax_class ); |
|
| 60 | + public function validate_request(Ajax $ajax_class): bool { |
|
| 61 | + return $this->request_validator->validate($ajax_class); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | * @return \Psr\Http\Message\ResponseInterface |
| 69 | 69 | * @filter Ajax_Hooks::CALLBACK_REQUEST_FILTER |
| 70 | 70 | */ |
| 71 | - public function invoke_callback( Ajax $ajax_class ): ResponseInterface { |
|
| 71 | + public function invoke_callback(Ajax $ajax_class): ResponseInterface { |
|
| 72 | 72 | return $ajax_class->callback( |
| 73 | - \apply_filters( Ajax_Hooks::CALLBACK_REQUEST_FILTER, $this->server_request, $ajax_class ), |
|
| 73 | + \apply_filters(Ajax_Hooks::CALLBACK_REQUEST_FILTER, $this->server_request, $ajax_class), |
|
| 74 | 74 | $this->response_factory |
| 75 | 75 | ); |
| 76 | 76 | } |
@@ -84,32 +84,32 @@ discard block |
||
| 84 | 84 | * @action Ajax_Hooks::CALLBACK_EXECUTION_EXCEPTION |
| 85 | 85 | * @filter Ajax_Hooks::CALLBACK_RESPONSE_FILTER |
| 86 | 86 | */ |
| 87 | - public function create_callback( Ajax $ajax_class ): Closure { |
|
| 87 | + public function create_callback(Ajax $ajax_class): Closure { |
|
| 88 | 88 | /** |
| 89 | 89 | * @param \PinkCrab\Ajax\Ajax $ajax_class |
| 90 | 90 | * @return noreturn |
| 91 | 91 | */ |
| 92 | - return function () use ( $ajax_class ): void { |
|
| 92 | + return function() use ($ajax_class): void { |
|
| 93 | 93 | |
| 94 | 94 | $valid_nonce = apply_filters( |
| 95 | 95 | Ajax_Hooks::REQUEST_NONCE_VERIFICATION, |
| 96 | - $this->validate_request( $ajax_class ), |
|
| 96 | + $this->validate_request($ajax_class), |
|
| 97 | 97 | $ajax_class, |
| 98 | 98 | $this->server_request |
| 99 | 99 | ); |
| 100 | 100 | |
| 101 | 101 | try { |
| 102 | 102 | $response = $valid_nonce |
| 103 | - ? $this->invoke_callback( $ajax_class ) |
|
| 103 | + ? $this->invoke_callback($ajax_class) |
|
| 104 | 104 | : $this->response_factory->unauthorised(); |
| 105 | - } catch ( Exception $th ) { |
|
| 105 | + } catch (Exception $th) { |
|
| 106 | 106 | |
| 107 | - do_action( Ajax_Hooks::CALLBACK_EXECUTION_EXCEPTION, $th, $ajax_class ); |
|
| 107 | + do_action(Ajax_Hooks::CALLBACK_EXECUTION_EXCEPTION, $th, $ajax_class); |
|
| 108 | 108 | |
| 109 | - $response = $this->response_factory->failure( array( 'error' => $th->getMessage() ) ); |
|
| 109 | + $response = $this->response_factory->failure(array('error' => $th->getMessage())); |
|
| 110 | 110 | } |
| 111 | 111 | $this->http_helper->emit_psr7_response( |
| 112 | - \apply_filters( Ajax_Hooks::CALLBACK_RESPONSE_FILTER, $response, $ajax_class, $this->server_request ) |
|
| 112 | + \apply_filters(Ajax_Hooks::CALLBACK_RESPONSE_FILTER, $response, $ajax_class, $this->server_request) |
|
| 113 | 113 | ); |
| 114 | 114 | |
| 115 | 115 | \wp_die(); |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | public Ajax_Dispatcher $dispatcher; |
| 24 | 24 | |
| 25 | - public function __construct( Ajax_Dispatcher $dispatcher ) { |
|
| 25 | + public function __construct(Ajax_Dispatcher $dispatcher) { |
|
| 26 | 26 | $this->dispatcher = $dispatcher; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -32,12 +32,12 @@ discard block |
||
| 32 | 32 | * @param object $class_instance |
| 33 | 33 | * @return object |
| 34 | 34 | */ |
| 35 | - public function process( object $class_instance ): object { |
|
| 36 | - if ( is_a( $class_instance, Ajax::class ) |
|
| 35 | + public function process(object $class_instance): object { |
|
| 36 | + if (is_a($class_instance, Ajax::class) |
|
| 37 | 37 | && is_admin() |
| 38 | 38 | && wp_doing_ajax() |
| 39 | 39 | ) { |
| 40 | - $this->dispatcher->add_ajax_call( $class_instance ); |
|
| 40 | + $this->dispatcher->add_ajax_call($class_instance); |
|
| 41 | 41 | } |
| 42 | 42 | return $class_instance; |
| 43 | 43 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * @return string |
| 50 | 50 | */ |
| 51 | 51 | public static function admin_ajax_url(): string { |
| 52 | - return admin_url( 'admin-ajax.php' ); |
|
| 52 | + return admin_url('admin-ajax.php'); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -60,17 +60,17 @@ discard block |
||
| 60 | 60 | * @return Ajax |
| 61 | 61 | * @throws Ajax_Exception (code 100) If non valid Ajax class passed. |
| 62 | 62 | */ |
| 63 | - private static function get_reflected( string $class_string ): Ajax { |
|
| 64 | - if ( ! \is_subclass_of( $class_string, Ajax::class ) ) { |
|
| 65 | - throw Ajax_Exception::non_ajax_model( 'get reflection' ); |
|
| 63 | + private static function get_reflected(string $class_string): Ajax { |
|
| 64 | + if ( ! \is_subclass_of($class_string, Ajax::class)) { |
|
| 65 | + throw Ajax_Exception::non_ajax_model('get reflection'); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - if ( ! array_key_exists( $class_string, self::$class_cache ) ) { |
|
| 69 | - $reflection = new ReflectionClass( $class_string ); |
|
| 70 | - self::$class_cache[ $class_string ] = $reflection->newInstanceWithoutConstructor(); |
|
| 68 | + if ( ! array_key_exists($class_string, self::$class_cache)) { |
|
| 69 | + $reflection = new ReflectionClass($class_string); |
|
| 70 | + self::$class_cache[$class_string] = $reflection->newInstanceWithoutConstructor(); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - return self::$class_cache[ $class_string ]; |
|
| 73 | + return self::$class_cache[$class_string]; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -82,11 +82,11 @@ discard block |
||
| 82 | 82 | * @throws Ajax_Exception (code 100) If non valid Ajax class passed. |
| 83 | 83 | * @throws Ajax_Exception (code 101) If no action defined |
| 84 | 84 | */ |
| 85 | - public static function get_action( string $class_string ): ?string { |
|
| 86 | - $instance = self::get_reflected( $class_string ); |
|
| 85 | + public static function get_action(string $class_string): ?string { |
|
| 86 | + $instance = self::get_reflected($class_string); |
|
| 87 | 87 | |
| 88 | - if ( ! $instance->has_valid_action() ) { |
|
| 89 | - throw Ajax_Exception::undefined_action( esc_attr( $class_string ) ); |
|
| 88 | + if ( ! $instance->has_valid_action()) { |
|
| 89 | + throw Ajax_Exception::undefined_action(esc_attr($class_string)); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | return $instance->get_action(); |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | * @return boolean |
| 100 | 100 | * @throws Ajax_Exception (code 100) If non valid Ajax class passed. |
| 101 | 101 | */ |
| 102 | - public static function has_nonce( string $class_string ): bool { |
|
| 103 | - return self::get_reflected( $class_string )->has_nonce(); |
|
| 102 | + public static function has_nonce(string $class_string): bool { |
|
| 103 | + return self::get_reflected($class_string)->has_nonce(); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | * @return Nonce|null |
| 111 | 111 | * @throws Ajax_Exception (code 100) If non valid Ajax class passed. |
| 112 | 112 | */ |
| 113 | - public static function get_nonce( string $class_string ): ?Nonce { |
|
| 114 | - $instance = self::get_reflected( $class_string ); |
|
| 113 | + public static function get_nonce(string $class_string): ?Nonce { |
|
| 114 | + $instance = self::get_reflected($class_string); |
|
| 115 | 115 | |
| 116 | 116 | return $instance->has_nonce() |
| 117 | - ? new Nonce( $instance->get_nonce_handle() ?? '' ) // has_nonce conditional should catch null here |
|
| 117 | + ? new Nonce($instance->get_nonce_handle() ?? '') // has_nonce conditional should catch null here |
|
| 118 | 118 | : null; |
| 119 | 119 | } |
| 120 | 120 | |
@@ -125,8 +125,8 @@ discard block |
||
| 125 | 125 | * @return string |
| 126 | 126 | * @throws Ajax_Exception (code 100) If non valid Ajax class passed. |
| 127 | 127 | */ |
| 128 | - public static function get_nonce_field( string $class_string ): string { |
|
| 129 | - return self::get_reflected( $class_string )->get_nonce_field(); |
|
| 128 | + public static function get_nonce_field(string $class_string): string { |
|
| 129 | + return self::get_reflected($class_string)->get_nonce_field(); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -136,14 +136,14 @@ discard block |
||
| 136 | 136 | * @param ServerRequestInterface $request |
| 137 | 137 | * @return array<string, string> |
| 138 | 138 | */ |
| 139 | - public static function extract_server_request_args( ServerRequestInterface $request ): array { |
|
| 140 | - switch ( $request->getMethod() ) { |
|
| 139 | + public static function extract_server_request_args(ServerRequestInterface $request): array { |
|
| 140 | + switch ($request->getMethod()) { |
|
| 141 | 141 | case 'POST': |
| 142 | 142 | // Return different post types. |
| 143 | - if ( str_contains( $request->getHeaderLine( 'Content-Type' ), 'application/x-www-form-urlencoded;' ) ) { |
|
| 143 | + if (str_contains($request->getHeaderLine('Content-Type'), 'application/x-www-form-urlencoded;')) { |
|
| 144 | 144 | $params = (array) $request->getParsedBody(); |
| 145 | 145 | } else { |
| 146 | - $params = json_decode( (string) $request->getBody(), true ) ?? array(); |
|
| 146 | + $params = json_decode((string) $request->getBody(), true) ?? array(); |
|
| 147 | 147 | } |
| 148 | 148 | break; |
| 149 | 149 | case 'GET': |