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

XToLocalFile   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 28
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A convert() 0 5 1
A getTempFile() 0 3 1
A initTempFile() 0 4 1
1
<?php
2
3
namespace tests\ChecksTests\TraitsTests;
4
5
6
use kalanis\kw_mime\Check\Traits\TToLocalFile;
7
use kalanis\kw_mime\MimeException;
8
9
10
class XToLocalFile
11
{
12
    use TToLocalFile;
13
14
    protected ?string $tempFile = null;
15
16
    /**
17
     * @param string $name
18
     * @param string|resource $content
19
     * @throws MimeException
20
     * @return string
21
     */
22
    public function convert(string $name, $content): string
23
    {
24
        $localPath = strval($this->getTempFile());
25
        $this->readSourceToLocalFile($name, $content, $localPath);
26
        return $localPath;
27
    }
28
29
    public function initTempFile(): void
30
    {
31
        // beware! it immediately creates that temporary file
32
        $this->tempFile = tempnam(sys_get_temp_dir(), 'MimeSrcTest');
33
    }
34
35
    public function getTempFile(): ?string
36
    {
37
        return $this->tempFile;
38
    }
39
}
40