Setup   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 59
ccs 33
cts 33
cp 1
rs 10
c 0
b 0
f 0
wmc 13

8 Methods

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