FileHandler::makeDir()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

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