@@ -37,18 +37,7 @@ public function generate($operation, $service, $isQueueable = false, array $jobs
3737
3838 $ content = file_get_contents ($ this ->getStub ($ isQueueable ));
3939
40- $ useJobs = '' ; // stores the `use` statements of the jobs
41- $ runJobs = '' ; // stores the `$this->run` statements of the jobs
42-
43- foreach ($ jobs as $ index => $ job ) {
44- $ useJobs .= 'use ' .$ job ['namespace ' ].'\\' .$ job ['className ' ]."; \n" ;
45- $ runJobs .= "\t\t" .'$this->run( ' .$ job ['className ' ].'::class); ' ;
46-
47- // only add carriage returns when it's not the last job
48- if ($ index != count ($ jobs ) - 1 ) {
49- $ runJobs .= "\n\n" ;
50- }
51- }
40+ list ($ useJobs , $ runJobs ) = self ::getUsesAndRunners ($ jobs );
5241
5342 $ content = str_replace (
5443 ['{{operation}} ' , '{{namespace}} ' , '{{foundation_namespace}} ' , '{{use_jobs}} ' , '{{run_jobs}} ' ],
@@ -121,4 +110,47 @@ private function getTestStub()
121110 {
122111 return __DIR__ .'/stubs/operation-test.stub ' ;
123112 }
113+
114+ /**
115+ * Get de use to import the right class
116+ * Get de job run command
117+ * @param $job
118+ * @return array
119+ * @author jgnovais <[email protected] > 120+ */
121+ static private function getUseAndJobRunCommand ($ job )
122+ {
123+ $ str = str_replace_last ('\\' ,'# ' , $ job );
124+ $ explode = explode ('# ' , $ str );
125+
126+ $ use = 'use ' .$ explode [0 ].'\\' .$ explode ['1 ' ]."; \n" ;
127+ $ runJobs = "\t\t" .'$this->run( ' .$ explode ['1 ' ].'::class); ' ;
128+
129+ return array ($ use , $ runJobs );
130+ }
131+
132+ /**
133+ * Returns all users and all $this->run() generated
134+ * @param $jobs
135+ * @return array
136+ * @author jgnovais <[email protected] > 137+ */
138+ static private function getUsesAndRunners ($ jobs )
139+ {
140+ $ useJobs = '' ;
141+ $ runJobs = '' ;
142+ foreach ($ jobs as $ index => $ job ) {
143+
144+ list ($ useLine , $ runLine ) = self ::getUseAndJobRunCommand ($ job );
145+ $ useJobs .= $ useLine ;
146+ $ runJobs .= $ runLine ;
147+ // only add carriage returns when it's not the last job
148+ if ($ index != count ($ jobs ) - 1 ) {
149+ $ runJobs .= "\n\n" ;
150+ }
151+ }
152+ return array ($ useJobs , $ runJobs );
153+ }
154+
155+
124156}
0 commit comments