| Total Complexity | 9 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | class Rest_Api_Handler extends JsonResponseHandler { |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @return bool |
||
| 16 | */ |
||
| 17 | private function isRestRequest() { |
||
|
1 ignored issue
–
show
|
|||
| 18 | |||
| 19 | if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { |
||
| 20 | return true; |
||
| 21 | } |
||
| 22 | |||
| 23 | // This is dirty, but no better way to detect before parse_request. |
||
| 24 | if ( ! empty( $_SERVER['REQUEST_URI'] ) && 0 !== stripos( $_SERVER['REQUEST_URI'], rest_get_url_prefix() ) ) { |
||
| 25 | return true; |
||
| 26 | } |
||
| 27 | |||
| 28 | return false; |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @return int |
||
| 33 | */ |
||
| 34 | public function handle() { |
||
| 57 | } |
||
| 58 | } |
||
| 59 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: