IndexControllerProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 28
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B connect() 0 25 3
1
<?php
2
3
namespace LoteriaApi\Provider\Routes;
4
5
use Silex\Application;
6
use Silex\ControllerProviderInterface;
7
8
class IndexControllerProvider implements ControllerProviderInterface
9
{
10
    public function connect(Application $app)
11
    {
12
        $controllers = $app['controllers_factory'];
13
14
        $controllers->get('/', function () use ($app) {
15
            $loteria = $app['request']->get('loteria');
16
            $concurso = $app['request']->get('concurso');
17
18
            try {
19
                $loteria = $app['factory']->getLoteria($loteria);
20
21
                $result = $loteria->findLastConcurso();
22
23
                if ($concurso) {
24
                    $result = $loteria->findByConcurso($concurso);
25
                }
26
                
27
                return $app->json($result, 200);
28
            } catch (\Exception $e) {
29
                return $app->abort(400);
30
            }
31
        });
32
33
        return $controllers;
34
    }
35
}
36