This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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 KochTest\Files; |
||
4 | |||
5 | use Koch\Files\Download; |
||
6 | use org\bovigo\vfs\vfsStream; |
||
7 | use org\bovigo\vfs\vfsStreamDirectory; |
||
8 | use org\bovigo\vfs\vfsStreamWrapper; |
||
9 | |||
10 | class DownloadTest extends \PHPUnit_Framework_TestCase |
||
11 | { |
||
12 | /** |
||
13 | * @var Download |
||
14 | */ |
||
15 | protected $object; |
||
16 | |||
17 | /** |
||
18 | * Sets up the fixture, for example, opens a network connection. |
||
19 | * This method is called before a test is executed. |
||
20 | */ |
||
21 | public function setUp() |
||
22 | { |
||
23 | include_once __DIR__ . '/../../../framework/Koch/Files/Download.php'; |
||
24 | include_once __DIR__ . '/../../../vendor/autoload.php'; |
||
25 | |||
26 | $this->object = new Download(); |
||
27 | |||
28 | $this->media_files = [ |
||
0 ignored issues
–
show
|
|||
29 | // type, mime, binarypacks |
||
30 | ['jpg', 'image/jpeg', [0xffd8, 0xffe0, 0x0010, 0x4a46, 0x4946, 0x0001, 0x0101, 0x0048, 0x0048]], |
||
31 | ['png', 'image/png', [0x8950, 0x4e47, 0x0d0a, 0x1a0a, 0x0000, 0x000d, 0x4948, 0x4452, 0x0000]], |
||
32 | ['mp4', 'video/mp4', [0x0000, 0x001c, 0x6674, 0x7970, 0x6d70, 0x3432, 0x0000, 0x0000, 0x6973]], |
||
33 | ['mp3', 'audio/mpeg', [0x4944, 0x3303, 0x0000, 0x0000, 0x1064, 0x5441, 0x4c42, 0x0000, 0x0017]], |
||
34 | ['avi', 'video/x-msvideo', [0x5249, 0x4646, 0x6a42, 0x0100, 0x4156, 0x4920, 0x4c49, 0x5354, 0x8c05]], |
||
35 | ['ogg', 'application/ogg', [0x4f67, 0x6753, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x5d28, 0xf95e]], |
||
36 | #array("crap", "application/octet-stream", array(0xff09, 0xff08, 0xff07, 0xff06, 0xff05, 0xff04, 0xff03, 0xff02, 0xff01)), |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
74% 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. ![]() |
|||
37 | ]; |
||
38 | |||
39 | vfsStreamWrapper::register(); |
||
40 | $this->root = new vfsStreamDirectory('root'); |
||
0 ignored issues
–
show
The property
root 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;
![]() |
|||
41 | |||
42 | // write virtual files |
||
43 | foreach ($this->media_files as $mime) { |
||
44 | // extract inner array structure into variables |
||
45 | list($type, $mimetype, $binary_pack) = $mime; |
||
0 ignored issues
–
show
$binary_pack does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() The assignment to
$mimetype is unused. Consider omitting it like so list($first,,$third) .
This checks looks for assignemnts to variables using the Consider the following code example. <?php
function returnThreeValues() {
return array('a', 'b', 'c');
}
list($a, $b, $c) = returnThreeValues();
print $a . " - " . $c;
Only the variables Instead, the list call could have been. list($a,, $c) = returnThreeValues();
![]() |
|||
46 | |||
47 | $file = 'file.' . $type; |
||
48 | $file = vfsStream::newFile($file, 0777)->withContent( |
||
49 | // write binarypacks to file |
||
50 | call_user_func_array('pack', array_merge(['n*'], (array) $binary_pack)) |
||
0 ignored issues
–
show
$binary_pack does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
51 | ); |
||
52 | $this->root->addChild($file); |
||
53 | } |
||
54 | vfsStreamWrapper::setRoot($this->root); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Tears down the fixture, for example, closes a network connection. |
||
59 | * This method is called after a test is executed. |
||
60 | */ |
||
61 | public function tearDown() |
||
62 | { |
||
63 | unset($this->object); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * @covers Koch\Files\Download::getMimeType |
||
68 | */ |
||
69 | public function testGetMimeType() |
||
70 | { |
||
71 | foreach ($this->media_files as $mime) { |
||
72 | // extract inner array structure into variables |
||
73 | list($type, $mimetype, $binary_pack) = $mime; |
||
0 ignored issues
–
show
$binary_pack does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() The assignment to
$binary_pack is unused. Consider omitting it like so list($first,,$third) .
This checks looks for assignemnts to variables using the Consider the following code example. <?php
function returnThreeValues() {
return array('a', 'b', 'c');
}
list($a, $b, $c) = returnThreeValues();
print $a . " - " . $c;
Only the variables Instead, the list call could have been. list($a,, $c) = returnThreeValues();
![]() |
|||
74 | |||
75 | // skip mp3, finfo detects them as "application/octet-stream" |
||
76 | // instead of "audio/mpeg" |
||
77 | if ($type === 'mp3') { |
||
78 | // skip |
||
79 | continue; |
||
80 | } |
||
81 | |||
82 | $vfsFile = vfsStream::url('root/file.' . $type); |
||
83 | $fetched_mimetype = $this->object->getMimeType($vfsFile); |
||
0 ignored issues
–
show
$fetched_mimetype does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
84 | $this->assertEquals($mimetype, $fetched_mimetype); |
||
0 ignored issues
–
show
$fetched_mimetype does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
85 | } |
||
86 | |||
87 | // fallback: unknown mimetype is always "application/octet-stream" |
||
88 | #$file = vfsStream::url('root/file.crap'); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
55% 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. ![]() |
|||
89 | #$this->assertEquals('application/octet-stream', $this->object->getMimeType($file)); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
77% 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. ![]() |
|||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @runInSeparateProcess |
||
94 | * -preserveGlobalState disabled |
||
95 | * @covers Koch\Files\Download::sendFile |
||
96 | */ |
||
97 | public function testSendFile() |
||
98 | { |
||
99 | $file = __DIR__ . DIRECTORY_SEPARATOR . 'DownloadTest.php'; |
||
100 | $this->object->sendFile($file); |
||
101 | |||
102 | $this->expectOutputString(file_get_contents($file)); |
||
103 | } |
||
104 | } |
||
105 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: