@@ -90,11 +90,29 @@ public function __construct()
9090 $ this ->paths = config ('entity-generator.paths ' );
9191 }
9292
93- protected function getOrCreateNamespace (string $ configPath , ?string $ subFolder = null ): string
93+ protected function getNamespace (string $ configPath , ?string $ subFolder = null ): string
9494 {
95- $ path = when ($ subFolder , fn () => Str::finish ($ this ->paths [$ configPath ], '/ ' ) . $ subFolder , $ this ->paths [$ configPath ]);
96-
97- $ pathParts = explode ('/ ' , $ path );
95+ $ pathParts = $ this ->getNamespacePathParts ($ configPath , $ subFolder );
96+
97+ $ namespace = array_map (fn (string $ part ) => ucfirst ($ part ), $ pathParts );
98+
99+ return implode ('\\' , $ namespace );
100+ }
101+
102+ protected function createNamespace (string $ configPath , ?string $ subFolder = null ): void
103+ {
104+ $ path = $ this ->getPath ($ configPath , $ subFolder );
105+
106+ $ fullPath = base_path ($ path );
107+
108+ if (!file_exists ($ fullPath )) {
109+ mkdir ($ fullPath , 0777 , true );
110+ }
111+ }
112+
113+ protected function getNamespacePathParts (string $ configPath , ?string $ subFolder = null ): array
114+ {
115+ $ pathParts = explode ('/ ' , $ this ->getPath ($ configPath , $ subFolder ));
98116
99117 if (Str::endsWith (Arr::last ($ pathParts ), '.php ' )) {
100118 array_pop ($ pathParts );
@@ -106,17 +124,12 @@ protected function getOrCreateNamespace(string $configPath, ?string $subFolder =
106124 }
107125 }
108126
109- $ namespace = array_map (function (string $ part ) {
110- return ucfirst ($ part );
111- }, $ pathParts );
112-
113- $ fullPath = base_path ($ path );
114-
115- if (!file_exists ($ fullPath )) {
116- mkdir ($ fullPath , 0777 , true );
117- }
127+ return $ pathParts ;
128+ }
118129
119- return implode ('\\' , $ namespace );
130+ protected function getPath (string $ configPath , ?string $ subFolder = null ): string
131+ {
132+ return when ($ subFolder , fn () => Str::finish ($ this ->paths [$ configPath ], '/ ' ) . $ subFolder , $ this ->paths [$ configPath ]);
120133 }
121134
122135 protected function isFolderHasCorrectCase (string $ folder , string $ configPath ): bool
@@ -239,7 +252,7 @@ protected function getRelatedModels(string $model, string $creatableClass): arra
239252 protected function generateRelativePath (string $ namespace , string $ basePath ): string
240253 {
241254 return Str::after (
242- subject: $ this ->namespaceToPath ($ namespace ),
255+ subject: $ this ->namespaceToPath ($ namespace ),
243256 search: $ this ->namespaceToPath ($ basePath ) . '/ ' ,
244257 );
245258 }
@@ -253,7 +266,7 @@ protected function getModelClass(string $model): string
253266 {
254267 $ subfolder = when ($ model === $ this ->model , $ this ->modelSubFolder );
255268
256- $ modelNamespace = $ this ->getOrCreateNamespace ('models ' , $ subfolder );
269+ $ modelNamespace = $ this ->getNamespace ('models ' , $ subfolder );
257270
258271 return "{$ modelNamespace }\\{$ model }" ;
259272 }
0 commit comments