Issues (27)

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/Promise/PromiseCancelled.php (6 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 Dazzle\Promise;
4
5
use Dazzle\Throwable\Exception\Logic\InvalidArgumentException;
6
use Dazzle\Throwable\Exception\Runtime\CancellationException;
7
use Error;
8
use Exception;
9
10
class PromiseCancelled implements PromiseInterface
11
{
12
    /**
13
     * @var Error|Exception|string|null
14
     */
15
    protected $reason;
16
17
    /**
18
     * @param Error|Exception|string|null $reason
19
     * @throws InvalidArgumentException
20
     */
21 140
    public function __construct($reason = null)
22
    {
23 140
        if ($reason instanceof PromiseInterface)
24
        {
25 1
            throw new InvalidArgumentException(
26 1
                'You cannot create PromiseCancelled with a promise. Use Promise::doCancel($promiseOrValue) instead.'
27
            );
28
        }
29
30 140
        $this->reason = $reason;
31 140
    }
32
33
    /**
34
     *
35
     */
36 134
    public function __destruct()
37
    {
38 134
        unset($this->reason);
39 134
    }
40
41
    /**
42
     * @override
43
     * @inheritDoc
44
     */
45 82
    public function then(callable $onFulfilled = null, callable $onRejected = null, callable $onCancel = null)
46
    {
47 82
        if (null === $onCancel)
48
        {
49 31
            return $this;
50
        }
51
52
        try
53
        {
54 81
            return Promise::doResolve($onCancel($this->getReason()))
55 81
                ->then(
56
                    function() {
57 81
                        return Promise::doCancel($this->getReason());
58 81
                    },
59
                    function() {
60 6
                        return Promise::doCancel($this->getReason());
61 81
                    }
62
                );
63
        }
64 5
        catch (Error $ex)
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
65
        {}
66 5
        catch (Exception $ex)
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
67
        {}
68
69 5
        return Promise::doCancel($this->getReason());
70
    }
71
72
    /**
73
     * @override
74
     * @inheritDoc
75
     */
76 65 View Code Duplication
    public function done(callable $onFulfilled = null, callable $onRejected = null, callable $onCancel = null)
0 ignored issues
show
This method 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...
77
    {
78 65
        if (null === $onCancel)
79
        {
80 6
            $this->throwError($this->getReason());
0 ignored issues
show
It seems like $this->getReason() targeting Dazzle\Promise\PromiseCancelled::getReason() can also be of type null; however, Dazzle\Promise\PromiseCancelled::throwError() does only seem to accept object<Exception>|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
81
        }
82
83 59
        $result = $onCancel($this->getReason());
84
85 54
        if ($result instanceof self)
86
        {
87 11
            $this->throwError($result->getReason());
0 ignored issues
show
It seems like $result->getReason() targeting Dazzle\Promise\PromiseCancelled::getReason() can also be of type null; however, Dazzle\Promise\PromiseCancelled::throwError() does only seem to accept object<Exception>|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
88
        }
89
90 43
        if ($result instanceof PromiseInterface)
91
        {
92
            $result->done();
93
        }
94 43
    }
95
96
    /**
97
     * @override
98
     * @inheritDoc
99
     */
100 2
    public function spread(callable $onFulfilled = null, callable $onRejected = null, callable $onCancel = null)
101
    {
102 2
        return $this->then(
103 2
            null,
104 2
            null,
105
            function($reasons) use($onCancel) {
106 2
                return $onCancel(...((array) $reasons));
107 2
            }
108
        );
109
    }
110
111
    /**
112
     * @override
113
     * @inheritDoc
114
     */
115 1
    public function success(callable $onSuccess)
116
    {
117 1
        return $this->then($onSuccess);
118
    }
119
120
    /**
121
     * @override
122
     * @inheritDoc
123
     */
124 1
    public function failure(callable $onFailure)
125
    {
126 1
        return $this->then(null, $onFailure);
127
    }
128
129
    /**
130
     * @override
131
     * @inheritDoc
132
     */
133 1
    public function abort(callable $onCancel)
134
    {
135 1
        return $this->then(null, null, $onCancel);
136
    }
137
138
    /**
139
     * @override
140
     * @inheritDoc
141
     */
142 5 View Code Duplication
    public function always(callable $onFulfilledOrRejected)
0 ignored issues
show
This method 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...
143
    {
144 5
        return $this->then(
145 5
            null,
146 5
            null,
147
            function($reason) use($onFulfilledOrRejected) {
148 4
                return Promise::doResolve($onFulfilledOrRejected())->then(function() use($reason) {
149 3
                    return new static($reason);
150 4
                });
151 5
            }
152
        );
153
    }
154
155
    /**
156
     * @override
157
     * @inheritDoc
158
     */
159 1
    public function isPending()
160
    {
161 1
        return false;
162
    }
163
164
    /**
165
     * @override
166
     * @inheritDoc
167
     */
168 3
    public function isFulfilled()
169
    {
170 3
        return false;
171
    }
172
173
    /**
174
     * @override
175
     * @inheritDoc
176
     */
177 3
    public function isRejected()
178
    {
179 3
        return false;
180
    }
181
182
    /**
183
     * @override
184
     * @inheritDoc
185
     */
186 5
    public function isCancelled()
187
    {
188 5
        return true;
189
    }
190
191
    /**
192
     * @override
193
     * @inheritDoc
194
     */
195
    public function getPromise()
196
    {
197
        return $this;
198
    }
199
200
    /**
201
     * @override
202
     * @inheritDoc
203
     */
204 1
    public function resolve($value = null)
205
    {
206 1
        return $this;
207
    }
208
209
    /**
210
     * @override
211
     * @inheritDoc
212
     */
213 1
    public function reject($reason = null)
214
    {
215 1
        return $this;
216
    }
217
218
    /**
219
     * @override
220
     * @inheritDoc
221
     */
222 1
    public function cancel($reason = null)
223
    {
224 1
        return $this;
225
    }
226
227
    /**
228
     * @see Promise::getValue
229
     */
230
    protected function getValue()
231
    {
232
        return null;
233
    }
234
235
    /**
236
     * @see Promise::getReason
237
     */
238 112
    protected function getReason()
239
    {
240 112
        return $this->reason;
241
    }
242
243
    /**
244
     * @param Error|Exception|string $reason
245
     * @throws Error|Exception
246
     */
247 17
    protected function throwError($reason)
248
    {
249 17
        if ($reason instanceof Error || $reason instanceof Exception)
250
        {
251 6
            throw $reason;
252
        }
253
254 11
        throw new CancellationException($reason);
255
    }
256
}
257