Passed
Pull Request — master (#30)
by Guillaume
38:15 queued 36:45
created

Setup::back()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Godbout\Alfred\Time\Menus\Clockify;
4
5
use Godbout\Alfred\Time\Menus\Menu;
6
use Godbout\Alfred\Time\Workflow;
7
use Godbout\Alfred\Workflow\Icon;
8
use Godbout\Alfred\Workflow\Item;
9
use Godbout\Alfred\Workflow\ScriptFilter;
10
11
class Setup extends Menu
12
{
13 5
    public static function scriptFilter()
14
    {
15 5
        ScriptFilter::add(
16 5
            self::apikey(),
17 5
            self::state(),
18 5
            self::back()
19
        );
20 5
    }
21
22 5
    private static function apikey()
23
    {
24 5
        return Item::create()
25 5
            ->title(self::apikeyTitle())
26 5
            ->subtitle(self::apikeySubtitle())
27 5
            ->arg('clockify_setup_apikey')
28 5
            ->icon(Icon::create('resources/icons/clockify.png'));
29
    }
30
31 5
    private static function apikeyTitle()
32
    {
33 5
        return empty(Workflow::getConfig()->read('clockify.api_token')) ? 'Set API KEY' : 'Update API KEY';
34
    }
35
36 5
    private static function apikeySubtitle()
37
    {
38 5
        $apikey = Workflow::getConfig()->read('clockify.api_token');
39
40 5
        return empty($apikey) ? 'No API KEY found' : 'Current API KEY: ' . substr($apikey, 0, 11) . '...';
41
    }
42
43 5
    private static function state()
44
    {
45 5
        return Item::create()
46 5
            ->title(self::stateTitle())
47 5
            ->subtitle(self::stateSubtitle())
48 5
            ->arg('clockify_setup_state')
49 5
            ->variable('clockify_enabled', Workflow::getConfig()->read('clockify.is_active') ? 'false' : 'true')
50 5
            ->icon(Icon::create('resources/icons/clockify.png'));
51
    }
52
53 5
    private static function stateTitle()
54
    {
55 5
        return (Workflow::getConfig()->read('clockify.is_active') === true) ? 'Disable' : 'Enable';
56
    }
57
58 5
    private static function stateSubtitle()
59
    {
60 5
        return (Workflow::getConfig()->read('clockify.is_active') === true) ? 'Currently enabled' : 'Currently disabled';
61
    }
62
63 5
    private static function back()
64
    {
65 5
        return Item::create()
66 5
            ->title('Back')
67 5
            ->arg('setup')
68 5
            ->icon(Icon::create('resources/icons/icon.png'));
69
    }
70
}
71