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

CreateInterfaceCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A actionIndex() 0 18 2
A createClass() 0 8 1
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 CreateInterfaceCommand 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 interface name: ", "magneta");
19
        $prefix    = str_replace(PHP_EOL, "", Cli::reader());
20
        $className = ucfirst($prefix) . 'Interface';
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/Interface/"), "{$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}\Interface;
52
53
interface {$className}
54
{
55
56
}\r\n
57
EOT;
58
    }
59
}
60