Completed
Pull Request — master (#20)
by Anatoliy
27:24 queued 17:25
created

UnknownTypeMock   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A newTempFile() 0 5 1
A getSample() 0 14 2
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|resource
23
     */
24
    public static function getSample()
25
    {
26
        $file_name = self::newTempFile();
27
        $resource = fopen($file_name, 'r');
28
        fclose($resource);
29
        $unknown = $resource;
30
        yield [$unknown];
31
        @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

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