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

ChooseProject::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 ChooseProject extends Menu
11
{
12
    public static function scriptFilter()
13
    {
14
        $service = Workflow::serviceEnabled();
15
16
        if ($service->allowsEmptyProject) {
17
            ScriptFilter::add(self::getNoProject());
18
        }
19
20
        foreach (self::getServiceProjects($service) as $project) {
21
            ScriptFilter::add($project);
22
        }
23
24
        if (self::userInput()) {
25
            ScriptFilter::filterItems(self::userInput());
26
        }
27
28
        ScriptFilter::sortItems('asc', 'match');
29
    }
30
31
    private static function getNoProject()
32
    {
33
        return Item::create()
34
            ->title('No project')
35
            ->subtitle('Timer will be created without a project')
36
            ->match('')
37
            ->arg('choose_tag');
38
    }
39
40 View Code Duplication
    private static function getServiceProjects($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...
41
    {
42
        $projects = [];
43
44
        foreach ($service->projects() as $id => $name) {
45
            $projects[] = Item::create()
46
                ->title($name)
47
                ->variable('timer_project_id', $id)
48
                ->variable('timer_project_name', $name)
49
                ->match($name)
50
                ->arg('choose_tag')
51
                ->icon(Icon::create("resources/icons/$service.png"));
52
        }
53
54
        return $projects;
55
    }
56
}
57