Passed
Push — master ( 1a6375...8f4058 )
by Petr
08:21 queued 05:12
created

ToLocalFileTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 27
c 0
b 0
f 0
dl 0
loc 54
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testNone2() 0 7 1
A testResource() 0 9 1
A testNone1() 0 7 1
A testString() 0 11 1
1
<?php
2
3
namespace tests\ChecksTests\TraitsTests;
4
5
6
use tests\CommonTestClass;
7
use kalanis\kw_mime\MimeException;
8
9
10
class ToLocalFileTest extends CommonTestClass
11
{
12
    /**
13
     * @throws MimeException
14
     */
15
    public function testNone1(): void
16
    {
17
        $lib = new XToLocalFile();
18
        $lib->initTempFile();
19
        @unlink($lib->getTempFile());
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

19
        /** @scrutinizer ignore-unhandled */ @unlink($lib->getTempFile());

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
20
        $this->expectException(MimeException::class);
21
        $lib->convert('file', /** @scrutinizer ignore-type */ false);
22
    }
23
24
    /**
25
     * @throws MimeException
26
     */
27
    public function testNone2(): void
28
    {
29
        $lib = new XToLocalFile();
30
        $lib->initTempFile();
31
        @unlink($lib->getTempFile());
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

31
        /** @scrutinizer ignore-unhandled */ @unlink($lib->getTempFile());

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
32
        $this->expectException(MimeException::class);
33
        $lib->convert('file', /** @scrutinizer ignore-type */ null);
34
    }
35
36
    /**
37
     * @throws MimeException
38
     */
39
    public function testString(): void
40
    {
41
        $lib = new XToLocalFile();
42
        $lib->initTempFile();
43
        $pt1 = $lib->convert('data', 'test data');
44
        $this->assertEquals('test data', file_get_contents($pt1));
45
        @unlink($pt1);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

45
        /** @scrutinizer ignore-unhandled */ @unlink($pt1);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
46
        $lib->initTempFile();
47
        $pt2 = $lib->convert('nums', /** @scrutinizer ignore-type */ 123456);
48
        $this->assertEquals('123456', file_get_contents($pt2));
49
        @unlink($pt2);
50
    }
51
52
    /**
53
     * @throws MimeException
54
     */
55
    public function testResource(): void
56
    {
57
        $lib = new XToLocalFile();
58
        $res = @fopen('php://memory', 'r+');
59
        fwrite($res, 'okmijnuhb');
0 ignored issues
show
Bug introduced by
It seems like $res can also be of type false; however, parameter $stream of fwrite() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

59
        fwrite(/** @scrutinizer ignore-type */ $res, 'okmijnuhb');
Loading history...
60
        $lib->initTempFile();
61
        $pt1 = $lib->convert('res', $res);
0 ignored issues
show
Bug introduced by
It seems like $res can also be of type false; however, parameter $content of tests\ChecksTests\Traits...XToLocalFile::convert() does only seem to accept resource|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
        $pt1 = $lib->convert('res', /** @scrutinizer ignore-type */ $res);
Loading history...
62
        $this->assertEquals('okmijnuhb', file_get_contents($pt1));
63
        @unlink($pt1);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

63
        /** @scrutinizer ignore-unhandled */ @unlink($pt1);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
64
    }
65
}
66