Issues (57)

Security Analysis    not enabled

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/StreamDecoratorTrait.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 Thruster\Component\HttpMessage;
4
5
use Psr\Http\Message\StreamInterface;
6
use function Thruster\Component\HttpMessage\copy_to_string;
7
8
/**
9
 * Trait StreamDecoratorTrait
10
 *
11
 * @package Thruster\Component\HttpMessage
12
 * @author  Aurimas Niekis <[email protected]>
13
 */
14
trait StreamDecoratorTrait
15
{
16
    /**
17
     * @param StreamInterface $stream Stream to decorate
18
     */
19 18
    public function __construct(StreamInterface $stream)
20
    {
21 18
        $this->stream = $stream;
0 ignored issues
show
The property stream does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22 18
    }
23
24
    /**
25
     * Magic method used to create a new stream if streams are not added in
26
     * the constructor of a decorator (e.g., LazyOpenStream).
27
     *
28
     * @param string $name Name of the property (allows "stream" only).
29
     *
30
     * @return StreamInterface
31
     */
32 9
    public function __get($name)
33
    {
34 9
        if ('stream' == $name) {
35 8
            $this->stream = $this->createStream();
36
37 7
            return $this->stream;
38
        }
39
40 1
        throw new \UnexpectedValueException("$name not found on class");
41
    }
42
43 19
    public function __toString()
44
    {
45
        try {
46 19
            if ($this->isSeekable()) {
47 15
                $this->seek(0);
48
            }
49
50 19
            return $this->getContents();
51 1
        } catch (\Exception $e) {
52
            // Really, PHP? https://bugs.php.net/bug.php?id=53648
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
53 1
            trigger_error('StreamDecorator::__toString exception: '
54 1
                . (string) $e, E_USER_ERROR);
55 1
            return '';
56
        }
57
    }
58
59 23
    public function getContents()
60
    {
61 23
        return copy_to_string($this);
62
    }
63
64
    /**
65
     * Allow decorators to implement custom methods
66
     *
67
     * @param string $method Missing method name
68
     * @param array  $args   Method arguments
69
     *
70
     * @return mixed
71
     */
72
    public function __call($method, array $args)
73
    {
74
        $result = call_user_func_array([$this->stream, $method], $args);
75
76
        // Always return the wrapped object if the result is a return $this
77
        return $result === $this->stream ? $this : $result;
78
    }
79
80 3
    public function close()
81
    {
82 3
        $this->stream->close();
83 3
    }
84
85 3
    public function getMetadata($key = null)
86
    {
87 3
        return $this->stream->getMetadata($key);
88
    }
89
90 2
    public function detach()
91
    {
92 2
        return $this->stream->detach();
93
    }
94
95 4
    public function getSize()
96
    {
97 4
        return $this->stream->getSize();
98
    }
99
100 15
    public function eof() : bool
101
    {
102 15
        return $this->stream->eof();
103
    }
104
105 8
    public function tell() : int
106
    {
107 8
        return $this->stream->tell();
108
    }
109
110 4
    public function isReadable() : bool
111
    {
112 4
        return $this->stream->isReadable();
113
    }
114
115 3
    public function isWritable() : bool
116
    {
117 3
        return $this->stream->isWritable();
118
    }
119
120 19
    public function isSeekable() : bool
121
    {
122 19
        return $this->stream->isSeekable();
123
    }
124
125
    public function rewind()
126
    {
127
        $this->seek(0);
128
    }
129
130 12
    public function seek($offset, $whence = SEEK_SET)
131
    {
132 12
        $this->stream->seek($offset, $whence);
133 12
    }
134
135 16
    public function read($length)
136
    {
137 16
        return $this->stream->read($length);
138
    }
139
140 6
    public function write($string)
141
    {
142 6
        return $this->stream->write($string);
143
    }
144
145
    /**
146
     * Implement in subclasses to dynamically create streams when requested.
147
     *
148
     * @return StreamInterface
149
     * @throws \BadMethodCallException
150
     */
151 1
    protected function createStream()
152
    {
153 1
        throw new \BadMethodCallException('Not implemented');
154
    }
155
}
156