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

ArrayToYml   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A actionIndex() 0 14 2
1
<?php
2
3
namespace App\Ship\Command;
4
5
use Exception;
6
use Symfony\Component\Yaml\Yaml;
7
use Rudra\Cli\ConsoleFacade as Cli;
8
9
class ArrayToYml
10
{
11
    public function actionIndex(): void
12
    {
13
        Cli::printer("Put the file containing the array into a directory\n", "green");
14
        Cli::printer("Enter filename with php Array: ", "magneta");
15
        $filename = trim(fgets(fopen("php://stdin", "r")));
16
17
        try {
18
            $array = include("config/$filename.php");
19
            $yaml = Yaml::dump($array);
20
            file_put_contents("config/$filename.yml", $yaml);
21
22
            Cli::printer("Yml was created" . PHP_EOL, "cyan", );
23
        } catch (Exception $e) {
24
            echo 'Exception: ',  $e->getMessage(), "\n";
25
        }
26
    }
27
}
28