Issues (4)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/LightFsm/StateMachine.php (2 issues)

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 LightFsm;
4
5
class StateMachine 
6
{
7
    /** @var StateConfiguration */
8
    private $currentState;
9
10
    /** @var StateConfiguration[] */
11
    private $states = [];
12
13
    /** @var callable|null */
14
    private $changeCallback;
15
16
    /**
17
     * @param string|int|callable $initialState
18
     * @param callable|null       $changeCallback f($newState, $event, $oldState, $isSubState, $data)
19
     */
20
    public function __construct($initialState, $changeCallback = null)
21
    {
22
        $state = is_callable($initialState) ? call_user_func($initialState) : $initialState;
23
        $this->states[$state] = $this->currentState = new StateConfiguration($state);
24
        $this->changeCallback = $changeCallback;
25
    }
26
27
    /**
28
     * @param string|int $state
29
     *
30
     * @return StateConfiguration
31
     */
32
    public function configure($state)
33
    {
34
        return $this->getState($state);
35
    }
36
37
    /**
38
     * @param string|int $event
39
     * @param mixed      $data
40
     */
41
    public function fire($event, $data = null)
42
    {
43
        $transition = $this->currentState->getTransition($event);
44
        if (null === $transition) {
45
            return;
46
        }
47
48
        if ($transition->getGuardCallback()) {
49
            $ok = call_user_func($transition->getGuardCallback(), $data);
50
            if (!$ok) {
51
                return;
52
            }
53
        }
54
55
        $nextState = $this->getState($transition->getNextState());
56
57
        $this->transition($this->currentState, $event, $nextState, $data);
58
    }
59
60
    /**
61
     * @return int|string
62
     */
63
    public function getCurrentState()
64
    {
65
        return $this->currentState->getState();
66
    }
67
68
    /**
69
     * @param string|int $state
70
     *
71
     * @return bool
72
     */
73
    public function isInState($state)
74
    {
75
        $parentState = $this->getState($state);
76
77
        return $this->isSubState($this->currentState, $parentState);
78
    }
79
80
    public function toDotGraph()
81
    {
82
        $result = "digraph {\n";
83
        $listeners = '';
84
        foreach ($this->states as $state) {
85 View Code Duplication
            foreach ($state->getAllEntryCallbacks() as $name=>$callback) {
0 ignored issues
show
This code seems to be duplicated across 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...
86
                if (is_int($name)) {
87
                    $name = 'listener';
88
                }
89
                $listeners .= sprintf("    \"%s\" -> \"%s\" [label=\"On Entry\"];\n", $state->getState(), $name);
90
            }
91 View Code Duplication
            foreach ($state->getAllExitCallbacks() as $name=>$callback) {
0 ignored issues
show
This code seems to be duplicated across 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...
92
                if (is_int($name)) {
93
                    $name = 'listener';
94
                }
95
                $listeners .= sprintf("    \"%s\" -> \"%s\" [label=\"On Exit\"];\n", $state->getState(), $name);
96
            }
97
98
            foreach ($state->getAllTransitions() as $transition) {
99
                if ($transition->getGuardCallback()) {
100
                    $guardName = $transition->getGuardName() ?: 'condition';
101
                    $result .= sprintf("    \"%s\" -> \"%s\" [label=\"%s [%s]\"];\n", $state->getState(), $transition->getNextState(), $transition->getEvent(), $guardName);
102
                } else {
103
                    $result .= sprintf("    \"%s\" -> \"%s\" [label=\"%s\"];\n", $state->getState(), $transition->getNextState(), $transition->getEvent());
104
                }
105
            }
106
        }
107
108
        if ($listeners) {
109
            $result .= "    node [shape=box];\n";
110
            $result .= $listeners;
111
        }
112
113
        $result .= "}\n";
114
115
        return $result;
116
    }
117
118
    /**
119
     * @param StateConfiguration $child
120
     * @param StateConfiguration $parent
121
     *
122
     * @return bool
123
     */
124
    private function isSubState(StateConfiguration $child, StateConfiguration $parent)
125
    {
126
        $state = $child;
127
128
        while ($state) {
129
            if ($state->getState() === $parent->getState()) {
130
                return true;
131
            }
132
133
            if ($state->getParentState()) {
134
                $state = $this->getState($state->getParentState());
135
            } else {
136
                $state = null;
137
            }
138
        }
139
140
        return false;
141
    }
142
143
    /**
144
     * @param string|int $state
145
     *
146
     * @return StateConfiguration
147
     */
148
    private function getState($state)
149
    {
150
        if (false === isset($this->states[$state])) {
151
            $this->states[$state] = new StateConfiguration($state);
152
        }
153
154
        return $this->states[$state];
155
    }
156
157
    /**
158
     * @param StateConfiguration $previousState
159
     * @param string|int         $event
160
     * @param StateConfiguration $nextState
161
     * @param mixed              $data
162
     */
163
    private function transition(StateConfiguration $previousState, $event, StateConfiguration $nextState, $data)
164
    {
165
        $isSubState = $this->isSubState($this->currentState, $nextState);
166
167
        $previousState->triggerExit($isSubState, $data);
168
        $this->currentState = $nextState;
169
        $nextState->triggerEntry($isSubState, $data);
170
171
        if ($this->changeCallback) {
172
            call_user_func($this->changeCallback, $nextState->getState(), $event, $previousState->getState(), $isSubState, $data);
173
        }
174
    }
175
}
176