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

orchestral / canvas-core / 6161733795

12 Sep 2023 03:39PM UTC coverage: 83.333%. Remained the same
6161733795

push

github

crynobone
wip

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

65 of 78 relevant lines covered (83.33%)

2.06 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\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 base working directory.
65
     */
66
    public function vendorPath(): string
67
    {
68
        return "{$this->basePath}/vendor";
2✔
69
    }
70

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

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

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

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

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

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

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

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

156
    /**
157
     * Preset name.
158
     */
159
    abstract public function name(): string;
160

161
    /**
162
     * Get the path to the base working directory.
163
     */
164
    abstract public function laravelPath(): string;
165

166
    /**
167
     * Get the path to the source directory.
168
     */
169
    abstract public function sourcePath(): string;
170

171
    /**
172
     * Preset namespace.
173
     */
174
    abstract public function rootNamespace(): string;
175

176
    /**
177
     * Model namespace.
178
     */
179
    abstract public function modelNamespace(): string;
180

181
    /**
182
     * Provider namespace.
183
     */
184
    abstract public function providerNamespace(): string;
185

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