| Total Complexity | 7 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Coverage | 27.27% |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | abstract class Controller |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @return void |
||
| 15 | */ |
||
| 16 | public function download($filename, $content) |
||
| 17 | { |
||
| 18 | if (!glsr()->can('edit_others_posts')) { |
||
| 19 | return; |
||
| 20 | } |
||
| 21 | nocache_headers(); |
||
| 22 | header('Content-Type: text/plain'); |
||
| 23 | header('Content-Disposition: attachment; filename="'.$filename.'"'); |
||
| 24 | echo html_entity_decode($content); |
||
| 25 | exit; |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param object $command |
||
| 30 | * @return mixed |
||
| 31 | * @throws InvalidArgumentException |
||
| 32 | */ |
||
| 33 | 1 | public function execute($command) |
|
| 34 | { |
||
| 35 | 1 | $handlerClass = str_replace('Commands', 'Handlers', get_class($command)); |
|
| 36 | 1 | if (!class_exists($handlerClass)) { |
|
| 37 | throw new InvalidArgumentException('Handler '.$handlerClass.' not found.'); |
||
| 38 | } |
||
| 39 | try { |
||
| 40 | 1 | return glsr($handlerClass)->handle($command); |
|
| 41 | } catch (Exception $e) { |
||
| 42 | status_header(400); |
||
| 43 | glsr(Notice::class)->addError(new WP_Error('site_reviews_error', $e->getMessage())); |
||
| 44 | glsr_log()->error($e->getMessage()); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @return int |
||
| 50 | */ |
||
| 51 | protected function getPostId() |
||
| 52 | { |
||
| 53 | return intval(filter_input(INPUT_GET, 'post')); |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @param int $postId |
||
| 58 | * @return bool |
||
| 59 | */ |
||
| 60 | 1 | protected function isReviewPostId($postId) |
|
| 63 | } |
||
| 64 | } |
||
| 65 |