These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace LaravelPlus\Extension\Generators\Commands; |
||
4 | |||
5 | use Jumilla\Generators\Laravel\OneFileGeneratorCommand as BaseCommand; |
||
6 | use Jumilla\Generators\FileGenerator; |
||
7 | use LaravelPlus\Extension\Addons\Addon; |
||
8 | use LaravelPlus\Extension\Generators\GeneratorCommandTrait; |
||
9 | |||
10 | View Code Duplication | class JobMakeCommand extends BaseCommand |
|
0 ignored issues
–
show
|
|||
11 | { |
||
12 | use GeneratorCommandTrait; |
||
13 | |||
14 | /** |
||
15 | * The console command singature. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $signature = 'make:job |
||
20 | {name : The name of the class} |
||
21 | {--a|addon= : The name of the addon} |
||
22 | {--s|sync : Indicates that job should be synchronous} |
||
23 | '; |
||
24 | |||
25 | /** |
||
26 | * The console command description. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $description = '[+] Create a new job class'; |
||
31 | |||
32 | /** |
||
33 | * The type of class being generated. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $type = 'Job'; |
||
38 | |||
39 | /** |
||
40 | * The constructor. |
||
41 | */ |
||
42 | 7 | public function __construct() |
|
43 | { |
||
44 | 7 | parent::__construct(); |
|
45 | |||
46 | 7 | $this->setStubDirectory(__DIR__.'/../stubs'); |
|
47 | 7 | } |
|
48 | |||
49 | /** |
||
50 | * Get the default namespace for the class. |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | 4 | protected function getDefaultNamespace() |
|
55 | { |
||
56 | 4 | return $this->getRootNamespace().'\\Jobs'; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * Get the stub file for the generator. |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | 4 | protected function getStub() |
|
65 | { |
||
66 | 4 | return $this->option('sync') ? 'job-sync.stub' : 'job-queued.stub'; |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * Generate file. |
||
71 | * |
||
72 | * @param \Jumilla\Generators\FileGenerator $generator |
||
73 | * @param string $path |
||
74 | * @param string $fqcn |
||
75 | * |
||
76 | * @return bool |
||
77 | */ |
||
78 | 4 | protected function generateFile(FileGenerator $generator, $path, $fqcn) |
|
79 | { |
||
80 | 4 | list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); |
|
81 | |||
82 | 4 | return $generator->file($path)->template($this->getStub(), [ |
|
83 | 4 | 'namespace' => $namespace, |
|
84 | 4 | 'root_namespace' => $this->getAppNamespace(), // use App\Jobs\Job |
|
85 | 4 | 'class' => $class, |
|
86 | ]); |
||
87 | } |
||
88 | } |
||
89 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.