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

SetupState::scriptFilter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Godbout\Alfred\Time\Menus\Toggl;
4
5
use Godbout\Alfred\Time\Workflow;
6
use Godbout\Alfred\Workflow\Icon;
7
use Godbout\Alfred\Workflow\Item;
8
use Godbout\Alfred\Time\Menus\Menu;
9
use Godbout\Alfred\Workflow\ScriptFilter;
10
11 View Code Duplication
class SetupState extends Menu
0 ignored issues
show
Duplication introduced by Guillaume Leclerc
This class 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...
12
{
13
    public static function scriptFilter()
14
    {
15
        self::saveState();
16
17
        ScriptFilter::add(
18
            self::stateSaved(),
19
            self::back()
20
        );
21
    }
22
23
    private static function saveState()
24
    {
25
        Workflow::disableAllServices();
26
27
        self::toEnable() ? Workflow::enableService('toggl') : Workflow::disableService('toggl');
28
    }
29
30
    private static function stateSaved()
31
    {
32
        return Item::create()
33
            ->title(self::stateTitle())
34
            ->subtitle(self::stateSubtitle())
35
            ->icon(Icon::create('resources/icons/toggl.png'))
36
            ->arg('do')
37
            ->variable('timer_action', 'exit');
38
    }
39
40
    private static function stateTitle()
41
    {
42
        return 'Toggl ' . (self::toEnable() ? 'ENABLED!' : 'DISABLED!');
43
    }
44
45
    protected static function stateSubtitle()
46
    {
47
        return (self::toEnable() ? 'Other services disabled. ' : '') . 'You may press enter to quit the workflow';
48
    }
49
50
    private static function back()
51
    {
52
        return Item::create()
53
            ->title('Back')
54
            ->subtitle('Go back to Toggl options')
55
            ->arg('toggl_setup')
56
            ->icon(Icon::create('resources/icons/toggl.png'));
57
    }
58
59
    protected static function toEnable()
60
    {
61
        return getenv('toggl_enabled') === 'true';
62
    }
63
}
64