ProcessResume::handle()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 7
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 12
rs 9.6111
1
<?php
2
3
namespace App\Jobs;
4
5
use App\Models\Candidate;
6
use App\Utils\ResumeParser;
7
use Illuminate\Bus\Queueable;
8
use Illuminate\Contracts\Queue\ShouldQueue;
9
use Illuminate\Foundation\Bus\Dispatchable;
10
use Illuminate\Queue\InteractsWithQueue;
11
use Illuminate\Queue\SerializesModels;
12
use Illuminate\Support\Facades\Storage;
13
14
class ProcessResume implements ShouldQueue
15
{
16
    use Dispatchable;
17
    use InteractsWithQueue;
18
    use Queueable;
19
    use SerializesModels;
0 ignored issues
show
introduced by
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by App\Jobs\ProcessResume: $id, $relations, $class, $keyBy
Loading history...
20
21
    /**
22
     * @var Candidate
23
     */
24
    protected $candidate;
25
26
    protected $override;
27
28
    /**
29
     * Create a new job instance.
30
     *
31
     * @param Candidate $candidate
32
     * @param bool      $override
33
     */
34
    public function __construct(Candidate $candidate, $override = false)
35
    {
36
        $this->candidate = $candidate;
37
        $this->override = $override;
38
    }
39
40
    /**
41
     * Execute the job.
42
     *
43
     * @throws \Exception
44
     *
45
     * @return void
46
     */
47
    public function handle()
48
    {
49
        if (substr($this->candidate->path_to_cv, -4) == '.pdf') {
50
            $outputFile = str_replace('.pdf', '_avatar.jpg', $this->candidate->path_to_cv);
51
52
            if ($this->override || Storage::disk('s3')->missing($outputFile)) {
53
                if (ResumeParser::extractPhoto($this->candidate->path_to_cv, $outputFile)) {
54
                    $this->candidate->photo_path = $outputFile;
55
                }
56
57
                $this->candidate->photo_extraction = new \DateTime();
58
                $this->candidate->save();
59
            }
60
        }
61
    }
62
}
63