Passed
Push — master ( 80342f...7969ca )
by Korotkov
03:23 queued 01:37
created

CreateFactoryCommand::actionIndex()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 11
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 18
rs 9.9
1
<?php
2
3
namespace App\Ship\Command;
4
5
use App\Ship\Utils\FileCreator;
6
use Rudra\Container\Facades\Rudra;
7
use Rudra\Cli\ConsoleFacade as Cli;
8
9
class CreateFactoryCommand extends FileCreator
10
{
11
    /**
12
     * Creates a file with Seed data
13
     * -----------------------------
14
     * Создает файл с данными Seed
15
     */
16
    public function actionIndex(): void
17
    {
18
        Cli::printer("Enter factory name: ", "magneta");
19
        $prefix    = str_replace(PHP_EOL, "", Cli::reader());
20
        $className = ucfirst($prefix) . 'Factory';
21
22
        Cli::printer("Enter container: ", "magneta");
23
        $container = ucfirst(str_replace(PHP_EOL, "", Cli::reader()));
24
25
        if (!empty($container)) {
26
27
            $this->writeFile(
28
                [str_replace('/', DIRECTORY_SEPARATOR, Rudra::config()->get('app.path') . "/app/Containers/$container/Factory/"), "{$className}.php"],
29
                $this->createClass($className, $container)
30
            );
31
32
        } else {
33
            $this->actionIndex();
34
        }
35
    }
36
37
    /**
38
     * Creates class data
39
     * ------------------
40
     * Создает данные класса
41
     *
42
     * @param string $className
43
     * @param string $container
44
     * @return string
45
     */
46
    private function createClass(string $className, string $container): string
47
    {
48
        return <<<EOT
49
<?php
50
51
namespace App\Containers\\{$container}\Factory;
52
53
class {$className}
54
{
55
    public function create()
56
    {
57
58
    }
59
}\r\n
60
EOT;
61
    }
62
}
63