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

ChooseTag::scriptFilter()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 4
nc 8
nop 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
    public static function scriptFilter()
13
    {
14
        $service = Workflow::serviceEnabled();
15
16
        if ($service->allowsEmptyTag) {
17
            ScriptFilter::add(self::getNoTag());
18
        }
19
20
        foreach (self::getServiceTags($service) as $tag) {
21
            ScriptFilter::add($tag);
22
        }
23
24
        if (self::userInput()) {
25
            ScriptFilter::filterItems(self::userInput());
26
        }
27
28
        ScriptFilter::sortItems('asc', 'match');
29
    }
30
31
    private static function getNoTag()
32
    {
33
        return Item::create()
34
            ->title('No tag')
35
            ->subtitle('Timer will be created without a tag')
36
            ->match('')
37
            ->arg('do')
38
            ->variable('timer_action', 'start');
39
    }
40
41 View Code Duplication
    private static function getServiceTags($service)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        $tags = [];
44
45
        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('timer_action', 'start');
54
        }
55
56
        return $tags;
57
    }
58
}
59