Issues (3)

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/Internal/GeneratorContainer.php (3 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 mpyw\Co\Internal;
4
use mpyw\Co\CoInterface;
5
6
class GeneratorContainer
7
{
8
    /**
9
     * Generator.
10
     * @var \Generator
11
     */
12
    private $g;
13
14
    /**
15
     * Generator object hash.
16
     * @var string
17
     */
18
    private $h;
19
20
    /**
21
     * Thrown exception.
22
     * @var \Throwable|\Exception
23
     */
24
    private $e;
25
26
    /**
27
     * Parent yield key.
28
     * @var mixed
29
     */
30
    private $yieldKey;
31
32
    /**
33
     * Constructor.
34
     * @param \Generator $g
35
     */
36 43
    public function __construct(\Generator $g, $yield_key = null)
37 43
    {
38 43
        $this->g = $g;
39 43
        $this->h = spl_object_hash($g);
40 43
        $this->yieldKey = $yield_key;
41 43
        $this->valid();
42 43
    }
43
44
    /**
45
     * Return parent yield key.
46
     * @return mixed
47
     */
48 28
    public function getYieldKey()
49 28
    {
50 28
        return $this->yieldKey;
51
    }
52
53
    /**
54
     * Return generator hash.
55
     * @return string
56
     */
57 29
    public function __toString()
58 29
    {
59 29
        return $this->h;
60
    }
61
62
    /**
63
     * Return whether generator is actually working.
64
     * @return bool
65
     */
66 43
    public function valid()
67 43
    {
68
        try {
69 43
            $this->g->current();
70 43
            return $this->e === null && $this->g->valid() && $this->g->key() !== CoInterface::RETURN_WITH;
71 2
        } catch (\Throwable $e) {} catch (\Exception $e) {}
72 2
        $this->e = $e;
73 2
        return false;
74
    }
75
76
    /**
77
     * Return current key.
78
     * @return mixed
79
     */
80 33
    public function key()
81 33
    {
82 33
        $this->validateValidity();
83 33
        return $this->g->key();
84
    }
85
86
    /**
87
     * Return current value.
88
     * @return mixed
89
     */
90 35
    public function current()
91 35
    {
92 35
        $this->validateValidity();
93 35
        return $this->g->current();
94
    }
95
96
    /**
97
     * Send value into generator.
98
     * @param mixed $value
99
     * @NOTE: This method returns nothing,
100
     *        while original generator returns something.
101
     */
102 31 View Code Duplication
    public function send($value)
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...
103 31
    {
104 31
        $this->validateValidity();
105
        try {
106 31
            $this->g->send($value);
107 28
            return;
108 19
        } catch (\Throwable $e) {} catch (\Exception $e) {}
109 19
        $this->e = $e;
110 19
    }
111
112
    /**
113
     * Throw exception into generator.
114
     * @param \Throwable|\Exception $e
115
     * @NOTE: This method returns nothing,
116
     *        while original generator returns something.
117
     */
118 19 View Code Duplication
    public function throw_($e)
0 ignored issues
show
The parameter $e is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
119 19
    {
120 19
        $this->validateValidity();
121
        try {
122 19
            $this->g->throw($e);
123 15
            return;
124 13
        } catch (\Throwable $e) {} catch (\Exception $e) {}
125 13
        $this->e = $e;
126 13
    }
127
128
    /**
129
     * Return whether Throwable is thrown.
130
     * @return bool
131
     */
132 31
    public function thrown()
133 31
    {
134 31
        return $this->e !== null;
135
    }
136
137
    /**
138
     * Return value that generator has returned or thrown.
139
     * @return mixed
140
     */
141 34
    public function getReturnOrThrown()
142 34
    {
143 34
        $this->validateInvalidity();
144 33
        if ($this->e === null && $this->g->valid() && !$this->valid()) {
145 9
            return $this->g->current();
146
        }
147 32
        if ($this->e) {
148 23
            return $this->e;
149
        }
150 29
        return method_exists($this->g, 'getReturn') ? $this->g->getReturn() : null;
151
    }
152
153
    /**
154
     * Validate that generator has finished running.
155
     * @throws \BadMethodCallException
156
     */
157 36
    private function validateValidity()
158 36
    {
159 36
        if (!$this->valid()) {
160 2
            throw new \BadMethodCallException('Unreachable here.');
161
        }
162 36
    }
163
164
    /**
165
     * Validate that generator is still running.
166
     * @throws \BadMethodCallException
167
     */
168 34
    private function validateInvalidity()
169 34
    {
170 34
        if ($this->valid()) {
171 1
            throw new \BadMethodCallException('Unreachable here.');
172
        }
173 33
    }
174
}
175