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

src/Menus/ChooseProject.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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