SetupState   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 51
ccs 29
cts 29
cp 1
rs 10
c 0
b 0
f 0
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A scriptFilter() 0 7 1
A stateSaved() 0 8 1
A stateSubtitle() 0 3 2
A back() 0 7 1
A toEnable() 0 3 1
A saveState() 0 5 2
A stateTitle() 0 3 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 SetupState extends Menu
12
{
13 18
    public static function scriptFilter()
14
    {
15 18
        self::saveState();
16
17 18
        ScriptFilter::add(
18 18
            self::stateSaved(),
19 18
            self::back()
20
        );
21 18
    }
22
23 18
    private static function saveState()
24
    {
25 18
        Workflow::disableAllServices();
26
27 18
        self::toEnable() ? Workflow::enableService('harvest') : Workflow::disableService('harvest');
28 18
    }
29
30 18
    private static function stateSaved()
31
    {
32 18
        return Item::create()
33 18
            ->title(self::stateTitle())
34 18
            ->subtitle(self::stateSubtitle())
35 18
            ->icon(Icon::create('resources/icons/harvest.png'))
36 18
            ->arg('do')
37 18
            ->variable('action', 'exit');
38
    }
39
40 18
    private static function stateTitle()
41
    {
42 18
        return 'Harvest ' . (self::toEnable() ? 'ENABLED!' : 'DISABLED!');
43
    }
44
45 18
    protected static function stateSubtitle()
46
    {
47 18
        return (self::toEnable() ? 'Other services disabled. ': '') . 'You may press enter to quit the workflow';
48
    }
49
50 18
    private static function back()
51
    {
52 18
        return Item::create()
53 18
            ->title('Back')
54 18
            ->subtitle('Go back to Harvest options')
55 18
            ->arg('harvest_setup')
56 18
            ->icon(Icon::create('resources/icons/harvest.png'));
57
    }
58
59 18
    protected static function toEnable()
60
    {
61 18
        return getenv('harvest_enabled') === 'true';
62
    }
63
}
64