FileHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 25
ccs 10
cts 10
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A placeFile() 0 4 1
A deleteReceived() 0 4 2
A makeDir() 0 3 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AHJ\ApprovalTests;
6
7
final class FileHandler
8
{
9
    /**
10
     * @param string $path     Example:
11
     *                         'tests/Example/approval'
12
     * @param string $fileName
13
     *                         Example:
14
     *                         'GildedRoseTest.testUpdateQuality.received.txt'
15
     */
16 2
    public function placeFile(string $path, string $fileName, string $content = null): void
17
    {
18 2
        $this->makeDir($path);
19 2
        file_put_contents($path . '/' . $fileName, $content);
20 2
    }
21
22 2
    public function deleteReceived(FilePathResolverResult $filePathResolved): void
23
    {
24 2
        if (file_exists($filePathResolved->getReceivedFile())) {
25 2
            unlink($filePathResolved->getReceivedFile());
26
        }
27 2
    }
28
29 2
    private function makeDir(string $path): bool
30
    {
31 2
        return is_dir($path) || mkdir($path, 0777, true);
32
    }
33
}
34