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

orchestral / canvas / 5873375043

pending completion
5873375043

push

github

crynobone
wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

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

797 of 824 relevant lines covered (96.72%)

21.76 hits per line

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

96.15
/src/Commands/Mail.php
1
<?php
2

3
namespace Orchestra\Canvas\Commands;
4

5
use Illuminate\Console\Concerns\CreatesMatchingTest;
6
use Illuminate\Support\Str;
7
use Orchestra\Canvas\Processors\GeneratesCodeWithMarkdown;
8
use Symfony\Component\Console\Attribute\AsCommand;
9
use Symfony\Component\Console\Input\InputOption;
10

11
/**
12
 * @see https://github.com/laravel/framework/blob/10.x/src/Illuminate/Foundation/Console/MailMakeCommand.php
13
 */
14
#[AsCommand(name: 'make:mail', description: 'Create a new email class')]
15
class Mail extends Generator
16
{
17
    use CreatesMatchingTest;
18

19
    /**
20
     * The console command name.
21
     *
22
     * @var string
23
     */
24
    protected $name = 'make:mail';
25

26
    /**
27
     * The console command description.
28
     *
29
     * @var string
30
     */
31
    protected $description = 'Create a new email class';
32

33
    /**
34
     * The type of class being generated.
35
     *
36
     * @var string
37
     */
38
    protected string $type = 'Mailable';
39

40
    /**
41
     * Generator processor.
42
     *
43
     * @var string
44
     */
45
    protected $processor = GeneratesCodeWithMarkdown::class;
46

47
    /**
48
     * Run after code successfully generated.
49
     */
50
    public function afterCodeHasBeenGenerated(string $className, string $path): void
51
    {
52
        if ($this->option('markdown') !== false) {
2✔
53
            $this->writeMarkdownTemplate();
1✔
54
        }
55

56
        parent::afterCodeHasBeenGenerated($className, $path);
2✔
57
    }
58

59
    /**
60
     * Get the stub file for the generator.
61
     */
62
    public function getStubFile(): string
63
    {
64
        return $this->getStubFileFromPresetStorage($this->preset, $this->getStubFileName());
2✔
65
    }
66

67
    /**
68
     * Get the stub file name for the generator.
69
     */
70
    public function getStubFileName(): string
71
    {
72
        return $this->option('markdown')
2✔
73
            ? 'markdown-mail.stub'
1✔
74
            : 'mail.stub';
2✔
75
    }
76

77
    /**
78
     * Get the default namespace for the class.
79
     */
80
    public function getDefaultNamespace(string $rootNamespace): string
81
    {
82
        return $rootNamespace.'\Mail';
2✔
83
    }
84

85
    /**
86
     * Generator options.
87
     *
88
     * @return array<string, mixed>
89
     */
90
    public function generatorOptions(): array
91
    {
92
        return [
2✔
93
            'markdown' => $this->option('markdown') ?? null,
2✔
94
            'view' => $this->componentView(),
2✔
95
            'force' => $this->option('force'),
2✔
96
        ];
2✔
97
    }
98

99
    /**
100
     * Write the Markdown template for the mailable.
101
     */
102
    protected function writeMarkdownTemplate(): void
103
    {
104
        $path = $this->preset->resourcePath().'/views/'.str_replace('.', '/', $this->componentView()).'.blade.php';
1✔
105

106
        if (! $this->files->isDirectory(\dirname($path))) {
1✔
107
            $this->files->makeDirectory(\dirname($path), 0755, true);
×
108
        }
109

110
        $this->files->put($path, (string) file_get_contents(__DIR__.'/../../storage/laravel/markdown.stub'));
1✔
111
    }
112

113
    /**
114
     * Get the view name.
115
     *
116
     * @return string
117
     */
118
    protected function componentView(): string
119
    {
120
        /** @var string|null $view */
121
        $view = $this->option('markdown');
2✔
122

123
        if (! $view) {
2✔
124
            /** @var string $name */
125
            $name = $this->argument('name');
1✔
126

127
            $view = 'mail.'.Str::kebab(class_basename($name));
1✔
128
        }
129

130
        return $view;
2✔
131
    }
132

133
    /**
134
     * Get the console command options.
135
     *
136
     * @return array<int, array>
137
     */
138
    protected function getOptions()
139
    {
140
        return [
90✔
141
            ['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the mailable already exists'],
90✔
142
            ['markdown', 'm', InputOption::VALUE_OPTIONAL, 'Create a new Markdown template for the mailable', false],
90✔
143
        ];
90✔
144
    }
145
}
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