SolarEdge::details()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 0
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
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
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
22
        $request = $this->connector->getFromSite('details');
23
24
        $details = collect();
25
26
        $details->id                = $request->id;
0 ignored issues
show
Bug introduced by
The property id does not seem to exist on Illuminate\Support\Collection.
Loading history...
27
        $details->name              = $request->name;
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on Illuminate\Support\Collection.
Loading history...
28
        $details->accountId         = $request->accountId;
0 ignored issues
show
Bug introduced by
The property accountId does not seem to exist on Illuminate\Support\Collection.
Loading history...
29
        $details->status            = $request->status;
0 ignored issues
show
Bug introduced by
The property status does not seem to exist on Illuminate\Support\Collection.
Loading history...
30
        $details->peakPower         = $request->peakPower;
0 ignored issues
show
Bug introduced by
The property peakPower does not seem to exist on Illuminate\Support\Collection.
Loading history...
31
        $details->lastUpdateTime    = $request->lastUpdateTime;
0 ignored issues
show
Bug introduced by
The property lastUpdateTime does not seem to exist on Illuminate\Support\Collection.
Loading history...
32
        $details->installationDate  = $request->installationDate;
0 ignored issues
show
Bug introduced by
The property installationDate does not seem to exist on Illuminate\Support\Collection.
Loading history...
33
        $details->ptoDate           = $request->ptoDate;
0 ignored issues
show
Bug introduced by
The property ptoDate does not seem to exist on Illuminate\Support\Collection.
Loading history...
34
        $details->notes             = $request->notes;
0 ignored issues
show
Bug introduced by
The property notes does not seem to exist on Illuminate\Support\Collection.
Loading history...
35
        $details->type              = $request->type;
0 ignored issues
show
Bug introduced by
The property type does not seem to exist on Illuminate\Support\Collection.
Loading history...
36
        $details->location          = $request->location;
0 ignored issues
show
Bug introduced by
The property location does not seem to exist on Illuminate\Support\Collection.
Loading history...
37
        $details->primaryModule     = $request->primaryModule;
0 ignored issues
show
Bug introduced by
The property primaryModule does not seem to exist on Illuminate\Support\Collection.
Loading history...
38
        $details->uris              = $request->uris;
0 ignored issues
show
Bug introduced by
The property uris does not seem to exist on Illuminate\Support\Collection.
Loading history...
39
        $details->publicSettings    = $request->publicSettings;
0 ignored issues
show
Bug introduced by
The property publicSettings does not seem to exist on Illuminate\Support\Collection.
Loading history...
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
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
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.

Loading history...
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
Bug introduced by
The property measured_by does not seem to exist on Illuminate\Support\Collection.
Loading history...
56
        $energy->unit = $request->unit;
0 ignored issues
show
Bug introduced by
The property unit does not seem to exist on Illuminate\Support\Collection.
Loading history...
57
58
        switch ($order) {
59
            case 'asc':
60
                $energy->days = collect($request->values)->sortBy('date')->reverse();
0 ignored issues
show
Bug introduced by
The property days does not seem to exist on Illuminate\Support\Collection.
Loading history...
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
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
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.

Loading history...
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
Bug introduced by
The property interval does not seem to exist on Illuminate\Support\Collection.
Loading history...
82
        $power->unit        = $request->unit;
0 ignored issues
show
Bug introduced by
The property unit does not seem to exist on Illuminate\Support\Collection.
Loading history...
83
84
        switch ($order) {
85
            case 'asc':
86
                $power->days    = collect($request->values)->sortBy('date')->reverse();
0 ignored issues
show
Bug introduced by
The property days does not seem to exist on Illuminate\Support\Collection.
Loading history...
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
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
101
        $request = $this->connector->getFromSite('overview');
102
103
        $overview = collect();
104
105
        $overview->measuredBy   = $request->measuredBy;
0 ignored issues
show
Bug introduced by
The property measuredBy does not seem to exist on Illuminate\Support\Collection.
Loading history...
106
        $overview->lastUpdate   = $request->lastUpdateTime;
0 ignored issues
show
Bug introduced by
The property lastUpdate does not seem to exist on Illuminate\Support\Collection.
Loading history...
107
        $overview->lifeTime     = $request->lifeTimeData->energy;
0 ignored issues
show
Bug introduced by
The property lifeTime does not seem to exist on Illuminate\Support\Collection.
Loading history...
108
        $overview->lastYear     = $request->lastYearData->energy;
0 ignored issues
show
Bug introduced by
The property lastYear does not seem to exist on Illuminate\Support\Collection.
Loading history...
109
        $overview->lastMonth    = $request->lastMonthData->energy;
0 ignored issues
show
Bug introduced by
The property lastMonth does not seem to exist on Illuminate\Support\Collection.
Loading history...
110
        $overview->lastDay      = $request->lastDayData->energy;
0 ignored issues
show
Bug introduced by
The property lastDay does not seem to exist on Illuminate\Support\Collection.
Loading history...
111
        $overview->currentPower = $request->currentPower->power;
0 ignored issues
show
Bug introduced by
The property currentPower does not seem to exist on Illuminate\Support\Collection.
Loading history...
112
        $overview->powerUnit    = 'W';
0 ignored issues
show
Bug introduced by
The property powerUnit does not seem to exist on Illuminate\Support\Collection.
Loading history...
113
        $overview->energyUnit   = 'Wh';
0 ignored issues
show
Bug introduced by
The property energyUnit does not seem to exist on Illuminate\Support\Collection.
Loading history...
114
115
        return $overview;
116
    }
117
}
118