StatsController::stats()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
namespace App\Controller\Api;
4
5
use Doctrine\ODM\MongoDB\DocumentManager;
6
use Nelmio\ApiDocBundle\Annotation\Security;
7
use Swagger\Annotations as SWG;
8
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\Routing\Annotation\Route;
11
12
/**
13
 * Provide routes for stats API.
14
 *
15
 * @Route("/api/stats", name="api_stats_", defaults={"_format": "json"})
16
 */
17
class StatsController extends AbstractController
18
{
19
    /**
20
     * Profile.
21
     *
22
     * @Route("", name="app", methods={"GET"})
23
     * @SWG\Response(
24
     *     response=200,
25
     *     description="Returns stats",
26
     * )
27
     * @SWG\Tag(name="stats")
28
     * @Security(name="Bearer")
29
     */
30
    public function stats(DocumentManager $dm): Response
31
    {
32
        return $this->json([
33
            'packages' => $dm->getRepository('App:Provider')->count(),
34
            'applications' => $dm->getRepository('App:Application')->count($this->getUser()),
35
            'weekly_downloads' => $dm->getRepository('App:Download')->countLast7Days(),
36
        ]);
37
    }
38
}
39