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

Setup::stateSubtitle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

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