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

orchestral / canvas / 6047542927

01 Sep 2023 09:03AM UTC coverage: 94.11% (-0.2%) from 94.316%
6047542927

push

github

crynobone
Merge remote-tracking branch 'origin/master'

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

751 of 798 relevant lines covered (94.11%)

22.82 hits per line

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

96.15
/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\Core\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 type of class being generated.
21
     *
22
     * @var string
23
     */
24
    protected string $type = 'Notification';
25

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

33
    /**
34
     * Run after code successfully generated.
35
     */
36
    public function afterCodeHasBeenGenerated(string $className, string $path): void
37
    {
38
        if ($this->option('markdown')) {
2✔
39
            $this->writeMarkdownTemplate();
1✔
40
        }
41

42
        parent::afterCodeHasBeenGenerated($className, $path);
2✔
43
    }
44

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

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

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

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

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

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

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

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

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

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

116
        return $view;
2✔
117
    }
118

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