-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSuspicion.php
More file actions
87 lines (76 loc) · 2.63 KB
/
Suspicion.php
File metadata and controls
87 lines (76 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
declare(strict_types=1);
namespace App\Models;
use App\Concerns\BelongsToCatagraphy;
use App\Contracts\HasVulnerabilityData;
use App\DataTransferObjects\VulnerabilityData;
use App\DataTransferObjects\VulnerabilityEntry;
use App\DataTransferObjects\VulnerabilityListItem;
use App\Models\Vulnerability\Vulnerability;
use App\Models\Vulnerability\VulnerabilityCategory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Suspicion extends Model implements HasVulnerabilityData
{
use BelongsToCatagraphy;
use HasFactory;
protected $fillable = [
'name',
'category',
'elements',
'notes',
];
protected $casts = [
'name' => 'string',
'category' => 'string',
'elements' => 'collection',
'notes' => 'string',
];
public function vulnerabilityData(?Model $record = null): VulnerabilityData
{
$categories = VulnerabilityCategory::cachedList();
$vulnerabilities = Vulnerability::cachedList();
$category = $vulnerabilities->get($this->category);
return new VulnerabilityData(
name: __('catagraphy.suspicion.label', [
'category' => $category?->name,
'name' => $this->name,
]),
category: $category?->name,
entries: [
new VulnerabilityEntry(
label: __('field.suspicion_name'),
value: $this->name,
),
new VulnerabilityEntry(
label: $categories->get('SUS_CS'),
value: $category?->name,
),
new VulnerabilityEntry(
label: $categories->get('SUS_BR_ES'),
value: $this->elements
?->map(fn (string $element) => $vulnerabilities->get($element)->name)
->join(', '),
),
new VulnerabilityEntry(
label: __('field.suspicion_notes'),
value: $this->notes,
),
]
);
}
public function vulnerabilityListItem(?Model $record = null): VulnerabilityListItem
{
$vulnerabilities = Vulnerability::cachedList();
$category = $vulnerabilities->get($this->category);
return new VulnerabilityListItem(
label: __('catagraphy.suspicion.label', [
'category' => $category?->name,
'name' => $this->name,
]),
value: $this->category,
type: $this->getMorphClass(),
valid: true
);
}
}