IndicatorsReportController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 53
ccs 26
cts 26
cp 1
rs 10
c 3
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B getIndicatorAction() 0 40 3
1
<?php
2
3
namespace Api\Controller;
4
5
use Zend\Mvc\Controller\AbstractRestfulController;
6
use Zend\View\Model\JsonModel;
7
use Api\Entity\Indicator;
8
use Api\Entity\IndicatorValue;
9
10
/**
11
 *
12
 */
13
class IndicatorsReportController extends AbstractRestfulController
14
{
15
    /**
16
     * Entity manager.
17
     * @var Doctrine\ORM\EntityManager
18
     */
19
    private $entityManager;
20
21 1
    public function __construct($entityManager)
22
    {
23 1
        $this->entityManager = $entityManager;
24 1
    }
25 1
    public function getIndicatorAction()
26
    {
27 1
        $indicator = (int) $this->params()->fromRoute('indicator');
28
29 1
        $response = [];
30
31
        // DATOS GENERALES DEL INDICADOR
32 1
        $arrIndicador = $this->entityManager->getRepository(Indicator::class)
33 1
            ->getIndicator($indicator);
34
35 1
        foreach ($arrIndicador as $indicador) {
36 1
            $response['indicador'] = $indicador;
37 1
            break;
38
        }
39
40 1
        $arrValores = $this->entityManager->getRepository(IndicatorValue::class)
41 1
            ->getIndicatorValue($indicator);
42
43 1
        $arrAnos = [];
44 1
        $arrValor = [];
45
46 1
        foreach ($arrValores as $a) {
47
            // SI EL NOMBRE TIENE UNA COMA LO TENGO QUE PONER ENTRE COMILLAS
48 1
            $arrAnos[]  = $a['year'];
49 1
            $arrValor[] = $a['value'];
50
        }
51
52 1
        $arrAnos = array_merge(array('x'), $arrAnos);
53 1
        $response['column_1'] = $arrAnos;
54
55 1
        $arrValor = array_merge(array($indicador['name']), $arrValor);
0 ignored issues
show
Bug introduced by
The variable $indicador seems to be defined by a foreach iteration on line 35. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
56 1
        $response['column_2'] = $arrValor;
57
58 1
        $response['unidad'] = $indicador['unit'];
59 1
        $response['descripcion'] = nl2br($indicador['description']);
60
61 1
        $response['colores'] = "#8064a2";
62
63 1
        return new JsonModel($response);
64
    }
65
}
66