• 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.3
/src/Commands/Notification.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/NotificationMakeCommand.php
13
 */
14
#[AsCommand(name: 'make:notification', description: 'Create a new notification class')]
15
class Notification extends Generator
16
{
17
    use CreatesMatchingTest;
18

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

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

33
    /**
34
     * The type of class being generated.
35
     *
36
     * @var string
37
     */
38
    protected string $type = 'Notification';
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')) {
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 getPublishedStubFileName(): ?string
63
    {
64
        return $this->getStubFileName();
2✔
65
    }
66

67
    /**
68
     * Get the stub file for the generator.
69
     */
70
    public function getStubFile(): string
71
    {
72
        return $this->getStubFileFromPresetStorage($this->preset, $this->getStubFileName());
2✔
73
    }
74

75
    /**
76
     * Get the stub file name for the generator.
77
     */
78
    public function getStubFileName(): string
79
    {
80
        return $this->option('markdown') !== false
2✔
81
            ? 'markdown-notification.stub'
1✔
82
            : 'notification.stub';
2✔
83
    }
84

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

93
    /**
94
     * Generator options.
95
     *
96
     * @return array<string, mixed>
97
     */
98
    public function generatorOptions(): array
99
    {
100
        return [
2✔
101
            'markdown' => $this->option('markdown') ?? null,
2✔
102
            'view' => $this->componentView(),
2✔
103
            'force' => $this->option('force'),
2✔
104
        ];
2✔
105
    }
106

107
    /**
108
     * Write the Markdown template for the mailable.
109
     */
110
    protected function writeMarkdownTemplate(): void
111
    {
112
        $path = $this->preset->resourcePath().'/views/'.str_replace('.', '/', $this->componentView()).'.blade.php';
1✔
113

114
        if (! $this->files->isDirectory(\dirname($path))) {
1✔
115
            $this->files->makeDirectory(\dirname($path), 0755, true);
×
116
        }
117

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

121
    /**
122
     * Get the view name.
123
     *
124
     * @return string
125
     */
126
    protected function componentView(): string
127
    {
128
        /** @var string|null $view */
129
        $view = $this->option('markdown');
2✔
130

131
        if (! $view) {
2✔
132
            /** @var string $name */
133
            $name = $this->argument('name');
1✔
134

135
            $view = 'mail.'.Str::kebab(class_basename($name));
1✔
136
        }
137

138
        return $view;
2✔
139
    }
140

141
    /**
142
     * Get the console command options.
143
     *
144
     * @return array<int, array>
145
     */
146
    protected function getOptions()
147
    {
148
        return [
90✔
149
            ['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the notification already exists'],
90✔
150
            ['markdown', 'm', InputOption::VALUE_OPTIONAL, 'Create a new Markdown template for the notification', false],
90✔
151
        ];
90✔
152
    }
153
}
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

© 2025 Coveralls, Inc