Test Setup Failed
Branch zf3-version (3457ba)
by Diego
04:51
created

IndicatorsReportController::getIndicatorAction()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 40
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 40
rs 8.8571
c 1
b 0
f 1
cc 3
eloc 23
nc 4
nop 0
1
<?php
2
3
namespace Api\Controller;
4
5
use Zend\Db\Adapter\AdapterInterface;
6
use Zend\Mvc\Controller\AbstractRestfulController;
7
use Zend\View\Model\JsonModel;
8
use Api\Helper\Utils;
9
use Api\Entity\Indicator;
10
use Api\Entity\IndicatorValue;
11
12
/**
13
 *
14
 */
15
class IndicatorsReportController extends AbstractRestfulController
16
{
17
    /**
18
     * Entity manager.
19
     * @var Doctrine\ORM\EntityManager
20
     */
21
    private $entityManager;
22
23
    public function __construct($entityManager)
24
    {
25
        $this->entityManager = $entityManager;
26
    }
27
    public function getIndicatorAction()
28
    {
29
        $indicator = (int)$this->params()->fromRoute('indicator');
30
31
        $response = [];
32
33
        // DATOS GENERALES DEL INDICADOR
34
        $arrIndicador = $this->entityManager->getRepository(Indicator::class)
35
            ->getIndicator($indicator);
36
37
        foreach($arrIndicador as $indicador) {
38
            $response['indicador'] = $indicador;
39
            break;
40
        }
41
42
        $arrValores = $this->entityManager->getRepository(IndicatorValue::class)
43
            ->getIndicatorValue($indicator);
44
45
        $arrAnos = [];
46
        $arrValor = [];
47
48
        foreach($arrValores as $a) {
49
            // SI EL NOMBRE TIENE UNA COMA LO TENGO QUE PONER ENTRE COMILLAS
50
            $arrAnos[]  = $a['year'];
51
            $arrValor[] = $a['value'];
52
        }
53
54
        $arrAnos = array_merge(array('x'), $arrAnos);
55
        $response['column_1'] = $arrAnos;
56
57
        $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 37. 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...
58
        $response['column_2'] = $arrValor;
59
60
        $response['unidad'] = $indicador['unit'];
61
        $response['descripcion'] = nl2br($indicador['description']);
62
63
        $response['colores'] = "#8064a2";
64
65
        return new JsonModel($response);
66
    }
67
}
68