Entrance::startTimer()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

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