Passed
Pull Request — master (#75)
by Korotkov
12:47
created

FileCreator::writeFile()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 10
nc 4
nop 2
dl 0
loc 15
rs 9.9332
c 1
b 0
f 1
1
<?php
2
3
namespace App\Ship\Utils;
4
5
use Rudra\Cli\ConsoleFacade as Cli;
6
7
class FileCreator
8
{
9
    /**
10
     * Writes data to a file
11
     * ---------------------
12
     * Записывает данные в файл
13
     *
14
     * @param array $path
15
     * @param string $data
16
     * @return void
17
     */
18
    protected function writeFile(array $path, string $data): void
19
    {
20
        if (!is_dir($path[0])) {
21
            mkdir($path[0], 0755, true);
22
        }
23
24
        $fullPath = $path[0] . $path[1];
25
26
        if (!file_exists($fullPath)) {
27
            Cli::printer("The file ", "light_green");
28
            Cli::printer($fullPath, "light_green");
29
            Cli::printer(" was created" . PHP_EOL, "light_green");
30
            file_put_contents($fullPath, $data);
31
        } else {
32
            Cli::printer("The file $fullPath is already exists" . PHP_EOL, "light_yellow");
33
        }
34
    }
35
}
36