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

orchestral / canvas-core / 6168643703

13 Sep 2023 06:09AM UTC coverage: 71.818% (-22.4%) from 94.203%
6168643703

push

github

crynobone
Merge branch '8.x'

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

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

237 of 330 relevant lines covered (71.82%)

2.62 hits per line

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

97.22
/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
    }
14✔
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
     */
37
    public function config(?string $key = null, $default = null)
38
    {
39
        if (\is_null($key)) {
13✔
40
            return $this->config;
2✔
41
        }
42

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

188
    /**
189
     * Model namespace.
190
     */
191
    abstract public function modelNamespace(): string;
192

193
    /**
194
     * Provider namespace.
195
     */
196
    abstract public function providerNamespace(): string;
197

198
    /**
199
     * Get custom stub path.
200
     */
201
    abstract public function getCustomStubPath(): ?string;
202
}
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