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

orchestral / canvas-core / 5926050279

21 Aug 2023 12:12PM UTC coverage: 93.939% (-1.4%) from 95.385%
5926050279

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%)

62 of 66 relevant lines covered (93.94%)

2.38 hits per line

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

90.91
/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";
×
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
        foreach ($this->config('generators', []) as $generator) {
×
140
            /** @var \Symfony\Component\Console\Command\Command $generator */
141
            $app->add(new $generator($this));
×
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
     * Model namespace.
170
     */
171
    abstract public function modelNamespace(): string;
172

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

178
    /**
179
     * Get custom stub path.
180
     */
181
    abstract public function getCustomStubPath(): ?string;
182
}
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