Setup::credentialsFound()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 2
rs 10
c 0
b 0
f 0
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