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 ( c9bd98...b01a3a )
by Christian
06:56
created

AuthService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A createSession() 0 12 2
A createToken() 0 10 2
A getAuthUrl() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the ni-ju-san CMS.
5
 *
6
 * (c) Christian Gripp <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Core23\LastFm\Service;
13
14
use Core23\LastFm\Connection\ConnectionInterface;
15
use Core23\LastFm\Connection\Session;
16
use Core23\LastFm\Connection\SessionInterface;
17
use Core23\LastFm\Exception\ApiException;
18
use Core23\LastFm\Exception\NotFoundException;
19
20
final class AuthService extends AbstractService
21
{
22
    /**
23
     * @var string
24
     */
25
    private $authUrl;
26
27
    /**
28
     * AuthService constructor.
29
     *
30
     * @param ConnectionInterface $connection
31
     * @param string              $authUrl
32
     */
33
    public function __construct(ConnectionInterface $connection, $authUrl = 'http://www.last.fm/api/auth/')
34
    {
35
        parent::__construct($connection);
36
37
        $this->authUrl = $authUrl;
38
    }
39
40
41
    /**
42
     * Creates a new session from a token.
43
     *
44
     * @param string $token
45
     *
46
     * @return SessionInterface|null
47
     *
48
     * @throws ApiException
49
     * @throws NotFoundException
50
     */
51
    public function createSession($token)
52
    {
53
        $response = $this->signedCall('auth.getSession', array(
54
            'token' => $token,
55
        ));
56
57
        if ($response) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $response of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
58
            return new Session($response['session']['name'], $response['session']['key'], $response['session']['subscriber']);
59
        }
60
61
        return;
62
    }
63
64
    /**
65
     * Creates a new api token.
66
     *
67
     * @return string|false
68
     *
69
     * @throws ApiException
70
     * @throws NotFoundException
71
     */
72
    public function createToken()
73
    {
74
        $response = $this->signedCall('auth.getToken');
75
76
        if ($response) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $response of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
77
            return $response['token'];
78
        }
79
80
        return false;
81
    }
82
83
    /**
84
     * Return the auth url.
85
     *
86
     * @param string $callbackUrl
87
     *
88
     * @return string
89
     */
90
    public function getAuthUrl($callbackUrl)
91
    {
92
        return $this->authUrl . '?api_key=' . $this->connection->getApiKey() . '&cb=' . $callbackUrl;
93
    }
94
}
95