FileHandler::placeFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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