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

orchestral / canvas / 6182179146

14 Sep 2023 07:15AM UTC coverage: 78.922% (-11.0%) from 89.945%
6182179146

Pull #24

github

crynobone
wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Pull Request #24: Use Laravel Generator Preset

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

161 of 204 relevant lines covered (78.92%)

5.91 hits per line

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

88.57
/src/Presets/Preset.php
1
<?php
2

3
namespace Orchestra\Canvas\Presets;
4

5
use Illuminate\Support\Arr;
6
use Symfony\Component\Console\Application;
7

8
abstract class Preset
9
{
10
    /**
11
     * Construct a new preset.
12
     *
13
     * @param  array<string, mixed>  $config
14
     */
15
    public function __construct(
16
        protected array $config,
17
        protected string $basePath
18
    ) {
19
        //
20
    }
30✔
21

22
    /**
23
     * Check if preset name equal to $name.
24
     */
25
    public function is(string $name): bool
26
    {
27
        return $this->name() === $name;
9✔
28
    }
29

30
    /**
31
     * Get configuration.
32
     *
33
     * @param  mixed|null  $default
34
     */
35
    public function config(?string $key = null, $default = null): mixed
36
    {
37
        if (\is_null($key)) {
29✔
38
            return $this->config;
4✔
39
        }
40

41
        return Arr::get($this->config, $key, $default);
27✔
42
    }
43

44
    /**
45
     * Get the path to the base working directory.
46
     */
47
    public function basePath(): string
48
    {
49
        return $this->basePath;
12✔
50
    }
51

52
    /**
53
     * Get the path to the testing directory.
54
     */
55
    public function testingPath(): string
56
    {
57
        return "{$this->basePath}/tests";
12✔
58
    }
59

60
    /**
61
     * Get the path to the vendor directory.
62
     */
63
    public function vendorPath(): string
64
    {
65
        return "{$this->basePath}/vendor";
2✔
66
    }
67

68
    /**
69
     * Get the path to the resource directory.
70
     */
71
    public function resourcePath(): string
72
    {
73
        return sprintf(
4✔
74
            '%s/%s',
4✔
75
            $this->basePath(),
4✔
76
            $this->config('paths.resource', 'resources')
4✔
77
        );
4✔
78
    }
79

80
    /**
81
     * Get the path to the factory directory.
82
     */
83
    public function factoryPath(): string
84
    {
85
        return sprintf(
6✔
86
            '%s/%s',
6✔
87
            $this->basePath(),
6✔
88
            $this->config('factory.path', 'database/factories')
6✔
89
        );
6✔
90
    }
91

92
    /**
93
     * Get the path to the migration directory.
94
     */
95
    public function migrationPath(): string
96
    {
97
        return sprintf(
2✔
98
            '%s/%s',
2✔
99
            $this->basePath(),
2✔
100
            $this->config('migration.path', 'database/migrations')
2✔
101
        );
2✔
102
    }
103

104
    /**
105
     * Get the path to the seeder directory.
106
     */
107
    public function seederPath(): string
108
    {
109
        return sprintf(
2✔
110
            '%s/%s',
2✔
111
            $this->basePath(),
2✔
112
            $this->config('seeder.path', 'database/seeders')
2✔
113
        );
2✔
114
    }
115

116
    /**
117
     * Database factory namespace.
118
     */
119
    public function factoryNamespace(): string
120
    {
121
        return $this->config('factory.namespace', 'Database\Factories');
6✔
122
    }
123

124
    /**
125
     * Database seeder namespace.
126
     */
127
    public function seederNamespace(): string
128
    {
129
        return $this->config('seeder.path', 'Database\Seeders');
2✔
130
    }
131

132
    /**
133
     * Sync commands to preset.
134
     */
135
    public function addAdditionalCommands(Application $app): void
136
    {
137
        tap($this->config('generators') ?? [], function ($generators) use ($app) {
×
138
            foreach (Arr::wrap($generators) as $generator) {
×
139
                /** @var class-string<\Symfony\Component\Console\Command\Command> $generator */
140
                $app->add(new $generator($this));
×
141
            }
142
        });
×
143
    }
144

145
    /**
146
     * Preset has custom stub path.
147
     */
148
    public function hasCustomStubPath(): bool
149
    {
150
        return ! \is_null($this->getCustomStubPath());
2✔
151
    }
152

153
    /**
154
     * Preset name.
155
     */
156
    abstract public function name(): string;
157

158
    /**
159
     * Get the path to the source directory.
160
     */
161
    abstract public function sourcePath(): string;
162

163
    /**
164
     * Preset namespace.
165
     */
166
    abstract public function rootNamespace(): string;
167

168
    /**
169
     * Command namespace.
170
     */
171
    abstract public function commandNamespace(): string;
172

173
    /**
174
     * Model namespace.
175
     */
176
    abstract public function modelNamespace(): string;
177

178
    /**
179
     * Provider namespace.
180
     */
181
    abstract public function providerNamespace(): string;
182

183
    /**
184
     * Testing namespace.
185
     */
186
    abstract public function testingNamespace(): string;
187

188
    /**
189
     * Get custom stub path.
190
     */
191
    abstract public function getCustomStubPath(): ?string;
192
}
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