forked from vormkracht10/laravel-seo-scanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSeoScore.php
63 lines (47 loc) · 1.38 KB
/
SeoScore.php
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
<?php
namespace Vormkracht10\Seo;
use Illuminate\Support\Collection;
class SeoScore
{
public int|float $score = 0;
public Collection $successful;
public Collection $failed;
public function __invoke(Collection $successful, Collection $failed): self
{
$this->successful = $successful;
$this->failed = $failed;
if (! $successful->count()) {
$this->score = 0;
return $this;
}
$successfulScoreWeight = $successful->sum('scoreWeight');
$failedScoreWeight = $failed->sum('scoreWeight');
$totalScoreWeight = $successfulScoreWeight + $failedScoreWeight;
$this->score = round($successfulScoreWeight / $totalScoreWeight * 100);
return $this;
}
public function getScore(): int|float
{
return $this->score;
}
public function getScoreDetails(): array
{
return [
'score' => $this->score,
'successful' => $this->successful,
'failed' => $this->failed,
];
}
public function getFailedChecks(): Collection
{
return $this->failed;
}
public function getSuccessfulChecks(): Collection
{
return $this->successful;
}
public function getAllChecks(): Collection
{
return collect(['successful' => $this->successful])->merge(['failed' => $this->failed]);
}
}