These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of Laravel Paket. |
||
5 | * |
||
6 | * (c) Anton Komarev <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | declare(strict_types=1); |
||
13 | |||
14 | namespace Cog\Laravel\Paket\Requirement\Jobs; |
||
15 | |||
16 | use Cog\Contracts\Paket\Job\Entities\Job as JobContract; |
||
17 | use Cog\Contracts\Paket\Job\Exceptions\JobFailed; |
||
18 | use Cog\Contracts\Paket\Job\Repositories\Job as JobRepositoryContract; |
||
19 | use Cog\Contracts\Paket\Requirement\Entities\Requirement as RequirementContract; |
||
20 | use Cog\Laravel\Paket\Requirement\Events\RequirementHasBeenInstalled; |
||
21 | use Cog\Laravel\Paket\Support\Composer; |
||
22 | use Illuminate\Bus\Queueable; |
||
23 | use Illuminate\Queue\InteractsWithQueue; |
||
24 | use Illuminate\Contracts\Queue\ShouldQueue; |
||
25 | use Illuminate\Foundation\Bus\Dispatchable; |
||
26 | |||
27 | View Code Duplication | final class InstallRequirement implements ShouldQueue |
|
0 ignored issues
–
show
|
|||
28 | { |
||
29 | use Dispatchable; |
||
30 | use InteractsWithQueue; |
||
31 | use Queueable; |
||
32 | |||
33 | private $requirement; |
||
34 | |||
35 | private $paketJob; |
||
36 | |||
37 | public function __construct(RequirementContract $requirement, JobContract $paketJob) |
||
38 | { |
||
39 | $this->requirement = $requirement; |
||
40 | $this->paketJob = $paketJob; |
||
41 | } |
||
42 | |||
43 | public function handle(JobRepositoryContract $jobs, Composer $composer): void |
||
44 | { |
||
45 | $jobs->changeJobStatus($this->paketJob, 'InProgress'); |
||
46 | |||
47 | try { |
||
48 | $composer->install($this->requirement, $this->paketJob); |
||
49 | |||
50 | $jobs->changeJobStatus($this->paketJob, 'Done'); |
||
51 | $jobs->changeJobExitCode($this->paketJob, 0); |
||
52 | |||
53 | event(new RequirementHasBeenInstalled($this->requirement, $this->paketJob)); |
||
54 | } catch (JobFailed $exception) { |
||
55 | $jobs->changeJobStatus($this->paketJob, 'Failed'); |
||
56 | $jobs->changeJobExitCode($this->paketJob, $exception->getExitCode()); |
||
57 | |||
58 | // TODO: (?) Dispatch `RequirementInstallationHasBeenFailed` || `InstallationHasBeenFailed` event? |
||
59 | } |
||
60 | } |
||
61 | } |
||
62 |
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.