Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| RecentReviews | |
100.00% |
10 / 10 |
|
100.00% |
6 / 6 |
6 | |
100.00% |
1 / 1 |
| key | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| label | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| icon | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| description | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| fields | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| reviews | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Widgets\Types; |
| 4 | |
| 5 | use App\Models\CustomerReview; |
| 6 | use App\Widgets\AbstractWidget; |
| 7 | |
| 8 | class RecentReviews extends AbstractWidget |
| 9 | { |
| 10 | protected string $view = 'widgets.recent-reviews'; |
| 11 | |
| 12 | public function key(): string |
| 13 | { |
| 14 | return 'recent_reviews'; |
| 15 | } |
| 16 | |
| 17 | public function label(): string |
| 18 | { |
| 19 | return 'Customer reviews'; |
| 20 | } |
| 21 | |
| 22 | public function icon(): string |
| 23 | { |
| 24 | return 'fas fa-star'; |
| 25 | } |
| 26 | |
| 27 | public function description(): string |
| 28 | { |
| 29 | return 'A strip of recent customer review images / quotes.'; |
| 30 | } |
| 31 | |
| 32 | public function fields(): array |
| 33 | { |
| 34 | return [ |
| 35 | 'title' => ['type' => 'text', 'label' => 'Heading', 'default' => 'What our customers say'], |
| 36 | 'limit' => ['type' => 'number', 'label' => 'How many', 'default' => 8], |
| 37 | ]; |
| 38 | } |
| 39 | |
| 40 | public function reviews(array $s) |
| 41 | { |
| 42 | $limit = max(1, min(24, (int) ($s['limit'] ?? 8))); |
| 43 | |
| 44 | return CustomerReview::query()->latest()->limit($limit)->get(); |
| 45 | } |
| 46 | } |