ChooseTag::getNoTag()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 8
ccs 7
cts 7
cp 1
crap 1
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\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