GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 31523c...8f74c0 )
by Christian
03:09
created

AbstractService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 56
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A call() 0 10 3
A toDateString() 0 8 2
1
<?php
2
3
/*
4
 * (c) Christian Gripp <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Core23\SetlistFm\Service;
11
12
use Core23\SetlistFm\Connection\ConnectionInterface;
13
use Core23\SetlistFm\Exception\ApiException;
14
use Core23\SetlistFm\Exception\NotFoundException;
15
16
abstract class AbstractService
17
{
18
    /**
19
     * @var ConnectionInterface
20
     */
21
    private $connection;
22
23
    /**
24
     * AbstractService constructor.
25
     *
26
     * @param ConnectionInterface $connection
27
     */
28
    public function __construct(ConnectionInterface $connection)
29
    {
30
        $this->connection = $connection;
31
    }
32
33
    /**
34
     * Calls the API unsigned.
35
     *
36
     * @param string $method
37
     * @param array  $params
38
     * @param string $requestMethod
39
     *
40
     * @return array
41
     *
42
     * @throws ApiException
43
     * @throws NotFoundException
44
     */
45
    final protected function call(string $method, array $params = array(), $requestMethod = 'GET'): array
46
    {
47
        foreach ($params as $key => $value) {
48
            if ($value instanceof \DateTime) {
49
                $params[$key] = $this->toDateString($value);
50
            }
51
        }
52
53
        return $this->connection->call($method, $params, $requestMethod);
54
    }
55
56
    /**
57
     * Formats a date to a timestamp.
58
     *
59
     * @param \DateTime|null $date
60
     *
61
     * @return string|null
62
     */
63
    private function toDateString(\DateTime $date = null) : ?string
64
    {
65
        if (null === $date) {
66
            return null;
67
        }
68
69
        return $date->format('d-m-Y');
70
    }
71
}
72