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

orchestral / canvas / 6018618864

29 Aug 2023 11:32PM UTC coverage: 94.256% (-0.1%) from 94.387%
6018618864

push

github

crynobone
Merge branch '6.x' into 7.x

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

804 of 853 relevant lines covered (94.26%)

21.88 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\Input\InputOption;
8

9
/**
10
 * @see https://github.com/laravel/framework/blob/9.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 $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 name for the generator.
67
     */
68
    public function getStubFileName(): string
69
    {
70
        return $this->option('markdown') !== false
2✔
71
            ? 'markdown-notification.stub'
1✔
72
            : 'notification.stub';
2✔
73
    }
74

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

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

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

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

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

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

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

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

128
        return $view;
2✔
129
    }
130

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