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

orchestral / canvas / 30921614659

04 Aug 2026 02:57PM UTC coverage: 91.944% (-2.5%) from 94.459%
30921614659

Pull #53

github

crynobone
wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Pull Request #53: Supports `laravel/doctor`

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

31 existing lines in 11 files now uncovered.

662 of 720 relevant lines covered (91.94%)

35.57 hits per line

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

74.58
/src/Console/ModelMakeCommand.php
1
<?php
2

3
namespace Orchestra\Canvas\Console;
4

5
use Illuminate\Support\Str;
6
use Orchestra\Canvas\Core\Concerns\CodeGenerator;
7
use Orchestra\Canvas\Core\Concerns\TestGenerator;
8
use Orchestra\Canvas\Core\Concerns\UsesGeneratorOverrides;
9
use Symfony\Component\Console\Attribute\AsCommand;
10

11
/**
12
 * @see https://github.com/laravel/framework/blob/11.x/src/Illuminate/Foundation/Console/ModelMakeCommand.php
13
 */
14
#[AsCommand(name: 'make:model', description: 'Create a new Eloquent model class')]
15
class ModelMakeCommand extends \Illuminate\Foundation\Console\ModelMakeCommand
16
{
17
    use CodeGenerator;
18
    use TestGenerator;
19
    use UsesGeneratorOverrides;
20

21
    /**
22
     * Configures the current command.
23
     *
24
     * @return void
25
     */
26
    #[\Override]
27
    protected function configure()
28
    {
29
        parent::configure();
9✔
30

31
        $this->addGeneratorPresetOptions();
9✔
32
    }
33

34
    /**
35
     * Execute the console command.
36
     *
37
     * @return bool|null
38
     *
39
     * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
40
     */
41
    #[\Override]
42
    public function handle()
43
    {
44
        /** @phpstan-ignore return.type */
45
        return $this->generateCode() ? self::SUCCESS : self::FAILURE;
9✔
46
    }
47

48
    /**
49
     * Run after code successfully generated.
50
     */
51
    protected function afterCodeHasBeenGenerated(): void
52
    {
53
        if ($this->option('all')) {
9✔
54
            $this->input->setOption('factory', true);
×
55
            $this->input->setOption('seed', true);
×
56
            $this->input->setOption('migration', true);
×
57
            $this->input->setOption('controller', true);
×
UNCOV
58
            $this->input->setOption('policy', true);
×
UNCOV
59
            $this->input->setOption('resource', true);
×
60
        }
61

62
        if ($this->option('factory')) {
9✔
63
            $this->createFactory();
1✔
64
        }
65

66
        if ($this->option('migration')) {
9✔
67
            $this->createMigration();
1✔
68
        }
69

70
        if ($this->option('seed')) {
9✔
71
            $this->createSeeder();
1✔
72
        }
73

74
        if ($this->option('controller') || $this->option('resource') || $this->option('api')) {
9✔
75
            $this->createController();
2✔
76
        }
77

78
        if ($this->option('policy')) {
9✔
UNCOV
79
            $this->createPolicy();
×
80
        }
81
    }
82

83
    /**
84
     * Create a model factory for the model.
85
     *
86
     * @return void
87
     */
88
    #[\Override]
89
    protected function createFactory()
90
    {
91
        $factory = Str::studly($this->getNameInput());
1✔
92

93
        $this->call('make:factory', [
1✔
94
            'name' => "{$factory}Factory",
1✔
95
            '--model' => $this->qualifyClass($this->getNameInput()),
1✔
96
            '--preset' => $this->option('preset'),
1✔
97
        ]);
1✔
98
    }
99

100
    /**
101
     * Create a migration file for the model.
102
     *
103
     * @return void
104
     */
105
    #[\Override]
106
    protected function createMigration()
107
    {
108
        $table = Str::snake(Str::pluralStudly(class_basename($this->getNameInput())));
1✔
109

110
        if ($this->option('pivot')) {
1✔
UNCOV
111
            $table = Str::singular($table);
×
112
        }
113

114
        $this->call('make:migration', [
1✔
115
            'name' => "create_{$table}_table",
1✔
116
            '--create' => $table,
1✔
117
            '--fullpath' => true,
1✔
118
            '--preset' => $this->option('preset'),
1✔
119
        ]);
1✔
120
    }
121

122
    /**
123
     * Create a seeder file for the model.
124
     *
125
     * @return void
126
     */
127
    #[\Override]
128
    protected function createSeeder()
129
    {
130
        $seeder = Str::studly(class_basename($this->getNameInput()));
1✔
131

132
        $this->call('make:seeder', [
1✔
133
            'name' => "{$seeder}Seeder",
1✔
134
            '--preset' => $this->option('preset'),
1✔
135
        ]);
1✔
136
    }
137

138
    /**
139
     * Create a controller for the model.
140
     *
141
     * @return void
142
     */
143
    #[\Override]
144
    protected function createController()
145
    {
146
        $controller = Str::studly(class_basename($this->getNameInput()));
2✔
147

148
        $modelName = $this->qualifyClass($this->getNameInput());
2✔
149

150
        $this->call('make:controller', array_filter([
2✔
151
            'name' => "{$controller}Controller",
2✔
152
            '--model' => $this->option('resource') || $this->option('api') ? $modelName : null,
2✔
153
            '--api' => $this->option('api'),
2✔
154
            '--requests' => $this->option('requests') || $this->option('all'),
2✔
155
            '--preset' => $this->option('preset'),
2✔
156
        ]));
2✔
157
    }
158

159
    /**
160
     * Create a policy file for the model.
161
     *
162
     * @return void
163
     */
164
    #[\Override]
165
    protected function createPolicy()
166
    {
167
        $policy = Str::studly(class_basename($this->getNameInput()));
×
168

169
        $this->call('make:policy', [
×
170
            'name' => "{$policy}Policy",
×
171
            '--model' => $this->qualifyClass($this->getNameInput()),
×
UNCOV
172
            '--preset' => $this->option('preset'),
×
UNCOV
173
        ]);
×
174
    }
175

176
    /**
177
     * Get the default namespace for the class.
178
     *
179
     * @param  string  $rootNamespace
180
     * @return string
181
     */
182
    #[\Override]
183
    protected function getDefaultNamespace($rootNamespace)
184
    {
185
        return rtrim($this->generatorPreset()->modelNamespace(), '\\');
9✔
186
    }
187

188
    /**
189
     * Qualify the given model class base name.
190
     *
191
     * @return string
192
     */
193
    #[\Override]
194
    protected function qualifyModel(string $model)
195
    {
UNCOV
196
        return $this->qualifyModelUsingCanvas($model);
×
197
    }
198

199
    /**
200
     * Get the destination class path.
201
     *
202
     * @param  string  $name
203
     * @return string
204
     */
205
    #[\Override]
206
    protected function getPath($name)
207
    {
208
        return $this->getPathUsingCanvas($name);
9✔
209
    }
210

211
    /**
212
     * Get the root namespace for the class.
213
     *
214
     * @return string
215
     */
216
    #[\Override]
217
    protected function rootNamespace()
218
    {
219
        return $this->rootNamespaceUsingCanvas();
9✔
220
    }
221
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc