1 | <?php |
||
2 | |||
3 | namespace PragmaBroadvertising\SolarEdge\Models; |
||
4 | |||
5 | use Carbon\Carbon; |
||
6 | use PragmaBroadvertising\SolarEdge\Interfaces\ApiConnectorInterface; |
||
7 | |||
8 | |||
9 | class SolarEdge |
||
10 | { |
||
11 | protected $connector; |
||
12 | |||
13 | public function __construct(ApiConnectorInterface $connector) { |
||
14 | $this->connector = $connector; |
||
15 | } |
||
16 | |||
17 | /** |
||
18 | * Get Site details |
||
19 | * @return mixed |
||
20 | */ |
||
21 | function details(){ |
||
0 ignored issues
–
show
|
|||
22 | $request = $this->connector->getFromSite('details'); |
||
23 | |||
24 | $details = collect(); |
||
25 | |||
26 | $details->id = $request->id; |
||
0 ignored issues
–
show
|
|||
27 | $details->name = $request->name; |
||
0 ignored issues
–
show
|
|||
28 | $details->accountId = $request->accountId; |
||
0 ignored issues
–
show
|
|||
29 | $details->status = $request->status; |
||
0 ignored issues
–
show
|
|||
30 | $details->peakPower = $request->peakPower; |
||
0 ignored issues
–
show
|
|||
31 | $details->lastUpdateTime = $request->lastUpdateTime; |
||
0 ignored issues
–
show
|
|||
32 | $details->installationDate = $request->installationDate; |
||
0 ignored issues
–
show
|
|||
33 | $details->ptoDate = $request->ptoDate; |
||
0 ignored issues
–
show
|
|||
34 | $details->notes = $request->notes; |
||
0 ignored issues
–
show
|
|||
35 | $details->type = $request->type; |
||
0 ignored issues
–
show
|
|||
36 | $details->location = $request->location; |
||
0 ignored issues
–
show
|
|||
37 | $details->primaryModule = $request->primaryModule; |
||
0 ignored issues
–
show
|
|||
38 | $details->uris = $request->uris; |
||
0 ignored issues
–
show
|
|||
39 | $details->publicSettings = $request->publicSettings; |
||
0 ignored issues
–
show
|
|||
40 | |||
41 | return $details; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Get Site energy |
||
46 | * @return mixed |
||
47 | */ |
||
48 | View Code Duplication | function energy($subtractDays, $order){ |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
49 | $start = Carbon::now()->subDays($subtractDays-1)->format('Y-m-d'); |
||
50 | $end = Carbon::now()->format('Y-m-d'); |
||
51 | $request = $this->connector->getFromSiteWithStartAndEnd('energy','QUARTER_OF_AN_HOUR', $start, $end); |
||
52 | |||
53 | $energy = collect(); |
||
54 | |||
55 | $energy->measured_by = $request->measuredBy; |
||
0 ignored issues
–
show
|
|||
56 | $energy->unit = $request->unit; |
||
0 ignored issues
–
show
|
|||
57 | |||
58 | switch ($order) { |
||
59 | case 'asc': |
||
60 | $energy->days = collect($request->values)->sortBy('date')->reverse(); |
||
0 ignored issues
–
show
|
|||
61 | break; |
||
62 | case 'desc': |
||
63 | $energy->days = collect($request->values)->sortBy('date'); |
||
64 | break; |
||
65 | } |
||
66 | |||
67 | return $energy; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Get Site power |
||
72 | * @return mixed |
||
73 | */ |
||
74 | View Code Duplication | function power($subtractDays, $order){ |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
75 | $start = Carbon::now()->subDays($subtractDays-1)->format('Y-m-d%20H:i:s'); |
||
76 | $end = Carbon::now()->format('Y-m-d%20H:i:s'); |
||
77 | $request = $this->connector->getFromSiteWithStartAndEnd('power','DAY', $start, $end,true); |
||
78 | |||
79 | $power = collect(); |
||
80 | |||
81 | $power->interval = $request->timeUnit; |
||
0 ignored issues
–
show
|
|||
82 | $power->unit = $request->unit; |
||
0 ignored issues
–
show
|
|||
83 | |||
84 | switch ($order) { |
||
85 | case 'asc': |
||
86 | $power->days = collect($request->values)->sortBy('date')->reverse(); |
||
0 ignored issues
–
show
|
|||
87 | break; |
||
88 | case 'desc': |
||
89 | $power->days = collect($request->values)->sortBy('date'); |
||
90 | break; |
||
91 | } |
||
92 | |||
93 | return $power; |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Get Site overview |
||
98 | * @return mixed |
||
99 | */ |
||
100 | function overview(){ |
||
0 ignored issues
–
show
|
|||
101 | $request = $this->connector->getFromSite('overview'); |
||
102 | |||
103 | $overview = collect(); |
||
104 | |||
105 | $overview->measuredBy = $request->measuredBy; |
||
0 ignored issues
–
show
|
|||
106 | $overview->lastUpdate = $request->lastUpdateTime; |
||
0 ignored issues
–
show
|
|||
107 | $overview->lifeTime = $request->lifeTimeData->energy; |
||
0 ignored issues
–
show
|
|||
108 | $overview->lastYear = $request->lastYearData->energy; |
||
0 ignored issues
–
show
|
|||
109 | $overview->lastMonth = $request->lastMonthData->energy; |
||
0 ignored issues
–
show
|
|||
110 | $overview->lastDay = $request->lastDayData->energy; |
||
0 ignored issues
–
show
|
|||
111 | $overview->currentPower = $request->currentPower->power; |
||
0 ignored issues
–
show
|
|||
112 | $overview->powerUnit = 'W'; |
||
0 ignored issues
–
show
|
|||
113 | $overview->energyUnit = 'Wh'; |
||
0 ignored issues
–
show
|
|||
114 | |||
115 | return $overview; |
||
116 | } |
||
117 | } |
||
118 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.