1 | <?php |
||
2 | |||
3 | namespace App\Trait; |
||
4 | |||
5 | use App\Entity\EnergyIntensityPerGDP; |
||
6 | use App\Entity\RenewableEnergyShare; |
||
7 | use App\Entity\RenewableEnergyTWh; |
||
8 | |||
9 | trait EnergyFormatterTrait |
||
10 | { |
||
11 | /** |
||
12 | * @param RenewableEnergyShare[] $items |
||
13 | * @return array<int, array<string, int|null>> |
||
14 | */ |
||
15 | private function formatEnergyShareTotal(array $items): array |
||
16 | { |
||
17 | $result = []; |
||
18 | foreach ($items as $item) { |
||
19 | $result[] = [ |
||
20 | 'year' => $item->getYear(), |
||
21 | 'total' => $item->getTotal(), |
||
22 | 'value' => $item->getHeatCoolingIndustry(), |
||
23 | ]; |
||
24 | } |
||
25 | return $result; |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @param RenewableEnergyShare[] $items |
||
30 | * @return array<int, array{year: int|null, el: int|null, transport: int|null}> |
||
31 | */ |
||
32 | private function formatEnergyShareEL(array $items): array |
||
33 | { |
||
34 | $result = []; |
||
35 | foreach ($items as $item) { |
||
36 | $result[] = [ |
||
37 | 'year' => $item->getYear(), |
||
38 | 'el' => $item->getElectricity(), |
||
39 | 'transport' => $item->getTransport(), |
||
40 | ]; |
||
41 | } |
||
42 | return $result; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @param EnergyIntensityPerGDP[] $items |
||
47 | * @return array<int, array{year: int|null, value: float|null}> |
||
48 | */ |
||
49 | private function formatEnergyIntensity(array $items): array |
||
50 | { |
||
51 | $result = []; |
||
52 | foreach ($items as $item) { |
||
53 | $result[] = [ |
||
54 | 'year' => $item->getYear(), |
||
55 | 'value' => $item->getIntensityChangePercent(), |
||
56 | ]; |
||
57 | } |
||
58 | return $result; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param RenewableEnergyTWh[] $items |
||
63 | * @return array<int, array{ |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
64 | * year: int|null, bio: int|null, hydro: int|null, wind: int|null, heat: int|null, solar: int|null |
||
65 | * }> |
||
66 | */ |
||
67 | private function formatEnergyTWh(array $items): array |
||
68 | { |
||
69 | $result = []; |
||
70 | foreach ($items as $item) { |
||
71 | $result[] = [ |
||
72 | 'year' => $item->getYear(), |
||
73 | 'bio' => $item->getBiofuels(), |
||
74 | 'hydro' => $item->getHydropower(), |
||
75 | 'wind' => $item->getWindPower(), |
||
76 | 'heat' => $item->getHeatPumps(), |
||
77 | 'solar' => $item->getSolarEnergy(), |
||
78 | ]; |
||
79 | } |
||
80 | return $result; |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @param RenewableEnergyTWh[] $items |
||
85 | * @return array<int, array{year: int|null, TWh-total: int|null, total-use: int|null}> |
||
86 | */ |
||
87 | private function formatTotalInTWh(array $items): array |
||
88 | { |
||
89 | $result = []; |
||
90 | foreach ($items as $item) { |
||
91 | $result[] = [ |
||
92 | 'year' => $item->getYear(), |
||
93 | 'TWh-total' => $item->getTotal(), |
||
94 | 'total-use' => $item->getTotalEnergyUse(), |
||
95 | ]; |
||
96 | } |
||
97 | return $result; |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * @param RenewableEnergyTWh[] $items |
||
102 | * @return array<int, array{year: int|null, statistical: int|null, target: int|null}> |
||
103 | */ |
||
104 | private function formatTarget(array $items): array |
||
105 | { |
||
106 | $result = []; |
||
107 | foreach ($items as $item) { |
||
108 | |||
109 | $result[] = [ |
||
110 | 'year' => $item->getYear(), |
||
111 | 'statistical' => $item->getStatisticalTransfer(), |
||
112 | 'target' => $item->getTargetCalculation(), |
||
113 | ]; |
||
114 | } |
||
115 | return $result; |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * @param RenewableEnergyTWh[] $items |
||
120 | * @param int|null $year |
||
121 | * @param string|null $type |
||
122 | * @return list<array<string, int|null>> |
||
0 ignored issues
–
show
The type
App\Trait\list was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
123 | */ |
||
124 | private function filterTWhDataByYearAndType(array $items, ?int $year, ?string $type): array |
||
125 | { |
||
126 | $result = []; |
||
127 | |||
128 | foreach ($items as $item) { |
||
129 | if ($item->getYear() === $year) { |
||
130 | $value = match ($type) { |
||
131 | 'bio' => $item->getBiofuels(), |
||
132 | 'hydro' => $item->getHydropower(), |
||
133 | 'wind' => $item->getWindPower(), |
||
134 | 'heat' => $item->getHeatPumps(), |
||
135 | 'solar' => $item->getSolarEnergy(), |
||
136 | default => null, |
||
137 | }; |
||
138 | |||
139 | if ($value !== null) { |
||
140 | $result[] = [ |
||
141 | 'year' => $item->getYear(), |
||
142 | $type => $value, |
||
143 | ]; |
||
144 | } |
||
145 | } |
||
146 | } |
||
147 | |||
148 | return $result; |
||
149 | } |
||
150 | |||
151 | } |
||
152 |