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

src/Menus/Harvest/SetupState.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\Harvest;
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
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('harvest') : Workflow::disableService('harvest');
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/harvest.png'))
36
            ->arg('do')
37
            ->variable('timer_action', 'exit');
38
    }
39
40
    private static function stateTitle()
41
    {
42
        return 'Harvest ' . (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 Harvest options')
55
            ->arg('harvest_setup')
56
            ->icon(Icon::create('resources/icons/harvest.png'));
57
    }
58
59
    protected static function toEnable()
60
    {
61
        return getenv('harvest_enabled') === 'true';
62
    }
63
}
64