ChooseTag   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 65.52%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 26
dl 0
loc 47
ccs 19
cts 29
cp 0.6552
rs 10
c 4
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getServiceTags() 0 16 2
A scriptFilter() 0 17 4
A getNoTag() 0 8 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 ChooseTag extends Menu
11
{
12 12
    public static function scriptFilter()
13
    {
14 12
        $service = Workflow::serviceEnabled();
15
16 12
        if ($service->allowsEmptyTag) {
17 12
            ScriptFilter::add(self::getNoTag());
18
        }
19
20 12
        foreach (self::getServiceTags($service) as $tag) {
21
            ScriptFilter::add($tag);
22
        }
23
24 12
        if (self::userInput()) {
25
            ScriptFilter::filterItems(self::userInput());
26
        }
27
28 12
        ScriptFilter::sortItems('asc', 'match');
29 12
    }
30
31 12
    private static function getNoTag()
32
    {
33 12
        return Item::create()
34 12
            ->title('No tag')
35 12
            ->subtitle('Timer will be created without a tag')
36 12
            ->match('')
37 12
            ->arg('do')
38 12
            ->variable('action', 'start');
39
    }
40
41 12
    private static function getServiceTags($service)
42
    {
43 12
        $tags = [];
44
45 12
        foreach ($service->tags() as $id => $name) {
46
            $tags[] = Item::create()
47
                ->title($name)
48
                ->variable('timer_tag', $name)
49
                ->variable('timer_tag_id', $id)
50
                ->match($name)
51
                ->icon(Icon::create("resources/icons/$service.png"))
52
                ->arg('do')
53
                ->variable('action', 'start');
54
        }
55
56 12
        return $tags;
57
    }
58
}
59