SolarEdgeClient   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFromSiteWithStartAndEnd() 0 20 2
A __construct() 0 5 1
A getFromSite() 0 3 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: evert
5
 * Date: 27/09/2017
6
 * Time: 09:38
7
 */
8
9
namespace PragmaBroadvertising\SolarEdge\Models;
10
11
use Ixudra\Curl\Facades\Curl;
12
use PragmaBroadvertising\SolarEdge\Interfaces\ApiConnectorInterface;
13
14
class SolarEdgeClient implements ApiConnectorInterface
15
{
16
    public function __construct()
17
    {
18
        $this->key = '?api_key=' . env('SOLAREDGE_API_KEY','');
0 ignored issues
show
Bug Best Practice introduced by
The property key does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
19
        $this->id = env('SOLAREDGE_INSTALLATION_ID','');
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
20
        $this->endpoint = env('SOLAREDGE_ENDPOINT','https://monitoringapi.solaredge.com/');
0 ignored issues
show
Bug Best Practice introduced by
The property endpoint does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
21
    }
22
23
    /**
24
     * Get from Site
25
     * - endpoint
26
     * - id
27
     * - key
28
     * @param $siteProperty
29
     * @return mixed
30
     */
31
    function getFromSite($siteProperty){
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...
32
        $request = Curl::to($this->endpoint . 'site/' . $this->id . '/' . $siteProperty . $this->key)->asJson()->get()->{$siteProperty};
33
        return $request;
34
    }
35
36
    /**
37
     * Get from Site with start- and end date
38
     * - endpoint
39
     * - id
40
     * - key
41
     * - timeUnit
42
     * - startDate
43
     * - endDate
44
     * - withTime
45
     * @param $siteProperty
46
     * @return mixed
47
     */
48
    function getFromSiteWithStartAndEnd($siteProperty,$timeUnit,$startDate,$endDate,$withTime = false){
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...
49
        if(!$withTime) {
50
            $request =
51
                Curl::to($this->endpoint . 'site/' . $this->id . '/' . $siteProperty .
52
                    $this->key .
53
                    '&startDate=' . $startDate .
54
                    '&endDate=' . $endDate .
55
                    '&timeUnit=' . $timeUnit
56
                )->asJson()->get()->{$siteProperty};
57
        }
58
        else {
59
            $request =
60
                Curl::to($this->endpoint . 'site/' . $this->id . '/' . $siteProperty .
61
                    $this->key .
62
                    '&startTime=' . $startDate .
63
                    '&endTime=' . $endDate
64
                )->asJson()->get()->{$siteProperty};
65
        }
66
67
        return $request;
68
    }
69
}