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

ArrayToYml::actionIndex()   A

Complexity

Conditions 2
Paths 5

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 5
nop 0
dl 0
loc 14
rs 9.9332
c 0
b 0
f 0
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