CreateListenerCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

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

2 Methods

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