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

FileCreator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
dl 0
loc 26
rs 10
c 1
b 0
f 1
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A writeFile() 0 15 3
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