Passed
Push — master ( 853bda...782fe1 )
by Guillaume
06:08
created

Entrance::timerAction()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 0
dl 0
loc 13
ccs 6
cts 7
cp 0.8571
crap 3.0261
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Godbout\Alfred\Time\Menus;
4
5
use Godbout\Alfred\Time\Workflow;
6
use Godbout\Alfred\Workflow\Icon;
7
use Godbout\Alfred\Workflow\Item;
8
use Godbout\Alfred\Workflow\Mods\Cmd;
9
use Godbout\Alfred\Workflow\ScriptFilter;
10
11
class Entrance extends Menu
12
{
13 48
    public static function scriptFilter()
14
    {
15 48
        ScriptFilter::add(
16 48
            self::timerAction(),
17 48
            self::setupWorkflow()
18
        );
19 48
    }
20
21 48
    private static function timerAction()
22
    {
23 48
        $serviceEnabled = Workflow::serviceEnabled();
24
25 48
        if (! $serviceEnabled) {
26 24
            return;
27
        }
28
29 24
        if ($serviceEnabled->runningTimer()) {
30
            return self::stopCurrentTimer();
31
        }
32
33 24
        return self::startTimer();
34
    }
35
36
    private static function stopCurrentTimer()
37
    {
38
        return Item::create()
39
            ->uid('stop_timer')
40
            ->title('Stop current timer')
41
            ->subtitle('That timer is currently running!')
42
            ->arg('do')
43
            ->variable('action', 'stop');
44
    }
45
46 24
    private static function startTimer()
47
    {
48 24
        if (! empty(Workflow::serviceEnabled())) {
49 24
            return Item::create()
50 24
                ->uid('start_timer')
51 24
                ->title('Start "' . self::userInput() . '"')
52 24
                ->mod(
53 24
                    Cmd::create()
54 24
                        ->subtitle('Continue a timer')
55 24
                        ->arg('choose_timer')
56
                )
57 24
                ->arg('choose_project')
58 24
                ->variable('timer_description', self::userInput());
59
        }
60
    }
61
62 48
    private static function setupWorkflow()
63
    {
64 48
        if (empty(Workflow::serviceEnabled()) || (empty(self::userInput()))) {
65 40
            return Item::create()
66 40
                ->uid('setup_timers')
67 40
                ->title('Setup the workflow')
68 40
                ->arg('setup')
69 40
                ->icon(Icon::create('resources/icons/icon.png'));
70
        }
71 8
    }
72
}
73