@@ -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 |
33 | 33 | * @return object |
34 | 34 | */ |
35 | - public function process( object $class ): object { |
|
36 | - if ( is_a( $class, Ajax::class ) |
|
35 | + public function process(object $class): object { |
|
36 | + if (is_a($class, Ajax::class) |
|
37 | 37 | && is_admin() |
38 | 38 | && wp_doing_ajax() |
39 | 39 | ) { |
40 | - $this->dispatcher->add_ajax_call( $class ); |
|
40 | + $this->dispatcher->add_ajax_call($class); |
|
41 | 41 | } |
42 | 42 | return $class; |
43 | 43 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | |
24 | 24 | class Ajax implements Module { |
25 | 25 | |
26 | - public function __construct( DI_Container $di_container ) { |
|
26 | + public function __construct(DI_Container $di_container) { |
|
27 | 27 | $di_container->addRule( |
28 | 28 | '*', |
29 | 29 | array( |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | } |
43 | 43 | |
44 | 44 | ## Unused methods |
45 | - public function pre_register( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
|
46 | - public function pre_boot( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
|
47 | - public function post_register( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
|
45 | + public function pre_register(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
|
46 | + public function pre_boot(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
|
47 | + public function post_register(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
|
48 | 48 | } |
@@ -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 |
@@ -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( \get_class( $ajax ) ); |
|
51 | + if ( ! $ajax->has_valid_action()) { |
|
52 | + throw Ajax_Exception::undefined_action(\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 | ); |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | |
35 | 35 | protected HTTP $http; |
36 | 36 | |
37 | - public function __construct( HTTP $http ) { |
|
37 | + public function __construct(HTTP $http) { |
|
38 | 38 | $this->http = $http; |
39 | 39 | } |
40 | 40 | |
@@ -44,11 +44,11 @@ discard block |
||
44 | 44 | * @param int $code The HTTP status code. Defaults to 200. |
45 | 45 | * @param string $reasonPhrase |
46 | 46 | */ |
47 | - public function createResponse( int $code = 200, string $reasonPhrase = '' ): ResponseInterface { |
|
47 | + public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface { |
|
48 | 48 | return $this->http->psr7_response() |
49 | - ->withStatus( $code ) |
|
50 | - ->withHeader( 'Content-Type', 'application/json; charset=' . get_option( 'blog_charset' ) ) |
|
51 | - ->withBody( Stream::create( $reasonPhrase ) ); |
|
49 | + ->withStatus($code) |
|
50 | + ->withHeader('Content-Type', 'application/json; charset=' . get_option('blog_charset')) |
|
51 | + ->withBody(Stream::create($reasonPhrase)); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | * @param array<mixed> $payload |
58 | 58 | * @return ResponseInterface |
59 | 59 | */ |
60 | - public function success( array $payload = array() ): ResponseInterface { |
|
61 | - return $this->createResponse( 200, json_encode( $payload ) ?: '' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode |
|
60 | + public function success(array $payload = array()): ResponseInterface { |
|
61 | + return $this->createResponse(200, json_encode($payload) ?: ''); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | * @param array<mixed> $payload |
69 | 69 | * @return ResponseInterface |
70 | 70 | */ |
71 | - public function unauthorised( array $payload = array( 'error' => 'unauthorised' ) ): ResponseInterface { |
|
72 | - return $this->createResponse( 401, json_encode( $payload ) ?: '' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode |
|
71 | + public function unauthorised(array $payload = array('error' => 'unauthorised')): ResponseInterface { |
|
72 | + return $this->createResponse(401, json_encode($payload) ?: ''); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | * @param array<mixed> $payload |
80 | 80 | * @return ResponseInterface |
81 | 81 | */ |
82 | - public function failure( array $payload = array( 'error' => 'error' ) ): ResponseInterface { |
|
83 | - return $this->createResponse( 500, json_encode( $payload ) ?: '' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode |
|
82 | + public function failure(array $payload = array('error' => 'error')): ResponseInterface { |
|
83 | + return $this->createResponse(500, json_encode($payload) ?: ''); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param array<mixed> $payload |
91 | 91 | * @return ResponseInterface |
92 | 92 | */ |
93 | - public function not_found( array $payload = array( 'error' => 'not found' ) ): ResponseInterface { |
|
94 | - return $this->createResponse( 404, json_encode( $payload ) ?: '' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode |
|
93 | + public function not_found(array $payload = array('error' => 'not found')): ResponseInterface { |
|
94 | + return $this->createResponse(404, json_encode($payload) ?: ''); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode |
|
95 | 95 | } |
96 | 96 | } |