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

orchestral / canvas-core / 6167171295

13 Sep 2023 02:17AM UTC coverage: 82.278% (-1.1%) from 83.333%
6167171295

push

github

crynobone
wip

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

1 of 1 new or added line in 1 file covered. (100.0%)

65 of 79 relevant lines covered (82.28%)

2.04 hits per line

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

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

3
namespace Orchestra\Canvas\Core\Presets;
4

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

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

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

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

44
        return Arr::get($this->config, $key, $default);
7✔
45
    }
46

47
    /**
48
     * Get the filesystem instance.
49
     */
50
    public function filesystem(): Filesystem
51
    {
52
        return $this->files;
2✔
53
    }
54

55
    /**
56
     * Get the path to the base working directory.
57
     */
58
    public function basePath(): string
59
    {
60
        return $this->basePath;
3✔
61
    }
62

63
    /**
64
     * Get the path to the testing directory.
65
     */
66
    public function testingPath(): string
67
    {
68
        return "{$this->basePath}/tests";
×
69
    }
70

71
    /**
72
     * Get the path to the vendor directory.
73
     */
74
    public function vendorPath(): string
75
    {
76
        return "{$this->basePath}/vendor";
2✔
77
    }
78

79
    /**
80
     * Get the path to the resource directory.
81
     */
82
    public function resourcePath(): string
83
    {
84
        return sprintf(
3✔
85
            '%s/%s',
3✔
86
            $this->basePath(),
3✔
87
            $this->config('paths.resource', 'resources')
3✔
88
        );
3✔
89
    }
90

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

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

115
    /**
116
     * Get the path to the seeder directory.
117
     */
118
    public function seederPath(): string
119
    {
120
        return sprintf(
3✔
121
            '%s/%s',
3✔
122
            $this->basePath(),
3✔
123
            $this->config('seeder.path', 'database/seeders')
3✔
124
        );
3✔
125
    }
126

127
    /**
128
     * Database factory namespace.
129
     */
130
    public function factoryNamespace(): string
131
    {
132
        return $this->config('factory.namespace', 'Database\Factories');
2✔
133
    }
134

135
    /**
136
     * Database seeder namespace.
137
     */
138
    public function seederNamespace(): string
139
    {
140
        return $this->config('seeder.path', 'Database\Seeders');
2✔
141
    }
142

143
    /**
144
     * Sync commands to preset.
145
     */
146
    public function addAdditionalCommands(Application $app): void
147
    {
148
        tap($this->config('generators') ?? [], function ($generators) use ($app) {
×
149
            foreach (Arr::wrap($generators) as $generator) {
×
150
                /** @var class-string<\Symfony\Component\Console\Command\Command> $generator */
151
                $app->add(new $generator($this));
×
152
            }
153
        });
×
154
    }
155

156
    /**
157
     * Preset has custom stub path.
158
     */
159
    public function hasCustomStubPath(): bool
160
    {
161
        return ! \is_null($this->getCustomStubPath());
2✔
162
    }
163

164
    /**
165
     * Preset name.
166
     */
167
    abstract public function name(): string;
168

169
    /**
170
     * Get the path to the base working directory.
171
     */
172
    abstract public function laravelPath(): string;
173

174
    /**
175
     * Get the path to the source directory.
176
     */
177
    abstract public function sourcePath(): string;
178

179
    /**
180
     * Preset namespace.
181
     */
182
    abstract public function rootNamespace(): string;
183

184
    /**
185
     * Model namespace.
186
     */
187
    abstract public function modelNamespace(): string;
188

189
    /**
190
     * Provider namespace.
191
     */
192
    abstract public function providerNamespace(): string;
193

194
    /**
195
     * Get custom stub path.
196
     */
197
    abstract public function getCustomStubPath(): ?string;
198
}
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