Passed
Push — master ( 6b35fa...ccb079 )
by Paul
10:24 queued 05:13
created

Controller::isReviewAdminPage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 6
rs 10
c 1
b 0
f 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A Controller::isReviewPostId() 0 3 1
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Controllers;
4
5
use Exception;
6
use GeminiLabs\SiteReviews\Application;
7
use GeminiLabs\SiteReviews\Modules\Notice;
8
use InvalidArgumentException;
9
use WP_Error;
10
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)
61
    {
62 1
        return Application::POST_TYPE == get_post_field('post_type', $postId);
63
    }
64
}
65