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

SetupState   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 53
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 5
dl 53
loc 53
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A scriptFilter() 9 9 1
A saveState() 6 6 2
A stateSaved() 9 9 1
A stateTitle() 4 4 2
A stateSubtitle() 4 4 2
A back() 8 8 1
A toEnable() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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