ExtractPhotos::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 18
rs 9.9
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Jobs\ProcessResume;
6
use App\Models\Candidate;
7
use App\Models\Tenant;
8
use App\Services\TenantManager;
9
use Illuminate\Console\Command;
10
use Symfony\Component\Console\Exception\RuntimeException;
11
12
class ExtractPhotos extends Command
13
{
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'photo:extract {tenantId}';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Command description';
27
28
    protected $tenantManager;
29
30
    /**
31
     * Create a new command instance.
32
     *
33
     * @param TenantManager $tenantManager
34
     */
35
    public function __construct(TenantManager $tenantManager)
36
    {
37
        parent::__construct();
38
39
        $this->tenantManager = $tenantManager;
40
    }
41
42
    /**
43
     * Execute the console command.
44
     *
45
     * @return mixed
46
     */
47
    public function handle()
48
    {
49
        $tenantId = $this->argument('tenantId');
50
        $tenant = Tenant::find($tenantId);
51
52
        if (!$tenant) {
53
            throw new RuntimeException('Tenant with ID = '.$tenantId.' does not exist.');
0 ignored issues
show
Bug introduced by
Are you sure $tenantId of type array|null|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
            throw new RuntimeException('Tenant with ID = './** @scrutinizer ignore-type */ $tenantId.' does not exist.');
Loading history...
54
        }
55
56
        $this->tenantManager->setTenant($tenant);
57
        \DB::purge('tenant');
58
59
        $candidates = Candidate::whereNull('photo_extraction')->where('path_to_cv', '<>', '')->get();
60
61
        foreach ($candidates as $candidate) {
62
            $this->info('Parsing candidate id '.$candidate->id);
63
            ProcessResume::dispatchNow($candidate);
0 ignored issues
show
Deprecated Code introduced by
The function App\Jobs\ProcessResume::dispatchNow() has been deprecated: Will be removed in a future Laravel version. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

63
            /** @scrutinizer ignore-deprecated */ ProcessResume::dispatchNow($candidate);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
64
            gc_collect_cycles();
65
        }
66
    }
67
}
68