Passed
Push — develop ( 51d8d9...f75e16 )
by Guillaume
01:49
created

BaseWorkflow   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 70
ccs 0
cts 48
cp 0
rs 10
wmc 14

9 Methods

Rating   Name   Duplication   Size   Complexity  
A notify() 0 9 2
A __construct() 0 3 1
A currentMenu() 0 5 1
A getMenuClassName() 0 3 2
A getInstance() 0 7 2
A __clone() 0 2 1
A getCurrentMenuClass() 0 5 2
A destroy() 0 5 1
A do() 0 9 2
1
<?php
2
3
namespace Godbout\Alfred\Workflow;
4
5
use Godbout\Alfred\Workflow\Contracts\Workflow;
6
use ReflectionClass;
7
8
abstract class BaseWorkflow implements Workflow
9
{
10
    private static $instance = null;
11
    private $scriptFilter = null;
12
13
14
    final protected function __construct()
15
    {
16
        $this->scriptFilter = ScriptFilter::create();
0 ignored issues
show
Bug introduced by
The type Godbout\Alfred\Workflow\ScriptFilter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
    }
18
19
    final public static function getInstance()
20
    {
21
        if (is_null(self::$instance)) {
22
            self::$instance = new static;
23
        }
24
25
        return self::$instance;
26
    }
27
28
    public static function currentMenu()
29
    {
30
        static::getCurrentMenuClass()::scriptFilter();
31
32
        return static::getInstance()->scriptFilter->output();
33
    }
34
35
    private static function getCurrentMenuClass()
36
    {
37
        $args = explode('_', getenv('action'));
0 ignored issues
show
Unused Code introduced by
The assignment to $args is dead and can be removed.
Loading history...
38
39
        return (new ReflectionClass(static::class))->getNamespaceName() . "\\Menus\\" . (static::getMenuClassName(getenv('action')) ?: 'Entrance');
40
    }
41
42
    private static function getMenuClassName($action)
43
    {
44
        return str_replace('_', '', ucwords($action === false ? 'entrance' : $action, '_'));
45
    }
46
47
    final public static function destroy()
48
    {
49
        ScriptFilter::destroy();
50
51
        self::$instance = null;
52
    }
53
54
    final private function __clone()
55
    {
56
    }
57
58
    public static function do()
59
    {
60
        $action = getenv('workflow_action');
61
62
        if (method_exists(static::class, $action)) {
63
            return static::$action();
64
        }
65
66
        return false;
67
    }
68
69
    public static function notify($result = false)
70
    {
71
        $action = getenv('workflow_action');
72
73
        if ($result === false) {
74
            return "Oops... cannot $action.";
75
        }
76
77
        return "$action is done!";
78
    }
79
}
80