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

orchestral / canvas / 6018618864

29 Aug 2023 11:32PM UTC coverage: 94.256% (-0.1%) from 94.387%
6018618864

push

github

crynobone
Merge branch '6.x' into 7.x

2 of 2 new or added lines in 2 files covered. (100.0%)

804 of 853 relevant lines covered (94.26%)

21.88 hits per line

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

93.02
/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
#[\Symfony\Component\Console\Attribute\AsCommand(name: 'make:controller')]
13
class Controller extends Generator
14
{
15
    /**
16
     * The console command name.
17
     *
18
     * @var string
19
     */
20
    protected $name = 'make:controller';
21

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

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

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

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

51
    /**
52
     * Get the stub file name for the generator.
53
     */
54
    public function getStubFileName(): string
55
    {
56
        $stub = null;
16✔
57

58
        /** @var string $type */
59
        $type = $this->option('type');
16✔
60

61
        if ($type) {
16✔
62
            $stub = "controller.{$type}.stub";
1✔
63
        } elseif ($this->option('parent')) {
15✔
64
            $stub = $this->option('singleton')
2✔
65
                        ? 'controller.nested.singleton.stub'
×
66
                        : 'controller.nested.stub';
2✔
67
        } elseif ($this->option('model')) {
13✔
68
            $stub = 'controller.model.stub';
7✔
69
        } elseif ($this->option('invokable')) {
6✔
70
            $stub = 'controller.invokable.stub';
2✔
71
        } elseif ($this->option('singleton')) {
4✔
72
            $stub = 'controller.singleton.stub';
×
73
        } elseif ($this->option('resource')) {
4✔
74
            $stub = 'controller.stub';
×
75
        }
76

77
        if ($this->option('api') && \is_null($stub)) {
16✔
78
            $stub = 'controller.api.stub';
1✔
79
        } elseif ($this->option('api') && ! \is_null($stub) && ! $this->option('invokable')) {
15✔
80
            $stub = str_replace('.stub', '.api.stub', $stub);
2✔
81
        }
82

83
        return $stub ?? 'controller.plain.stub';
16✔
84
    }
85

86
    /**
87
     * Get the default namespace for the class.
88
     */
89
    public function getDefaultNamespace(string $rootNamespace): string
90
    {
91
        return $rootNamespace.'\Http\Controllers';
16✔
92
    }
93

94
    /**
95
     * Generator options.
96
     *
97
     * @return array<string, mixed>
98
     */
99
    public function generatorOptions(): array
100
    {
101
        return array_merge(parent::generatorOptions(), [
16✔
102
            'model' => $this->option('model'),
16✔
103
            'parent' => $this->option('parent'),
16✔
104
            'requests' => $this->option('requests'),
16✔
105
        ]);
16✔
106
    }
107

108
    /**
109
     * Create model.
110
     */
111
    public function createModel(string $className): void
112
    {
113
        if ($this->confirm("A {$className} model does not exist. Do you want to generate it?", true)) {
9✔
114
            $this->call('make:model', ['name' => $className]);
9✔
115
        }
116
    }
117

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

128
    /**
129
     * Get the console command options.
130
     *
131
     * @return array<int, array>
132
     */
133
    protected function getOptions()
134
    {
135
        return [
90✔
136
            ['api', null, InputOption::VALUE_NONE, 'Exclude the create and edit methods from the controller.'],
90✔
137
            ['force', null, InputOption::VALUE_NONE, 'Create the class even if the controller already exists'],
90✔
138
            ['invokable', 'i', InputOption::VALUE_NONE, 'Generate a single method, invokable controller class.'],
90✔
139
            ['model', 'm', InputOption::VALUE_OPTIONAL, 'Generate a resource controller for the given model.'],
90✔
140
            ['parent', 'p', InputOption::VALUE_OPTIONAL, 'Generate a nested resource controller class.'],
90✔
141
            ['resource', 'r', InputOption::VALUE_NONE, 'Generate a resource controller class.'],
90✔
142
            ['singleton', 's', InputOption::VALUE_NONE, 'Generate a singleton resource controller class'],
90✔
143
            ['type', null, InputOption::VALUE_REQUIRED, 'Manually specify the controller stub file to use.'],
90✔
144
            ['requests', 'R', InputOption::VALUE_NONE, 'Create new form request classes and use them in the resource controller'],
90✔
145
        ];
90✔
146
    }
147
}
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