Passed
Pull Request — master (#30)
by Guillaume
34:24 queued 30:24
created

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