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

Setup   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 5
dl 0
loc 61
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A scriptFilter() 0 8 1
A credentials() 0 8 1
A credentialsTitle() 0 4 2
A credentialsFound() 0 7 2
A state() 0 9 2
A stateTitle() 0 4 2
A stateSubtitle() 0 4 2
A back() 0 7 1
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