Passed
Push — develop ( 39ad60...0ca1de )
by Paul
14:09
created

SearchAssignedPosts   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 20
dl 0
loc 28
ccs 0
cts 21
cp 0
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 26 4
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\Bricks\Commands;
4
5
use GeminiLabs\SiteReviews\Database;
6
7
class SearchAssignedPosts extends AbstractSearchCommand
8
{
9
    public function handle(): void
10
    {
11
        $this->verifyNonce();
12
        $args = [
13
            'post__in' => [],
14
            'posts_per_page' => 25,
15
        ];
16
        if (is_numeric($this->search)) {
17
            $args['post__in'][] = (int) $this->search;
18
        } else {
19
            $args['s'] = $this->search;
20
        }
21
        $results = glsr(Database::class)->posts($args);
22
        if ($missingIds = $this->missingIds($results, $this->include)) {
23
            $results += glsr(Database::class)->posts([
24
                'post__in' => $missingIds,
25
            ]);
26
        }
27
        $formatted = $this->formatResults($results);
28
        if (empty($this->search)) {
29
            $formatted = [
30
                'post_id' => esc_html_x('The Current Page', 'admin-text', 'site-reviews'),
31
                'parent_id' => esc_html_x('The Parent Page', 'admin-text', 'site-reviews'),
32
            ] + $formatted;
33
        }
34
        $this->response = $formatted;
35
    }
36
}
37