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

orchestral / canvas / 6222385879

18 Sep 2023 12:18PM UTC coverage: 85.938% (-7.9%) from 93.885%
6222385879

Pull #25

github

crynobone
wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Pull Request #25: Use `Illuminate\Console\GeneratorCommand`

555 of 555 new or added lines in 33 files covered. (100.0%)

495 of 576 relevant lines covered (85.94%)

23.85 hits per line

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

0.0
/src/Console/PresetMakeCommand.php
1
<?php
2

3
namespace Orchestra\Canvas\Console;
4

5
use Illuminate\Support\Str;
6
use Orchestra\Canvas\Core\Commands\GeneratorCommand;
7
use Orchestra\Canvas\Core\Concerns\ResolvesPresetStubs;
8
use Symfony\Component\Console\Attribute\AsCommand;
9
use Symfony\Component\Console\Input\InputOption;
10

11
#[AsCommand(name: 'preset', description: 'Create canvas.yaml for the project')]
12
class PresetMakeCommand extends GeneratorCommand
13
{
14
    use ResolvesPresetStubs;
15

16
    /**
17
     * The type of class being generated.
18
     *
19
     * @var string
20
     */
21
    protected $type = 'Preset';
22

23
    /**
24
     * Get the stub file for the generator.
25
     *
26
     * @return string
27
     */
28
    protected function getStub()
29
    {
30
        $name = Str::lower($this->getNameInput());
×
31

32
        $stub = __DIR__.'/stubs/preset';
×
33

34
        return $this->files->exists("{$stub}.{$name}.stub")
×
35
            ? "{$stub}.{$name}.stub"
×
36
            : "{$stub}.laravel.stub";
×
37
    }
38

39
    /**
40
     * Get the destination class path.
41
     *
42
     * @param  string  $name
43
     * @return string
44
     */
45
    protected function getPath($name)
46
    {
47
        return $this->generatorPreset()->basePath().'/canvas.yaml';
×
48
    }
49

50
    /**
51
     * Get the root namespace for the class.
52
     */
53
    protected function rootNamespace(): string
54
    {
55
        $namespace = transform($this->option('namespace'), function (string $namespace) {
×
56
            return trim($namespace);
×
57
        });
×
58

59
        if (! empty($namespace)) {
×
60
            return $namespace;
×
61
        }
62

63
        switch ($this->option('name')) {
×
64
            case 'package':
×
65
                return 'PackageName';
×
66
            case 'laravel':
×
67
            default:
68
                return rtrim($this->laravel->getNamespace(), '\\');
×
69
        }
70
    }
71

72
    /**
73
     * Get the console command options.
74
     *
75
     * @return array<int, array>
76
     */
77
    protected function getOptions()
78
    {
79
        return [
×
80
            ['namespace', null, InputOption::VALUE_OPTIONAL, 'Root namespace'],
×
81
        ];
×
82
    }
83
}
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