Passed
Branch master (2fcc75)
by Paul
11:46
created

TogglePinned   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
eloc 16
c 3
b 0
f 2
dl 0
loc 25
ccs 0
cts 20
cp 0
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 20 5
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Handlers;
4
5
use GeminiLabs\SiteReviews\Commands\TogglePinned as Command;
6
use GeminiLabs\SiteReviews\Database;
7
use GeminiLabs\SiteReviews\Modules\Notice;
8
9
class TogglePinned
10
{
11
    /**
12
     * @return bool
13
     */
14
    public function handle(Command $command)
15
    {
16
        if (!get_post($command->id)) {
17
            return false;
18
        }
19
        if (!glsr()->can('edit_others_posts')) {
20
            $meta = (Database::class)->get($command->id, 'pinned');
21
            return wp_validate_boolean($meta);
22
        }
23
        if (is_null($command->pinned)) {
24
            $meta = glsr(Database::class)->get($command->id, 'pinned');
25
            $command->pinned = !wp_validate_boolean($meta);
26
        } else {
27
            $notice = $command->pinned
28
                ? __('Review pinned.', 'site-reviews')
29
                : __('Review unpinned.', 'site-reviews');
30
            glsr(Notice::class)->addSuccess($notice);
31
        }
32
        glsr(Database::class)->update($command->id, 'pinned', $command->pinned);
33
        return $command->pinned;
34
    }
35
}
36