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

BaseWorkflow::getMenuClassName()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 6
rs 10
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