UnknownTypeMock::getSample()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 16
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: danchukas
6
 * Date: 2017-07-18 08:46
7
 */
8
9
namespace DanchukAS\Mock\Type;
10
11
12
use DanchukAS\Mock\TypeMock;
13
14
/**
15
 * Class UnknownTypeMock
16
 * @package DanchukAS\Mock\Type
17
 */
18
class UnknownTypeMock extends TypeMock
19
{
20
21
    /**
22
     * @return \Generator
23
     */
24
    public static function getSample()
25
    {
26
        $file_name = self::newTempFile();
27
        $resource = fopen($file_name, 'rb');
28
        fclose($resource);
0 ignored issues
show
Bug introduced by
It seems like $resource can also be of type false; however, parameter $handle of fclose() 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

28
        fclose(/** @scrutinizer ignore-type */ $resource);
Loading history...
29
        $unknown = $resource;
30
        yield [$unknown];
31
32
        /** @noinspection PhpUsageOfSilenceOperatorInspection */
33
        @unlink($file_name);
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

33
        /** @scrutinizer ignore-unhandled */ @unlink($file_name);

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...
34
35
        if (function_exists('imagecreate')) {
36
            $resource = \imagecreate(1, 1);
37
            \imagedestroy($resource);
38
            $unknown = $resource;
39
            yield [$unknown];
40
        }
41
    }
42
43
    /**
44
     * @return bool|string
45
     */
46
    private static function newTempFile()
47
    {
48
        return tempnam(sys_get_temp_dir(), 'vo_');
49
    }
50
}