-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQualityListingController.php
53 lines (43 loc) · 1.15 KB
/
QualityListingController.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
<?php
declare(strict_types=1);
namespace App\Infrastructure\Api;
use Symfony\Component\HttpFoundation\JsonResponse;
final class QualityListingController
{
private CalculateScoreController $ads;
private array $listAds = [];
/**
* Constructor that injects a CalculateScoreController instance
*
* @param CalculateScoreController $ads
*/
public function __construct(CalculateScoreController $ads)
{
$this->ads = $ads;
}
/**
* Invokable method that returns a JsonResponse containing quality-filtered ads
*
* @return JsonResponse
*/
public function __invoke(): JsonResponse
{
$this->listAds = $this->ads->getAdsAndScore();
return new JsonResponse( $this->getAds() );
}
/**
* Method to get quality-filtered ads
*
* @return array
*/
public function getAds(): array
{
$filteredAds = array_filter($this->listAds, function ($ad) {
return $ad['score'] < 40;
});
usort($filteredAds, function ($ad1, $ad2) {
return $ad2['score'] <=> $ad1['score'];
});
return $filteredAds;
}
}