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

orchestral / canvas-core / 22725516755

05 Mar 2026 03:39PM UTC coverage: 92.857% (-0.6%) from 93.496%
22725516755

push

github

crynobone
Merge branch '10.x' into 11.x

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

54 of 59 new or added lines in 5 files covered. (91.53%)

169 of 182 relevant lines covered (92.86%)

2.82 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
    protected function possibleModelsUsingCanvas(): array
91
    {
NEW
92
        return $this->findAvailableModelsUsingCanvas();
×
93
    }
94

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

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

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

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

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