@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @param null|string $name |
| 69 | 69 | * @param null|object $fileSystem |
| 70 | 70 | */ |
| 71 | - public function __construct($path=null,$name=null,$fileSystem=null) |
|
| 71 | + public function __construct($path = null, $name = null, $fileSystem = null) |
|
| 72 | 72 | { |
| 73 | 73 | $this->path = $path; |
| 74 | 74 | |
@@ -93,14 +93,14 @@ discard block |
||
| 93 | 93 | * |
| 94 | 94 | * @throws FileNotFoundException |
| 95 | 95 | */ |
| 96 | - public function createClass($replacement=array()) |
|
| 96 | + public function createClass($replacement = array()) |
|
| 97 | 97 | { |
| 98 | - if(file_exists($this->path)){ |
|
| 98 | + if (file_exists($this->path)) { |
|
| 99 | 99 | |
| 100 | 100 | $content = $this->fileSystem->get($this->getStubFile()); |
| 101 | 101 | |
| 102 | - if($this->fileSystem->put($this->file,$content)!==FALSE){ |
|
| 103 | - $this->replaceFileContent($replacement,$this->file); |
|
| 102 | + if ($this->fileSystem->put($this->file, $content)!==FALSE) { |
|
| 103 | + $this->replaceFileContent($replacement, $this->file); |
|
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | |
@@ -115,23 +115,23 @@ discard block |
||
| 115 | 115 | * |
| 116 | 116 | * @throws FileNotFoundException |
| 117 | 117 | */ |
| 118 | - public function createClassProperty($properties=array(),$loadedMethod=false) |
|
| 118 | + public function createClassProperty($properties = array(), $loadedMethod = false) |
|
| 119 | 119 | { |
| 120 | - if(is_null($this->classProperties)){ |
|
| 120 | + if (is_null($this->classProperties)) { |
|
| 121 | 121 | $this->classProperties = $properties; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - if($loadedMethod){ |
|
| 124 | + if ($loadedMethod) { |
|
| 125 | 125 | |
| 126 | 126 | foreach ($this->classProperties as $property) { |
| 127 | 127 | |
| 128 | - if(preg_match('@class\s.*\n{@',$this->fileSystem->get($this->file),$parse)){ |
|
| 128 | + if (preg_match('@class\s.*\n{@', $this->fileSystem->get($this->file), $parse)) { |
|
| 129 | 129 | $this->replaceFileContent([ |
| 130 | 130 | $parse[0] => $parse[0].' |
| 131 | 131 | '.$property.' |
| 132 | 132 | ' |
| 133 | 133 | |
| 134 | - ],$this->file,true); |
|
| 134 | + ], $this->file, true); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | |
@@ -146,11 +146,11 @@ discard block |
||
| 146 | 146 | * |
| 147 | 147 | * @throws FileNotFoundException |
| 148 | 148 | */ |
| 149 | - public function createMethod($methods=array()) |
|
| 149 | + public function createMethod($methods = array()) |
|
| 150 | 150 | { |
| 151 | 151 | $list = []; |
| 152 | 152 | |
| 153 | - foreach ($methods as $method){ |
|
| 153 | + foreach ($methods as $method) { |
|
| 154 | 154 | |
| 155 | 155 | $list[] = ' |
| 156 | 156 | '.$this->getAccessibleMethodValue($method).' function '.$method.'('.$this->getMethodParameters($method).') |
@@ -159,12 +159,12 @@ discard block |
||
| 159 | 159 | } |
| 160 | 160 | '; |
| 161 | 161 | } |
| 162 | - if(preg_match('@class\s.*\n{@',$this->fileSystem->get($this->file),$parse)){ |
|
| 162 | + if (preg_match('@class\s.*\n{@', $this->fileSystem->get($this->file), $parse)) { |
|
| 163 | 163 | $this->replaceFileContent([ |
| 164 | - $parse[0] => $parse[0].' '.implode('',$list) |
|
| 165 | - ],$this->file,true); |
|
| 164 | + $parse[0] => $parse[0].' '.implode('', $list) |
|
| 165 | + ], $this->file, true); |
|
| 166 | 166 | |
| 167 | - $this->createClassProperty([],true); |
|
| 167 | + $this->createClassProperty([], true); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | } |
@@ -175,9 +175,9 @@ discard block |
||
| 175 | 175 | * @param array $methods |
| 176 | 176 | * @return void|mixed |
| 177 | 177 | */ |
| 178 | - public function createMethodAccessibleProperty($methods=array()) |
|
| 178 | + public function createMethodAccessibleProperty($methods = array()) |
|
| 179 | 179 | { |
| 180 | - foreach($methods as $method=>$accessibleValue) |
|
| 180 | + foreach ($methods as $method=>$accessibleValue) |
|
| 181 | 181 | { |
| 182 | 182 | $this->accessibleProperties[$method] = $accessibleValue; |
| 183 | 183 | |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | 'public function '.$method.'' => ''.$this->getAccessibleMethodValue($method).' function '.$method.'' |
| 187 | 187 | |
| 188 | - ],$this->file,true); |
|
| 188 | + ], $this->file, true); |
|
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | |
@@ -194,16 +194,16 @@ discard block |
||
| 194 | 194 | * |
| 195 | 195 | * @param array $methods |
| 196 | 196 | */ |
| 197 | - public function createMethodBody($methods=array()) |
|
| 197 | + public function createMethodBody($methods = array()) |
|
| 198 | 198 | { |
| 199 | - foreach ($methods as $method=>$body){ |
|
| 199 | + foreach ($methods as $method=>$body) { |
|
| 200 | 200 | |
| 201 | 201 | $this->replaceFileContent([ |
| 202 | 202 | ''.$this->getAccessibleMethodValue($method).' function '.$method.'\('.$this->getMethodParameters($method).'\)\n.*{\n.*\n.*}' => ''.$this->getAccessibleMethodValue($method).' function '.$method.'('.$this->getMethodParameters($method).') |
| 203 | 203 | { |
| 204 | 204 | '.$body.' |
| 205 | 205 | }' |
| 206 | - ],$this->file,true); |
|
| 206 | + ], $this->file, true); |
|
| 207 | 207 | } |
| 208 | 208 | } |
| 209 | 209 | |
@@ -212,14 +212,14 @@ discard block |
||
| 212 | 212 | * |
| 213 | 213 | * @param array $methods |
| 214 | 214 | */ |
| 215 | - public function createMethodDocument($methods=array()) |
|
| 215 | + public function createMethodDocument($methods = array()) |
|
| 216 | 216 | { |
| 217 | - foreach ($methods as $method=>$documents){ |
|
| 217 | + foreach ($methods as $method=>$documents) { |
|
| 218 | 218 | |
| 219 | 219 | $documentString = []; |
| 220 | 220 | $documentString[] = '/**'; |
| 221 | 221 | |
| 222 | - foreach ($documents as $document){ |
|
| 222 | + foreach ($documents as $document) { |
|
| 223 | 223 | $documentString[] = ' |
| 224 | 224 | * '.$document.''; |
| 225 | 225 | } |
@@ -228,9 +228,9 @@ discard block |
||
| 228 | 228 | */'; |
| 229 | 229 | |
| 230 | 230 | $this->replaceFileContent([ |
| 231 | - ''.$this->getAccessibleMethodValue($method).' function '.$method.'\('.$this->getMethodParameters($method).'\)' => ''.implode('',$documentString).' |
|
| 231 | + ''.$this->getAccessibleMethodValue($method).' function '.$method.'\('.$this->getMethodParameters($method).'\)' => ''.implode('', $documentString).' |
|
| 232 | 232 | '.$this->getAccessibleMethodValue($method).' function '.$method.'('.$this->getMethodParameters($method).')' |
| 233 | - ],$this->file,true); |
|
| 233 | + ], $this->file, true); |
|
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | 236 | |
@@ -240,9 +240,9 @@ discard block |
||
| 240 | 240 | * @param array $methods |
| 241 | 241 | * @return void|mixed |
| 242 | 242 | */ |
| 243 | - public function createMethodParameters($methods=array()) |
|
| 243 | + public function createMethodParameters($methods = array()) |
|
| 244 | 244 | { |
| 245 | - foreach($methods as $method=>$parameter) |
|
| 245 | + foreach ($methods as $method=>$parameter) |
|
| 246 | 246 | { |
| 247 | 247 | $this->methodParameters[$method] = $parameter; |
| 248 | 248 | |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | |
| 251 | 251 | ''.$this->getAccessibleMethodValue($method).' function '.$method.'\(\)' => ''.$this->getAccessibleMethodValue($method).' function '.$method.'('.$parameter.')' |
| 252 | 252 | |
| 253 | - ],$this->file,true); |
|
| 253 | + ], $this->file, true); |
|
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | |
@@ -261,8 +261,8 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | public function createPath() |
| 263 | 263 | { |
| 264 | - if(!file_exists($this->path)){ |
|
| 265 | - if(!$this->fileSystem->makeDirectory($this->path)){ |
|
| 264 | + if (!file_exists($this->path)) { |
|
| 265 | + if (!$this->fileSystem->makeDirectory($this->path)) { |
|
| 266 | 266 | throw new \Error($this->path.' makeDirectory fail'); |
| 267 | 267 | } |
| 268 | 268 | } |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | private function getMethodParameters($method) |
| 291 | 291 | { |
| 292 | 292 | return (isset($this->methodParameters[$method])) ? |
| 293 | - str_replace('$','\$',$this->methodParameters[$method]) |
|
| 293 | + str_replace('$', '\$', $this->methodParameters[$method]) |
|
| 294 | 294 | : ''; |
| 295 | 295 | } |
| 296 | 296 | |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | { |
| 304 | 304 | $stubFile = $this->stubPath.''.DIRECTORY_SEPARATOR.''.$this->type.'.stub'; |
| 305 | 305 | |
| 306 | - if(!file_exists($stubFile)){ |
|
| 306 | + if (!file_exists($stubFile)) { |
|
| 307 | 307 | throw new \Error($stubFile.' path is not available'); |
| 308 | 308 | } |
| 309 | 309 | |
@@ -318,24 +318,24 @@ discard block |
||
| 318 | 318 | * @param bool $default |
| 319 | 319 | * @return void |
| 320 | 320 | */ |
| 321 | - private function replaceFileContent($replacement,$file,$default=false) |
|
| 321 | + private function replaceFileContent($replacement, $file, $default = false) |
|
| 322 | 322 | { |
| 323 | 323 | $replacementVariables = ($default) ? $replacement : $this->replacementVariables($replacement); |
| 324 | 324 | $content = $this->fileSystem->get($file); |
| 325 | 325 | |
| 326 | - foreach ($replacementVariables as $key=>$replacementVariable){ |
|
| 326 | + foreach ($replacementVariables as $key=>$replacementVariable) { |
|
| 327 | 327 | |
| 328 | - if($default){ |
|
| 328 | + if ($default) { |
|
| 329 | 329 | $search = '/'.$key.'/'; |
| 330 | 330 | } |
| 331 | - else{ |
|
| 331 | + else { |
|
| 332 | 332 | $search = '/__'.$key.'__/'; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | $replace = $replacementVariable; |
| 336 | - $content = preg_replace($search,$replace,$content); |
|
| 336 | + $content = preg_replace($search, $replace, $content); |
|
| 337 | 337 | } |
| 338 | - $this->fileSystem->replace($file,$content); |
|
| 338 | + $this->fileSystem->replace($file, $content); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /** |
@@ -344,12 +344,12 @@ discard block |
||
| 344 | 344 | * @param array $replacement |
| 345 | 345 | * @return array |
| 346 | 346 | */ |
| 347 | - private function replacementVariables($replacement=array()) |
|
| 347 | + private function replacementVariables($replacement = array()) |
|
| 348 | 348 | { |
| 349 | 349 | $replacement['namespace'] = $this->namespace; |
| 350 | 350 | $replacement['class'] = $this->name; |
| 351 | 351 | |
| 352 | - return array_map(function($item){ |
|
| 352 | + return array_map(function($item) { |
|
| 353 | 353 | return ucfirst($item); |
| 354 | 354 | },$replacement); |
| 355 | 355 | } |
@@ -359,12 +359,12 @@ discard block |
||
| 359 | 359 | * |
| 360 | 360 | * @param $stubPath |
| 361 | 361 | */ |
| 362 | - public function setStubPath($stubPath=null) |
|
| 362 | + public function setStubPath($stubPath = null) |
|
| 363 | 363 | { |
| 364 | - if(is_null($stubPath)){ |
|
| 364 | + if (is_null($stubPath)) { |
|
| 365 | 365 | $this->stubPath = app()->corePath().'Console/Stubs/generator'; |
| 366 | 366 | } |
| 367 | - else{ |
|
| 367 | + else { |
|
| 368 | 368 | $this->stubPath = $stubPath; |
| 369 | 369 | } |
| 370 | 370 | } |
@@ -327,8 +327,7 @@ discard block |
||
| 327 | 327 | |
| 328 | 328 | if($default){ |
| 329 | 329 | $search = '/'.$key.'/'; |
| 330 | - } |
|
| 331 | - else{ |
|
| 330 | + } else{ |
|
| 332 | 331 | $search = '/__'.$key.'__/'; |
| 333 | 332 | } |
| 334 | 333 | |
@@ -363,8 +362,7 @@ discard block |
||
| 363 | 362 | { |
| 364 | 363 | if(is_null($stubPath)){ |
| 365 | 364 | $this->stubPath = app()->corePath().'Console/Stubs/generator'; |
| 366 | - } |
|
| 367 | - else{ |
|
| 365 | + } else{ |
|
| 368 | 366 | $this->stubPath = $stubPath; |
| 369 | 367 | } |
| 370 | 368 | } |