Issues (2)

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/FileStream.php (1 issue)

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
namespace pastuhov\FileStream;
3
4
class FileStream extends BaseFileStream
5
{
6
    /**
7
     * File header.
8
     *
9
     * Any file will be started from that string.
10
     *
11
     * @var string
12
     */
13
    protected $header;
14
15
    /**
16
     * File footer.
17
     *
18
     * Any file will be ended at that string.
19
     *
20
     * @var string
21
     */
22
    protected $footer;
23
24
    /**
25
     * Max possible writes to one file.
26
     * @var int
27
     */
28
    protected $maxCount;
29
30
    /**
31
     * File name count placeholder.
32
     * @var string
33
     */
34
    protected $countPlaceHolder = '{count}';
35
36
    /**
37
     * Current writes count.
38
     * @var int
39
     */
40
    protected $currentCount = 0;
41
42
    /**
43
     * Current files count.
44
     * @var int
45
     */
46
    protected $currentFileCount = 0;
47
48
    /**
49
     * List of Files
50
     * @var array
51
     */
52
    protected $files = [];
53
54
    /**
55 9
     * @inheritdoc
56
     * @param string|null $header File header
57 9
     * @param string|null $footer File footer
58
     * @param int|bool|false $maxCount Max possible writes to one file
59 9
     * @throws \Exception
60 9
     */
61 9
    public function __construct($fileName, $header = null, $footer = null, $maxCount = false)
62
    {
63 9
        parent::__construct($fileName);
64 3
65
        $this->header = $header;
66 6
        $this->footer = $footer;
67
        $this->maxCount = $maxCount;
0 ignored issues
show
Documentation Bug introduced by
It seems like $maxCount can also be of type boolean. However, the property $maxCount is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
68
69
        if ($this->maxCount !== false && strpos($this->fileName, $this->countPlaceHolder) === false) {
70
            throw new \Exception('File name ' . $this->countPlaceHolder . ' placeholder is needed');
71 6
        }
72
    }
73 6
74
    /**
75 6
     * Adds the given Filename to the internal Array
76 3
     * @param $filename
77 3
     */
78 6
    protected function addFile($filename)
79
    {
80
        $this->files[] = $filename;
81
    }
82
83
    /**
84
     * Returns the List of written Files
85 6
     * @return array
86
     */
87 6
    public function getFileList()
88
    {
89 6
        return $this->files;
90 6
    }
91 6
92 3
    /**
93 3
     * @inheritdoc
94 6
     */
95 6
    protected function openHandle()
96
    {
97
        parent::openHandle();
98
        $this->addFile($this->getFileName());
99
        if ($this->header !== null) {
100 6
            $this->write($this->header, false);
101
        }
102 6
    }
103 3
104 3
    /**
105
     * @inheritdoc
106 6
     * @param bool $count
107
     * @throws \Exception
108 6
     */
109 6
    public function write($string, $count = true)
110 6
    {
111
        parent::write($string);
112
113
        if ($count) {
114
            $this->currentCount++;
115
            if ($this->currentCount === $this->maxCount) {
116 6
                $this->closeHandle();
117
            }
118 6
        }
119
    }
120 6
121 3
    /**
122 3
     * @inheritdoc
123
     */
124 6
    protected function closeHandle()
125
    {
126
        if ($this->footer !== null) {
127
            $this->write($this->footer, false);
128
        }
129
130
        parent::closeHandle();
131
132
        $this->currentFileCount++;
133
        $this->currentCount = 0;
134
    }
135
136
    /**
137
     * Base file name with replaced count placeholder.
138
     * @return string Base file name with replaced placeholder
139
     */
140
    protected function getFileName()
141
    {
142
        $fileName = parent::getFileName();
143
144
        if ($this->maxCount !== false) {
145
            $fileName = strtr($fileName, [$this->countPlaceHolder => $this->currentFileCount]);
146
        }
147
148
        return $fileName;
149
    }
150
}