Wakatime   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 65
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setApiKey() 0 6 1
A getApiKey() 0 4 1
A getBaseUrl() 0 4 1
A setBaseUrl() 0 6 1
A fetchUserDurations() 0 7 1
A performRequest() 0 4 1
1
<?php
2
3
namespace Kallencode\Wakatime;
4
5
use DateTime;
6
use Illuminate\Support\Collection;
7
use Illuminate\Support\Traits\Macroable;
8
9
class Wakatime
10
{
11
    use Macroable;
12
13
    protected $client;
14
15
    /**
16
     * Create a new Wakatime Instance.
17
     */
18
    public function __construct(WakatimeClient $client)
19
    {
20
        $this->client = $client;
21
    }
22
23
    public function setApiKey(string $apiKey)
24
    {
25
        $this->client->setApiKey($apiKey);
26
27
        return $this;
28
    }
29
30
    public function getApiKey() : string
31
    {
32
         return $this->client->getApiKey();
33
    }
34
35
    public function getBaseUrl() : string
36
    {
37
        return $this->client->getBaseUrl();
38
    }
39
40
    public function setBaseUrl(string $baseUrl)
41
    {
42
        $this->client->setBaseUrl($baseUrl);
43
44
        return $this;
45
    }
46
47
    /**
48
     * Fetches the User's durations for the specified Date
49
     *
50
     *
51
     * @param  DateTime $date
52
     * @param  string   $user
53
     * @param  array    $optionalQuery
54
     *         project  (optional) Only show duration for this project
55
     *         branches (optional) Only show durations for these branches:
56
     *                             comma separated list of branch names
57
     * @return Collection
58
     */
59
    public function fetchUserDurations(DateTime $date, string $user = 'current', array $optionalQuery = []) : Collection
60
    {
61
        $query = array_merge([
62
            'date' => $date->format('Y-m-d'), $optionalQuery]);
63
64
        return $this->performRequest("users/{$user}/durations", $query, []);
65
    }
66
67
68
    public function performRequest($resource, array $query = [], array $headers = [])
69
    {
70
        return $this->client->performRequest($resource, $headers, $query);
71
    }
72
73
}
74