DownloadsController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
c 2
b 0
f 0
dl 0
loc 31
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A provider() 0 18 3
1
<?php
2
3
namespace App\Controller\Api;
4
5
use App\Document\Provider;
6
use Doctrine\ODM\MongoDB\DocumentManager;
7
use Nelmio\ApiDocBundle\Annotation\Security;
8
use Swagger\Annotations as SWG;
9
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
10
use Symfony\Component\HttpFoundation\Response;
11
use Symfony\Component\Routing\Annotation\Route;
12
13
/**
14
 * Provide routes for stats API.
15
 *
16
 * @Route("/api/downloads", name="api_downloads_", defaults={"_format": "json"})
17
 */
18
class DownloadsController extends AbstractController
19
{
20
    /**
21
     * Profile.
22
     *
23
     * @Route("/{name}/{version}", name="provider", methods={"GET"}, requirements={"name": ".+"})
24
     * @SWG\Response(
25
     *     response=200,
26
     *     description="Returns provider downloads",
27
     * )
28
     * @SWG\Tag(name="downloads")
29
     * @Security(name="Bearer")
30
     */
31
    public function provider(Provider $provider, $version, DocumentManager $dm): Response
32
    {
33
        $all = $dm->getRepository('App:Download')->getProviderStats($provider);
34
        $version = $dm->getRepository('App:Download')->getProviderStats($provider, $version);
35
36
        $data = [];
37
38
        foreach ($all as $item) {
39
            $data[$item['date']]['all'] = $item['downloads'];
40
        }
41
42
        foreach ($version as $item) {
43
            $data[$item['date']]['version'] = $item['downloads'];
44
        }
45
46
        ksort($data);
47
48
        return $this->json($data);
49
    }
50
}
51