CandidateDeleter::hashData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace App\Utils\Candidates;
4
5
use App\Events\CandidateDeleted;
6
use App\Http\Requests\CandidateDeleteRequest;
7
use App\Models\Candidate;
8
use Illuminate\Support\Facades\Storage;
9
10
class CandidateDeleter
11
{
12
    public static function deleteCandidate(CandidateDeleteRequest $request, $candidateId)
13
    {
14
        $candidate = Candidate::findOrFail($candidateId);
15
16
        $notificationEmailAddress = null;
17
        if ($request->get('notify_candidate')) {
0 ignored issues
show
Bug introduced by
The method get() does not exist on App\Http\Requests\CandidateDeleteRequest. ( Ignorable by Annotation )

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

17
        if ($request->/** @scrutinizer ignore-call */ get('notify_candidate')) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
18
            $notificationEmailAddress = $candidate->email;
19
        }
20
21
        Storage::delete(storage_path('app/'.$candidate->path_to_cv));
22
        $candidate->path_to_cv = '';
0 ignored issues
show
Bug introduced by
The property path_to_cv does not seem to exist on Illuminate\Database\Eloquent\Collection.
Loading history...
23
        self::hashData($candidate);
24
        $candidate->save();
25
26
        $candidate->delete(); //safe since we use softdeletes
27
28
        event(new CandidateDeleted($candidate, $notificationEmailAddress));
29
    }
30
31
    protected static function hashData(Candidate $candidate)
32
    {
33
        $candidate->name = sha1($candidate->first_name);
0 ignored issues
show
Bug introduced by
The property first_name does not seem to exist on App\Models\Candidate. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
34
        $candidate->email = sha1($candidate->email);
35
        $candidate->phone_number = sha1($candidate->phone_number);
36
    }
37
}
38