Completed
Push — master ( 3b0b6a...263c36 )
by Guillaume
02:53
created

Setup::credentials()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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