SetupState::toEnable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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