• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

orchestral / canvas / 3848713348

pending completion
3848713348

push

github

Mior Muhammad Zaki
Merge branch '7.x'

772 of 799 relevant lines covered (96.62%)

19.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.18
/src/Commands/Routing/Controller.php
1
<?php
2

3
namespace Orchestra\Canvas\Commands\Routing;
4

5
use Orchestra\Canvas\Commands\Generator;
6
use Orchestra\Canvas\Processors\GeneratesControllerCode;
7
use Symfony\Component\Console\Input\InputOption;
8

9
/**
10
 * @see https://github.com/laravel/framework/blob/9.x/src/Illuminate/Routing/Console/ControllerMakeCommand.php
11
 */
12
class Controller extends Generator
13
{
14
    /**
15
     * The console command name.
16
     *
17
     * @var string
18
     */
19
    protected $name = 'make:controller';
20

21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Create a new controller class';
27

28
    /**
29
     * The type of class being generated.
30
     *
31
     * @var string
32
     */
33
    protected string $type = 'Controller';
34

35
    /**
36
     * Generator processor.
37
     *
38
     * @var string
39
     */
40
    protected $processor = GeneratesControllerCode::class;
41

42
    /**
43
     * Get the stub file for the generator.
44
     */
45
    public function getPublishedStubFileName(): ?string
46
    {
47
        return $this->getStubFileName();
16✔
48
    }
49

50
    /**
51
     * Get the stub file for the generator.
52
     */
53
    public function getStubFile(): string
54
    {
55
        return $this->getStubFileFromPresetStorage($this->preset, $this->getStubFileName());
16✔
56
    }
57

58
    /**
59
     * Get the stub file name for the generator.
60
     */
61
    public function getStubFileName(): string
62
    {
63
        $stub = null;
16✔
64

65
        /** @var string $type */
66
        $type = $this->option('type');
16✔
67

68
        if ($type) {
16✔
69
            $stub = "controller.{$type}.stub";
1✔
70
        } elseif ($this->option('parent')) {
15✔
71
            $stub = $this->option('singleton')
2✔
72
                        ? 'controller.nested.singleton.stub'
×
73
                        : 'controller.nested.stub';
2✔
74
        } elseif ($this->option('model')) {
13✔
75
            $stub = 'controller.model.stub';
7✔
76
        } elseif ($this->option('invokable')) {
6✔
77
            $stub = 'controller.invokable.stub';
2✔
78
        } elseif ($this->option('singleton')) {
4✔
79
            $stub = 'controller.singleton.stub';
×
80
        } elseif ($this->option('resource')) {
4✔
81
            $stub = 'controller.stub';
×
82
        }
83

84
        if ($this->option('api') && \is_null($stub)) {
16✔
85
            $stub = 'controller.api.stub';
1✔
86
        } elseif ($this->option('api') && ! \is_null($stub) && ! $this->option('invokable')) {
15✔
87
            $stub = str_replace('.stub', '.api.stub', $stub);
2✔
88
        }
89

90
        return $stub ?? 'controller.plain.stub';
16✔
91
    }
92

93
    /**
94
     * Get the default namespace for the class.
95
     */
96
    public function getDefaultNamespace(string $rootNamespace): string
97
    {
98
        return $rootNamespace.'\Http\Controllers';
16✔
99
    }
100

101
    /**
102
     * Generator options.
103
     *
104
     * @return array<string, mixed>
105
     */
106
    public function generatorOptions(): array
107
    {
108
        return array_merge(parent::generatorOptions(), [
16✔
109
            'model' => $this->option('model'),
16✔
110
            'parent' => $this->option('parent'),
16✔
111
            'requests' => $this->option('requests'),
16✔
112
        ]);
16✔
113
    }
114

115
    /**
116
     * Create model.
117
     */
118
    public function createModel(string $className): void
119
    {
120
        if ($this->confirm("A {$className} model does not exist. Do you want to generate it?", true)) {
9✔
121
            $this->call('make:model', ['name' => $className]);
9✔
122
        }
123
    }
124

125
    /**
126
     * Create request.
127
     */
128
    public function createRequest(string $className): void
129
    {
130
        if ($this->confirm("A {$className} request does not exist. Do you want to generate it?", true)) {
1✔
131
            $this->call('make:request', ['name' => $className]);
1✔
132
        }
133
    }
134

135
    /**
136
     * Get the console command options.
137
     *
138
     * @return array<int, array>
139
     */
140
    protected function getOptions()
141
    {
142
        return [
84✔
143
            ['api', null, InputOption::VALUE_NONE, 'Exclude the create and edit methods from the controller.'],
84✔
144
            ['force', null, InputOption::VALUE_NONE, 'Create the class even if the controller already exists'],
84✔
145
            ['invokable', 'i', InputOption::VALUE_NONE, 'Generate a single method, invokable controller class.'],
84✔
146
            ['model', 'm', InputOption::VALUE_OPTIONAL, 'Generate a resource controller for the given model.'],
84✔
147
            ['parent', 'p', InputOption::VALUE_OPTIONAL, 'Generate a nested resource controller class.'],
84✔
148
            ['resource', 'r', InputOption::VALUE_NONE, 'Generate a resource controller class.'],
84✔
149
            ['singleton', 's', InputOption::VALUE_NONE, 'Generate a singleton resource controller class'],
84✔
150
            ['type', null, InputOption::VALUE_REQUIRED, 'Manually specify the controller stub file to use.'],
84✔
151
            ['requests', 'R', InputOption::VALUE_NONE, 'Create new form request classes and use them in the resource controller'],
84✔
152
        ];
84✔
153
    }
154
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc