Passed
Push — main ( a0e9c5...805967 )
by Paul
07:42
created

FlyoutController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 32
c 1
b 0
f 0
dl 0
loc 59
ccs 0
cts 46
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A renderFlyout() 0 14 4
A menuItems() 0 37 2
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Controllers;
4
5
use GeminiLabs\SiteReviews\Defaults\FlyoutItemDefaults;
6
use GeminiLabs\SiteReviews\Helpers\Str;
7
use GeminiLabs\SiteReviews\License;
8
9
class FlyoutController extends Controller
10
{
11
    /**
12
     * @action admin_footer
13
     */
14
    public function renderFlyout(): void
15
    {
16
        $screen = glsr_current_screen();
17
        if ('post' === $screen->base) {
18
            return;
19
        }
20
        if (!Str::startsWith($screen->post_type, glsr()->post_type)) {
21
            return;
22
        }
23
        if (!glsr()->filterBool('flyoutmenu/enabled', true)) {
24
            return;
25
        }
26
        glsr()->render('views/partials/flyoutmenu', [
27
            'items' => $this->menuItems(),
28
        ]);
29
    }
30
31
    protected function menuItems(): array
32
    {
33
        $items = [
34
            [
35
                'icon' => 'dashicons-star-filled',
36
                'title' => _x('Upgrade to Premium', 'admin-text', 'site-reviews'),
37
                'url' => 'https://niftyplugins.com/plugins/site-reviews-premium/',
38
            ],
39
            [
40
                'icon' => 'dashicons-editor-help',
41
                'title' => _x('Learn the Basics', 'admin-text', 'site-reviews'),
42
                'url' => glsr_admin_url('welcome'),
43
            ],
44
            [
45
                'icon' => 'dashicons-youtube',
46
                'title' => _x('Watch a Tutorial', 'admin-text', 'site-reviews'),
47
                'url' => 'https://youtu.be/H5HdMCXvuq8',
48
            ],
49
            [
50
                'icon' => 'dashicons-sos',
51
                'title' => _x('Read the Documentation', 'admin-text', 'site-reviews'),
52
                'url' => glsr_admin_url('documentation'),
53
            ],
54
            [
55
                'icon' => 'dashicons-wordpress-alt',
56
                'title' => _x('Ask for Help', 'admin-text', 'site-reviews'),
57
                'url' => 'https://wordpress.org/support/plugin/site-reviews/',
58
            ],
59
        ];
60
        if (glsr(License::class)->isLicensed()) {
61
            array_shift($items);
62
        }
63
        $items = glsr()->filterArray('flyoutmenu/items', $items);
64
        array_walk($items, function (&$item) {
65
            $item = glsr(FlyoutItemDefaults::class)->restrict($item);
66
        });
67
        return $items;
68
    }
69
}
70