@@ -21,7 +21,7 @@ class MakeService extends GeneratorCommand
2121 *
2222 * @var string
2323 */
24- protected $ signature = 'make:service {name : Create a service class} {--c : Create a service contract } ' ;
24+ protected $ signature = 'make:service {name : Create a service class} {--i : Create a service interface } ' ;
2525
2626 /**
2727 * The console command description.
@@ -42,21 +42,24 @@ protected function getStub()
4242 }
4343
4444 /**
45- * @param bool $isContract
4645 * @return string
4746 */
48- protected function getServiceStub (bool $ isContract ): string
47+ protected function getServiceStub (): string
4948 {
50- return self ::STUB_PATH .
51- ($ isContract ? 'service.stub ' : 'service.origin.stub ' );
49+ return self ::STUB_PATH . 'service.stub ' ;
50+ }
51+
52+ protected function getInterfaceStub (): string
53+ {
54+ return self ::STUB_PATH . 'interface.stub ' ;
5255 }
5356
5457 /**
5558 * @return string
5659 */
57- protected function getServiceContractStub (): string
60+ protected function getServiceInterfaceStub (): string
5861 {
59- return self ::STUB_PATH . 'service.contract .stub ' ;
62+ return self ::STUB_PATH . 'service.interface .stub ' ;
6063 }
6164
6265 /**
@@ -89,31 +92,31 @@ public function handle()
8992 }
9093
9194 $ this ->makeDirectory ($ path );
92- $ isContract = $ this ->option ('c ' );
95+ $ isInterface = $ this ->option ('i ' );
9396
9497 $ this ->files ->put (
9598 $ path ,
9699 $ this ->sortImports (
97- $ this ->buildServiceClass ($ name , $ isContract )
100+ $ this ->buildServiceClass ($ name , $ isInterface )
98101 )
99102 );
100103 $ message = $ this ->type ;
101104
102105 // Whether to create contract
103- if ($ isContract ) {
104- $ contractName = $ this ->getNameInput () . 'Contract .php ' ;
105- $ contractPath = str_replace ($ this ->getNameInput () . '.php ' , 'Contracts / ' , $ path );
106+ if ($ isInterface ) {
107+ $ interfaceName = $ this ->getNameInput () . 'Interface .php ' ;
108+ $ interfacePath = str_replace ($ this ->getNameInput () . '.php ' , 'Interfaces / ' , $ path );
106109
107- $ this ->makeDirectory ($ contractPath . $ contractName );
110+ $ this ->makeDirectory ($ interfacePath . $ interfaceName );
108111
109112 $ this ->files ->put (
110- $ contractPath . $ contractName ,
113+ $ interfacePath . $ interfaceName ,
111114 $ this ->sortImports (
112- $ this ->buildServiceContractInterface ($ this ->getNameInput ())
115+ $ this ->buildServiceInterface ($ this ->getNameInput ())
113116 )
114117 );
115118
116- $ message .= ' and Contract ' ;
119+ $ message .= ' and Interface ' ;
117120 }
118121
119122 $ this ->info ($ message . ' created successfully. ' );
@@ -123,14 +126,16 @@ public function handle()
123126 * Build the class with the given name.
124127 *
125128 * @param string $name
126- * @param $isContract
129+ * @param $isInterface
127130 * @return string
128131 *
129132 * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
130133 */
131- protected function buildServiceClass ($ name , $ isContract ): string
134+ protected function buildServiceClass (string $ name , $ isInterface ): string
132135 {
133- $ stub = $ this ->files ->get ($ this ->getServiceStub ($ isContract ));
136+ $ stub = $ this ->files ->get (
137+ $ isInterface ? $ this ->getServiceInterfaceStub () : $ this ->getServiceStub ()
138+ );
134139
135140 return $ this ->replaceNamespace ($ stub , $ name )->replaceClass ($ stub , $ name );
136141 }
@@ -143,9 +148,9 @@ protected function buildServiceClass($name, $isContract): string
143148 *
144149 * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
145150 */
146- protected function buildServiceContractInterface ( $ name ): string
151+ protected function buildServiceInterface ( string $ name ): string
147152 {
148- $ stub = $ this ->files ->get ($ this ->getServiceContractStub ());
153+ $ stub = $ this ->files ->get ($ this ->getInterfaceStub ());
149154
150155 return $ this ->replaceNamespace ($ stub , $ name )->replaceClass ($ stub , $ name );
151156 }
0 commit comments