Completed
Pull Request — master (#94)
by Alessandro
08:53
created

TempFilenameFactory::getTempFilename()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 2
cts 2
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 3
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Paraunit\Configuration;
5
6
use Paraunit\File\TempDirectory;
7
8
/**
9
 * Class TempFilenameFactory
10
 * @package Tests\Unit\Parser
11
 */
12
class TempFilenameFactory
13
{
14
    /** @var TempDirectory */
15
    private $tempDirectory;
16
17
    /**
18
     * TempFilenameFactory constructor.
19
     * @param TempDirectory $tempDirectory
20 42
     */
21
    public function __construct(TempDirectory $tempDirectory)
22 42
    {
23 42
        $this->tempDirectory = $tempDirectory;
24
    }
25
26
    public function getPathForLog(): string
27
    {
28 17
        return $this->getTempSubDir('logs');
29
    }
30 17
31
    /**
32
     * @param string $uniqueId
33
     * @return string
34
     */
35
    public function getFilenameForLog(string $uniqueId): string
36
    {
37 31
        return $this->getTempFilename('logs', $uniqueId, 'json.log');
38
    }
39 31
40
    public function getFilenameForCoverage(string $uniqueId): string
41
    {
42
        return $this->getTempFilename('coverage', $uniqueId, 'php');
43
    }
44
45
    public function getFilenameForConfiguration(): string
46 2
    {
47
        return $this->getTempFilename('config', 'phpunit', 'xml.dist');
48 2
    }
49
50
    private function getTempFilename(string $subDir, string $filename, string $extension): string
51
    {
52
        return $this->getTempSubDir($subDir)
53
            . $filename
54 1
            . '.'
55
            . $extension;
56 1
    }
57
58
    private function getTempSubDir(string $subDir): string
59
    {
60
        return $this->tempDirectory->getTempDirForThisExecution()
61
            . DIRECTORY_SEPARATOR
62
            . $subDir
63
            . DIRECTORY_SEPARATOR;
64 34
    }
65
}
66