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

orchestral / canvas / 3848713348

pending completion
3848713348

push

github

Mior Muhammad Zaki
Merge branch '7.x'

772 of 799 relevant lines covered (96.62%)

19.07 hits per line

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

68.18
/src/Database/MigrationCreator.php
1
<?php
2

3
namespace Orchestra\Canvas\Database;
4

5
use Illuminate\Support\Str;
6
use InvalidArgumentException;
7
use Orchestra\Canvas\Concerns\ResolvesPresetStubs;
8
use Orchestra\Canvas\Core\Presets\Laravel;
9
use Orchestra\Canvas\Core\Presets\Preset;
10

11
class MigrationCreator extends \Illuminate\Database\Migrations\MigrationCreator
12
{
13
    use ResolvesPresetStubs;
14

15
    /**
16
     * Canvas preset.
17
     *
18
     * @var \Orchestra\Canvas\Core\Presets\Preset
19
     */
20
    protected $preset;
21

22
    /**
23
     * Create a new migration creator instance.
24
     */
25
    public function __construct(Preset $preset)
26
    {
27
        $this->files = $preset->filesystem();
84✔
28
        $this->preset = $preset;
84✔
29
        $this->customStubPath = sprintf('%s/stubs', $this->preset->basePath());
84✔
30
    }
31

32
    /**
33
     * Create a new migration at the given path.
34
     *
35
     * @param  string  $name
36
     * @param  string  $path
37
     * @param  string|null  $table
38
     * @param  bool  $create
39
     * @return string
40
     *
41
     * @throws \Exception
42
     */
43
    public function create($name, $path, $table = null, $create = false)
44
    {
45
        $name = trim(implode('_', [Str::slug($this->preset->config('migration.prefix', ''), '_'), $name]), '_');
7✔
46

47
        if (! $this->files->isDirectory($path)) {
7✔
48
            if ($this->preset instanceof Laravel) {
1✔
49
                throw new InvalidArgumentException("Path {$path} doesn't exists.");
1✔
50
            }
51

52
            $this->files->makeDirectory($path, 0755, true, true);
×
53
        }
54

55
        return parent::create($name, $path, $table, $create);
6✔
56
    }
57

58
    /**
59
     * Get the migration stub file.
60
     *
61
     * @param  string|null  $table
62
     * @param  bool  $create
63
     * @return string
64
     */
65
    protected function getStub($table, $create)
66
    {
67
        if (\is_null($table)) {
6✔
68
            $stub = $this->files->exists($customPath = $this->customStubPath.'/migration.stub')
×
69
                ? $customPath
×
70
                : $this->getStubFileFromPresetStorage($this->preset, 'migration.stub');
×
71
        } elseif ($create) {
6✔
72
            $stub = $this->files->exists($customPath = $this->customStubPath.'/migration.create.stub')
4✔
73
                ? $customPath
×
74
                : $this->getStubFileFromPresetStorage($this->preset, 'migration.create.stub');
4✔
75
        } else {
76
            $stub = $this->files->exists($customPath = $this->customStubPath.'/migration.update.stub')
2✔
77
                ? $customPath
×
78
                : $this->getStubFileFromPresetStorage($this->preset, 'migration.update.stub');
2✔
79
        }
80

81
        return $this->files->get($stub);
6✔
82
    }
83

84
    /**
85
     * Get the path to the stubs.
86
     *
87
     * @return string
88
     */
89
    public function stubPath()
90
    {
91
        return '';
×
92
    }
93
}
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