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

XToLocalFile::convert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 2
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