Issues (14)

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/Tests/Reader/SimpleReaderTest.php (4 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 TextFile\Tests\Reader;
4
5
use TextFile\Reader\SimpleReader;
6
use TextFile\Tests\TextFileTestCase;
7
use TextFile\Walker\SimpleWalker;
8
9
/**
10
 * Class SimpleReaderTest
11
 *
12
 * @package TextFile\Tests\Reader
13
 */
14
class SimpleReaderTest extends TextFileTestCase
15
{
16
    /**
17
     * @covers TextFile\Reader\SimpleReader::getLinesRange
18
     */
19
    public function testGetLinesRange()
20
    {
21
        $reader = new SimpleReader(new SimpleWalker());
22
23
        $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt');
24
        $file     = new \SplFileObject($filePath, 'r+');
25
        $range    = $reader->getLinesRange($file, 0, 2);
26
27
        $this->assertInstanceOf('\LimitIterator', $range);
28
29
        $this->assertCount(2, $range);
30
    }
31
32
    /**
33
     * @covers TextFile\Reader\SimpleReader::getLinesRange
34
     *
35
     * @expectedException \TextFile\Exception\OutOfBoundsException
36
     */
37 View Code Duplication
    public function testGetLinesRangeOutOfBoundsTooLow()
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...
38
    {
39
        $reader = new SimpleReader(new SimpleWalker());
40
41
        $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt');
42
        $file     = new \SplFileObject($filePath, 'r+');
43
44
        $reader->getLinesRange($file, -1, 2);
45
    }
46
47
    /**
48
     * @covers TextFile\Reader\SimpleReader::getLinesRange
49
     *
50
     * @expectedException \TextFile\Exception\OutOfBoundsException
51
     */
52 View Code Duplication
    public function testGetLinesRangeOutOfBoundsTooHigh()
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...
53
    {
54
        $reader = new SimpleReader(new SimpleWalker());
55
56
        $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt');
57
        $file     = new \SplFileObject($filePath, 'r+');
58
59
        $reader->getLinesRange($file, 0, 20);
60
    }
61
62
    /**
63
     * @covers TextFile\Reader\SimpleReader::getNextLineContent
64
     */
65
    public function testGetNextLineContentFromStart()
66
    {
67
        $reader = new SimpleReader(new SimpleWalker());
68
69
        $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt');
70
        $file     = new \SplFileObject($filePath, 'r+');
71
72
        $this->assertEquals('second', $reader->getNextLineContent($file));
73
74
        // Test if pointer is correctly reset
75
76
        $this->assertEquals('second', $reader->getNextLineContent($file));
77
    }
78
79
    /**
80
     * @covers TextFile\Reader\SimpleReader::getNextLineContent
81
     */
82
    public function testGetNextLineContent()
83
    {
84
        $reader = new SimpleReader(new SimpleWalker());
85
86
        $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt');
87
        $file     = new \SplFileObject($filePath, 'r+');
88
89
        $file->seek(2);
90
91
        $this->assertEquals('fourth', $reader->getNextLineContent($file));
92
93
        // Test if pointer is correctly reset
94
95
        $this->assertEquals('fourth', $reader->getNextLineContent($file));
96
    }
97
98
    /**
99
     * @covers TextFile\Reader\SimpleReader::getNextLineContent
100
     *
101
     * @expectedException \TextFile\Exception\OutOfBoundsException
102
     */
103 View Code Duplication
    public function testGetNextLineContentOutOfBounds()
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...
104
    {
105
        $reader = new SimpleReader(new SimpleWalker());
106
107
        $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt');
108
        $file     = new \SplFileObject($filePath, 'r+');
109
110
        $file->seek(5);
111
112
        $reader->getNextLineContent($file);
113
    }
114
115
    /**
116
     * @covers TextFile\Reader\SimpleReader::getPreviousLineContent
117
     */
118
    public function testGetPreviousLineContent()
119
    {
120
        $reader = new SimpleReader(new SimpleWalker());
121
122
        $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt');
123
        $file     = new \SplFileObject($filePath, 'r+');
124
125
        $file->seek(2);
126
127
        $this->assertEquals('second', $reader->getPreviousLineContent($file));
128
129
        // Test if pointer is correctly reset
130
131
        $this->assertEquals('second', $reader->getPreviousLineContent($file));
132
    }
133
134
    /**
135
     * @covers TextFile\Reader\SimpleReader::getPreviousLineContent
136
     *
137
     * @expectedException \TextFile\Exception\OutOfBoundsException
138
     */
139 View Code Duplication
    public function testGetPreviousLineContentOutOfBounds()
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...
140
    {
141
        $reader = new SimpleReader(new SimpleWalker());
142
143
        $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt');
144
        $file     = new \SplFileObject($filePath, 'r+');
145
146
        $file->seek(0);
147
148
        $reader->getPreviousLineContent($file);
149
    }
150
151
    /**
152
     * @covers TextFile\Reader\SimpleReader::getCurrentLineContent
153
     */
154
    public function testGetCurrentLineContent()
155
    {
156
        $reader = new SimpleReader(new SimpleWalker());
157
158
        $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt');
159
        $file     = new \SplFileObject($filePath, 'r+');
160
161
        $file->seek(2);
162
163
        $this->assertEquals('third', $reader->getCurrentLineContent($file));
164
165
        // Test if pointer is correctly reset
166
167
        $this->assertEquals('third', $reader->getCurrentLineContent($file));
168
    }
169
170
    /**
171
     * @covers TextFile\Reader\SimpleReader::getLineContent
172
     */
173
    public function testGetLineContent()
174
    {
175
        $reader = new SimpleReader(new SimpleWalker());
176
177
        $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt');
178
        $file     = new \SplFileObject($filePath, 'r+');
179
180
        $this->assertEquals('third', $reader->getLineContent($file, 2));
181
    }
182
183
    /**
184
     * @covers TextFile\Reader\SimpleReader::getLineContent
185
     *
186
     * @expectedException \TextFile\Exception\OutOfBoundsException
187
     */
188
    public function testGetLineContentOutOfBoundsTooHigh()
189
    {
190
        $reader = new SimpleReader(new SimpleWalker());
191
192
        $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt');
193
        $file     = new \SplFileObject($filePath, 'r+');
194
195
        $this->assertEquals('third', $reader->getLineContent($file, 9));
196
    }
197
198
    /**
199
     * @covers TextFile\Reader\SimpleReader::getLineContent
200
     *
201
     * @expectedException \TextFile\Exception\OutOfBoundsException
202
     */
203
    public function testGetLineContentOutOfBoundsTooLow()
204
    {
205
        $reader = new SimpleReader(new SimpleWalker());
206
207
        $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt');
208
        $file     = new \SplFileObject($filePath, 'r+');
209
210
        $this->assertEquals('third', $reader->getLineContent($file, -1));
211
    }
212
213
    /**
214
     * @covers TextFile\Reader\SimpleReader::getNextCharacterContent
215
     */
216
    public function testGetNextCharacterContent()
217
    {
218
        $reader = new SimpleReader(new SimpleWalker());
219
220
        $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt');
221
        $file     = new \SplFileObject($filePath, 'r+');
222
223
        $file->fseek(2);
224
225
        $this->assertEquals('r', $reader->getNextCharacterContent($file));
226
    }
227
228
    /**
229
     * @covers TextFile\Reader\SimpleReader::getPreviousCharacterContent
230
     */
231
    public function testGetPreviousCharacterContent()
232
    {
233
        $reader = new SimpleReader(new SimpleWalker());
234
235
        $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt');
236
        $file     = new \SplFileObject($filePath, 'r+');
237
238
        $file->fseek(2);
239
240
        $this->assertEquals('i', $reader->getPreviousCharacterContent($file));
241
    }
242
243
    /**
244
     * @covers TextFile\Reader\SimpleReader::getCharacterContent
245
     */
246
    public function testGetCharacterContent()
247
    {
248
        $reader = new SimpleReader(new SimpleWalker());
249
250
        $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt');
251
        $file     = new \SplFileObject($filePath, 'r+');
252
253
        $this->assertEquals('r', $reader->getCharacterContent($file, 2));
254
    }
255
256
    /**
257
     * @covers TextFile\Reader\SimpleReader::cleanLineContent
258
     */
259
    public function testCleanLineContent()
260
    {
261
        $reader = new SimpleReader(new SimpleWalker());
262
263
        $this->assertEmpty($reader->cleanLineContent(PHP_EOL));
264
    }
265
}
266