1 | <?php |
||||
2 | |||||
3 | namespace App\Utils; |
||||
4 | |||||
5 | use App\Models\Source; |
||||
6 | use Illuminate\Support\Str; |
||||
7 | |||||
8 | class SourceCreator |
||||
9 | { |
||||
10 | const SOURCE_KEY_MAXLENGTH = 6; |
||||
11 | |||||
12 | public static function create(array $data): Source |
||||
13 | { |
||||
14 | $source = new Source(); |
||||
15 | $source->name = $data['name']; |
||||
16 | $source->recruitment_id = $data['recruitment_id']; |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
17 | $source->key = self::generateKey(); |
||||
18 | $source->save(); |
||||
19 | |||||
20 | return Source::find($source->id); |
||||
0 ignored issues
–
show
|
|||||
21 | } |
||||
22 | |||||
23 | private static function generateKey() |
||||
24 | { |
||||
25 | do { |
||||
26 | $key = strtoupper(Str::random(self::SOURCE_KEY_MAXLENGTH)); |
||||
0 ignored issues
–
show
The method
random() does not exist on Illuminate\Support\Str .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
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. ![]() |
|||||
27 | $sources = Source::where('key', $key)->count(); |
||||
28 | } while ($sources > 0); |
||||
29 | |||||
30 | return $key; |
||||
31 | } |
||||
32 | } |
||||
33 |