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

orchestral / canvas-core / 19317827659

13 Nov 2025 01:49AM UTC coverage: 92.742% (-0.8%) from 93.496%
19317827659

push

github

crynobone
Fix `Orchestra\Canvas\Core\Commands\GeneratorCommand`

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

115 of 124 relevant lines covered (92.74%)

3.15 hits per line

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

88.89
/src/Concerns/UsesGeneratorOverrides.php
1
<?php
2

3
namespace Orchestra\Canvas\Core\Concerns;
4

5
use Illuminate\Support\Str;
6
use Orchestra\Canvas\Core\Presets\Preset;
7
use Symfony\Component\Finder\Finder;
8

9
use function Illuminate\Filesystem\join_paths;
10

11
trait UsesGeneratorOverrides
12
{
13
    /**
14
     * Qualify the given model class base name.
15
     */
16
    protected function qualifyModelUsingCanvas(string $model): string
17
    {
18
        $model = ltrim($model, '\\/');
1✔
19

20
        $model = str_replace('/', '\\', $model);
1✔
21

22
        if (str_starts_with($model, $this->rootNamespace())) {
1✔
23
            return $model;
×
24
        }
25

26
        return $this->generatorPreset()->modelNamespace().$model;
1✔
27
    }
28

29
    /**
30
     * Get the destination class path.
31
     */
32
    protected function getPathUsingCanvas(string $name): string
33
    {
34
        $name = Str::replaceFirst($this->rootNamespace(), '', $name);
6✔
35

36
        return join_paths($this->getGeneratorSourcePath(), str_replace('\\', '/', $name).'.php');
6✔
37
    }
38

39
    /**
40
     * Get the root namespace for the class.
41
     */
42
    protected function rootNamespaceUsingCanvas(): string
43
    {
44
        return $this->generatorPreset()->rootNamespace();
7✔
45
    }
46

47
    /**
48
     * Get the model for the default guard's user provider.
49
     */
50
    protected function userProviderModelUsingCanvas(?string $guard = null): ?string
51
    {
52
        return $this->generatorPreset()->userProviderModel($guard);
4✔
53
    }
54

55
    /**
56
     * Get the first view directory path from the application configuration.
57
     */
58
    protected function viewPathUsingCanvas(string $path = ''): string
59
    {
60
        $views = $this->generatorPreset()->viewPath();
1✔
61

62
        return join_paths($views, $path);
1✔
63
    }
64

65
    /**
66
     * Get a list of possible model names.
67
     *
68
     * @return array<int, string>
69
     */
70
    protected function findAvailableModelsUsingCanvas(): array
71
    {
72
        $sourcePath = $this->generatorPreset()->sourcePath();
1✔
73

74
        $modelPath = is_dir(join_paths($sourcePath, 'Models')) ? join_paths($sourcePath, 'Models') : $sourcePath;
1✔
75

76
        return collect((new Finder)->files()->depth(0)->in($modelPath))
1✔
77
            ->map(fn ($file) => $file->getBasename('.php'))
1✔
78
            ->sort()
1✔
79
            ->values()
1✔
80
            ->all();
1✔
81
    }
82

83
    /**
84
     * Get a list of possible model names.
85
     * 
86
     * @return array<int, string>
87
     * 
88
     * @deprecated 10.1.0 Use `findAvailableModelsUsingCanvas()` instead.
89
     */
90
    #[\Deprecated('Use `findAvailableModelsUsingCanvas()` instead.', since: '10.1.0')]
91
    protected function possibleModelsUsingCanvas(): array
92
    {
93
        return $this->findAvailableModelsUsingCanvas();
×
94
    }
95

96
    /**
97
     * Get a list of possible event names.
98
     *
99
     * @return array<int, string>
100
     */
101
    protected function possibleEventsUsingCanvas(): array
102
    {
103
        $eventPath = join_paths($this->generatorPreset()->sourcePath(), 'Events');
1✔
104

105
        if (! is_dir($eventPath)) {
1✔
106
            return [];
×
107
        }
108

109
        return collect((new Finder)->files()->depth(0)->in($eventPath))
1✔
110
            ->map(fn ($file) => $file->getBasename('.php'))
1✔
111
            ->sort()
1✔
112
            ->values()
1✔
113
            ->all();
1✔
114
    }
115

116
    /**
117
     * Get the root namespace for the class.
118
     *
119
     * @return string
120
     */
121
    abstract protected function rootNamespace();
122

123
    /**
124
     * Resolve the generator preset.
125
     */
126
    abstract protected function generatorPreset(): Preset;
127
}
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