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

orchestral / canvas-core / 5934171707

22 Aug 2023 03:39AM UTC coverage: 94.203% (-1.4%) from 95.588%
5934171707

push

github

crynobone
Merge branch '8.x'

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

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

65 of 69 relevant lines covered (94.2%)

2.33 hits per line

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

91.18
/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
    }
8✔
22

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

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

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

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

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

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

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

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

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

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

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

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

134
    /**
135
     * Sync commands to preset.
136
     */
137
    public function addAdditionalCommands(Application $app): void
138
    {
139
        $generators = $this->config('generators') ?? [];
×
140

141
        foreach (Arr::wrap($generators) as $generator) {
×
142
            /** @var \Symfony\Component\Console\Command\Command $generator */
143
            $app->add(new $generator($this));
×
144
        }
145
    }
146

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

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

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

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

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

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

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

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