Completed
Push — master ( 3b0b6a...263c36 )
by Guillaume
02:53
created

Entrance   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 6
dl 0
loc 62
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A scriptFilter() 0 7 1
A timerAction() 0 14 3
A stopCurrentTimer() 0 9 1
A startTimer() 0 15 2
A setupWorkflow() 0 10 3
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
    public static function scriptFilter()
14
    {
15
        ScriptFilter::add(
16
            self::timerAction(),
17
            self::setupWorkflow()
18
        );
19
    }
20
21
    private static function timerAction()
22
    {
23
        $serviceEnabled = Workflow::serviceEnabled();
24
25
        if (! $serviceEnabled) {
26
            return;
27
        }
28
29
        if ($serviceEnabled->runningTimer()) {
30
            return self::stopCurrentTimer();
31
        }
32
33
        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('timer_action', 'stop');
44
    }
45
46
    private static function startTimer()
47
    {
48
        if (! empty(Workflow::serviceEnabled())) {
49
            return Item::create()
50
                ->uid('start_timer')
51
                ->title('Start "' . self::userInput() . '"')
52
                ->mod(
53
                    Cmd::create()
54
                        ->subtitle('Continue a timer')
55
                        ->arg('choose_timer')
56
                )
57
                ->arg('choose_project')
58
                ->variable('timer_description', self::userInput());
59
        }
60
    }
61
62
    private static function setupWorkflow()
63
    {
64
        if (empty(Workflow::serviceEnabled()) || (empty(self::userInput()))) {
65
            return Item::create()
66
                ->uid('setup_timers')
67
                ->title('Setup the workflow')
68
                ->arg('setup')
69
                ->icon(Icon::create('resources/icons/icon.png'));
70
        }
71
    }
72
}
73