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

orchestral / canvas / 4665386932

pending completion
4665386932

push

github

Mior Muhammad Zaki
wip

807 of 834 relevant lines covered (96.76%)

21.96 hits per line

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

96.43
/src/Commands/Notification.php
1
<?php
2

3
namespace Orchestra\Canvas\Commands;
4

5
use Illuminate\Support\Str;
6
use Orchestra\Canvas\Processors\GeneratesCodeWithMarkdown;
7
use Symfony\Component\Console\Input\InputOption;
8

9
/**
10
 * @see https://github.com/laravel/framework/blob/10.x/src/Illuminate/Foundation/Console/NotificationMakeCommand.php
11
 */
12
#[\Symfony\Component\Console\Attribute\AsCommand(name: 'make:notification')]
13
class Notification extends Generator
14
{
15
    /**
16
     * The console command name.
17
     *
18
     * @var string
19
     */
20
    protected $name = 'make:notification';
21

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

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

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

43
    /**
44
     * Code successfully generated.
45
     */
46
    public function codeHasBeenGenerated(string $className): int
47
    {
48
        $exitCode = parent::codeHasBeenGenerated($className);
2✔
49

50
        if ($this->option('markdown')) {
2✔
51
            $this->writeMarkdownTemplate();
1✔
52
        }
53

54
        return $exitCode;
2✔
55
    }
56

57
    /**
58
     * Get the stub file for the generator.
59
     */
60
    public function getPublishedStubFileName(): ?string
61
    {
62
        return $this->getStubFileName();
2✔
63
    }
64

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

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

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

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

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

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

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

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

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

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

136
        return $view;
2✔
137
    }
138

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