Conditions | 8 |
Paths | 3 |
Total Lines | 78 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
54 | public function getSectoralDistributionAction() |
||
55 | { |
||
56 | $year = (int)$this->params()->fromRoute('year'); |
||
57 | $sector = (int)$this->params()->fromRoute('sector'); |
||
58 | |||
59 | $response = []; |
||
60 | $arrGraphData = []; |
||
61 | |||
62 | $results = $this->entityManager->getRepository(Emission::class) |
||
63 | ->findActivityByYearAndSector($year, $sector); |
||
64 | |||
65 | $totalActivities = 0; |
||
66 | |||
67 | foreach ($results as $result) { |
||
68 | $arrActividades = [ |
||
69 | 'label' => $result['name'], |
||
70 | 'value' => round($result['total'], 2) |
||
71 | ]; |
||
72 | |||
73 | $totalActivities += $result['total']; |
||
74 | |||
75 | // EN CADA ACTIVIDAD HAGO QUE HACER EL SEARCH DE LA SUBACTIVIDAD |
||
76 | $results2 = $this->entityManager->getRepository(Emission::class) |
||
77 | ->findSubactivityByYearSectorAndActivity($year, $sector, $result['activity']); |
||
78 | |||
79 | if (count($results2) > 0) { |
||
80 | $arrSubactividades = []; |
||
81 | |||
82 | $i = 0; |
||
83 | |||
84 | foreach ($results2 as $result2) { |
||
85 | $arrSubactividades[$i] = [ |
||
86 | 'label' => $result2['name'], |
||
87 | 'value' => round($result2['total'], 2) |
||
88 | ]; |
||
89 | |||
90 | |||
91 | if ($sector == 3 || $sector == 4) { |
||
92 | continue; |
||
93 | } |
||
94 | |||
95 | // TODO: ACA EN CADA SUBACTIVIDAD TENDRIA QUE HACER EL SEARCH DE LA CATEGORIA |
||
96 | $results3 = $this->entityManager->getRepository(Emission::class) |
||
97 | ->findCategoryByYearSectorActivityAndSubactivity($year, $sector, $result['activity'], $result2['subactivity']); |
||
98 | |||
99 | if (count($results3) > 0) { |
||
100 | $arrCategorias = []; |
||
101 | |||
102 | foreach ($results3 as $result3) { |
||
103 | $arrCategorias[] = [ |
||
104 | 'label'=>$result3['name'], |
||
105 | 'value'=>round($result3['total'], 2) |
||
106 | ]; |
||
107 | } |
||
108 | $arrSubactividades[$i]['inner'] = $arrCategorias; |
||
109 | } |
||
110 | $i++; |
||
111 | } |
||
112 | |||
113 | $arrActividades['inner'] = $arrSubactividades; |
||
114 | } |
||
115 | |||
116 | $arrGraphData[] = $arrActividades; |
||
117 | } |
||
118 | |||
119 | |||
120 | $response['graph_data'] = $arrGraphData; |
||
121 | $response['totalActividades'] = $totalActivities; |
||
122 | |||
123 | /** |
||
124 | * BUSCO LA INFO DEL SECTOR |
||
125 | */ |
||
126 | $results = $this->entityManager->getRepository(Sector::class)->getSector($sector); |
||
127 | |||
128 | $response['sector'] = $results[0]; |
||
129 | |||
130 | return new JsonModel($response); |
||
131 | } |
||
132 | |||
192 |