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

orchestral / canvas / 6018895533

30 Aug 2023 12:15AM UTC coverage: 94.242% (-0.01%) from 94.256%
6018895533

push

github

crynobone
wip

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

802 of 851 relevant lines covered (94.24%)

21.72 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\Support\Str;
6
use Orchestra\Canvas\Processors\GeneratesCodeWithMarkdown;
7
use Symfony\Component\Console\Attribute\AsCommand;
8
use Symfony\Component\Console\Input\InputOption;
9

10
/**
11
 * @see https://github.com/laravel/framework/blob/9.x/src/Illuminate/Foundation/Console/NotificationMakeCommand.php
12
 */
13
#[AsCommand(name: 'make:notification', description: 'Create a new notification class')]
14
class Notification extends Generator
15
{
16
    /**
17
     * The type of class being generated.
18
     *
19
     * @var string
20
     */
21
    protected string $type = 'Notification';
22

23
     /**
24
     * Generator processor.
25
     *
26
     * @var class-string<\Orchestra\Canvas\Core\GeneratesCode>
27
     */
28
    protected string $processor = GeneratesCodeWithMarkdown::class;
29

30
    /**
31
     * Code successfully generated.
32
     */
33
    public function codeHasBeenGenerated(string $className): int
34
    {
35
        $exitCode = parent::codeHasBeenGenerated($className);
2✔
36

37
        if ($this->option('markdown')) {
2✔
38
            $this->writeMarkdownTemplate();
1✔
39
        }
40

41
        return $exitCode;
2✔
42
    }
43

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

52
    /**
53
     * Get the stub file name for the generator.
54
     */
55
    public function getStubFileName(): string
56
    {
57
        return $this->option('markdown') !== false
2✔
58
            ? 'markdown-notification.stub'
1✔
59
            : 'notification.stub';
2✔
60
    }
61

62
    /**
63
     * Get the default namespace for the class.
64
     */
65
    public function getDefaultNamespace(string $rootNamespace): string
66
    {
67
        return $rootNamespace.'\Notifications';
2✔
68
    }
69

70
    /**
71
     * Generator options.
72
     *
73
     * @return array<string, mixed>
74
     */
75
    public function generatorOptions(): array
76
    {
77
        return [
2✔
78
            'markdown' => $this->option('markdown') ?? null,
2✔
79
            'view' => $this->componentView(),
2✔
80
            'force' => $this->option('force'),
2✔
81
        ];
2✔
82
    }
83

84
    /**
85
     * Write the Markdown template for the mailable.
86
     */
87
    protected function writeMarkdownTemplate(): void
88
    {
89
        $path = $this->preset->resourcePath().'/views/'.str_replace('.', '/', $this->componentView()).'.blade.php';
1✔
90

91
        if (! $this->files->isDirectory(\dirname($path))) {
1✔
92
            $this->files->makeDirectory(\dirname($path), 0755, true);
×
93
        }
94

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

98
    /**
99
     * Get the view name.
100
     *
101
     * @return string
102
     */
103
    protected function componentView(): string
104
    {
105
        /** @var string|null $view */
106
        $view = $this->option('markdown');
2✔
107

108
        if (! $view) {
2✔
109
            /** @var string $name */
110
            $name = $this->argument('name');
1✔
111

112
            $view = 'mail.'.Str::kebab(class_basename($name));
1✔
113
        }
114

115
        return $view;
2✔
116
    }
117

118
    /**
119
     * Get the console command options.
120
     *
121
     * @return array<int, array>
122
     */
123
    protected function getOptions()
124
    {
125
        return [
90✔
126
            ['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the notification already exists'],
90✔
127
            ['markdown', 'm', InputOption::VALUE_OPTIONAL, 'Create a new Markdown template for the notification', false],
90✔
128
        ];
90✔
129
    }
130
}
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