Issues (197)

src/Commands/TransformerCommand.php (1 issue)

1
<?php
2
namespace Salah3id\Domains\Commands;
3
4
use Illuminate\Console\Command;
5
use Illuminate\Support\Collection;
6
use Salah3id\Domains\Repository\Generators\FileAlreadyExistsException;
7
use Salah3id\Domains\Repository\Generators\TransformerGenerator;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputOption;
10
use Salah3id\Domains\Traits\DomainCommandTrait;
11
12
/**
13
 * Class TransformerCommand
14
 * @package Salah3id\Domains\Commands
15
 * @author Anderson Andrade <[email protected]>
16
 */
17
class TransformerCommand extends Command
18
{
19
20
    use DomainCommandTrait;
21
    /**
22
     * The name of command.
23
     *
24
     * @var string
25
     */
26
    protected $name = 'domain:transformer';
27
28
    /**
29
     * The description of command.
30
     *
31
     * @var string
32
     */
33
    protected $description = 'Create a new transformer.';
34
35
    /**
36
     * The type of class being generated.
37
     *
38
     * @var string
39
     */
40
    protected $type = 'Transformer';
41
42
    /**
43
     * Execute the command.
44
     *
45
     * @see fire()
46
     * @return void
47
     */
48
    public function handle(){
49
        $this->laravel->call([$this, 'fire'], func_get_args());
50
    }
51
52
    /**
53
     * Execute the command.
54
     *
55
     * @return void
56
     */
57
    public function fire()
58
    {
59
        $domain = $this->getDomainNameForRepo();
60
        $domainPath = $this->laravel['domains']->getDomainPath($domain);
61
        try {
62
            (new TransformerGenerator([
63
                'name' => $this->argument('name'),
64
                'force' => $this->option('force'),
65
            ],$domain,$domainPath))->run();
66
            $this->info("Transformer created successfully.");
67
        } catch (FileAlreadyExistsException $e) {
68
            $this->error($this->type . ' already exists!');
69
70
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type void.
Loading history...
71
        }
72
    }
73
74
75
    /**
76
     * The array of command arguments.
77
     *
78
     * @return array
79
     */
80
    public function getArguments()
81
    {
82
        return [
83
            [
84
                'name',
85
                InputArgument::REQUIRED,
86
                'The name of model for which the transformer is being generated.',
87
                null
88
            ],
89
        ];
90
    }
91
92
    /**
93
     * The array of command options.
94
     *
95
     * @return array
96
     */
97
    public function getOptions()
98
    {
99
        return [
100
            [
101
                'force',
102
                'f',
103
                InputOption::VALUE_NONE,
104
                'Force the creation if file already exists.',
105
                null
106
            ]
107
        ];
108
    }
109
}
110