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