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

ChooseTimer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A scriptFilter() 0 12 3
A getServicePastTimers() 0 20 2
A pastTimerSubtitle() 0 4 1
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\ScriptFilter;
9
10
class ChooseTimer extends Menu
11
{
12
    public static function scriptFilter()
13
    {
14
        $service = Workflow::serviceEnabled();
15
16
        foreach (self::getServicePastTimers($service) as $pastTimer) {
17
            ScriptFilter::add($pastTimer);
18
        }
19
20
        if (self::userInput()) {
21
            ScriptFilter::filterItems(self::userInput());
22
        }
23
    }
24
25
    private static function getServicePastTimers($service)
26
    {
27
        $pastTimers = [];
28
29
        foreach ($service->pastTimers() as $id => $pastTimer) {
30
            $pastTimers[] = Item::create()
31
                ->title($pastTimer->description)
32
                ->subtitle(self::pastTimerSubtitle($pastTimer))
33
                ->icon(Icon::create("resources/icons/$service.png"))
34
                ->arg('do')
35
                ->variable('timer_action', 'continue')
36
                ->variable('timer_id', $pastTimer->id)
37
                ->variable('timer_description', $pastTimer->description)
38
                ->variable('timer_project_id', $pastTimer->project_id)
39
                ->variable('timer_project_name', $pastTimer->project_name)
40
                ->variable('timer_tag', $pastTimer->tags);
41
        }
42
43
        return $pastTimers;
44
    }
45
46
    protected static function pastTimerSubtitle($pastTimer)
47
    {
48
        return "$pastTimer->project_name, [$pastTimer->tags], $pastTimer->duration";
49
    }
50
}
51