Completed
Push — master ( 29bda6...e00326 )
by David
9s
created

AbstractService::determineRequestUriFromPath()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 19
nc 7
nop 2
1
<?php
2
3
namespace OAuth\Common\Service;
4
5
use OAuth\Common\Consumer\CredentialsInterface;
6
use OAuth\Common\Http\Client\ClientInterface;
7
use OAuth\Common\Http\Uri\Uri;
8
use OAuth\Common\Http\Uri\UriInterface;
9
use OAuth\Common\Exception\Exception;
10
use OAuth\Common\Storage\TokenStorageInterface;
11
12
/**
13
 * Abstract OAuth service, version-agnostic
14
 */
15
abstract class AbstractService implements ServiceInterface
16
{
17
    /** @var Credentials */
18
    protected $credentials;
19
20
    /** @var ClientInterface */
21
    protected $httpClient;
22
23
    /** @var TokenStorageInterface */
24
    protected $storage;
25
26
    /**
27
     * @param CredentialsInterface  $credentials
28
     * @param ClientInterface       $httpClient
29
     * @param TokenStorageInterface $storage
30
     */
31
    public function __construct(
32
        CredentialsInterface $credentials,
33
        ClientInterface $httpClient,
34
        TokenStorageInterface $storage
35
    ) {
36
        $this->credentials = $credentials;
0 ignored issues
show
Documentation Bug introduced by
It seems like $credentials of type object<OAuth\Common\Cons...r\CredentialsInterface> is incompatible with the declared type object<OAuth\Common\Service\Credentials> of property $credentials.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
37
        $this->httpClient = $httpClient;
38
        $this->storage = $storage;
39
    }
40
41
    /**
42
     * @param UriInterface|string $path
43
     * @param UriInterface        $baseApiUri
44
     *
45
     * @return UriInterface
46
     *
47
     * @throws Exception
48
     */
49
    protected function determineRequestUriFromPath($path, UriInterface $baseApiUri = null)
50
    {
51
        if ($path instanceof UriInterface) {
52
            $uri = $path;
53
        } elseif (stripos($path, 'http://') === 0 || stripos($path, 'https://') === 0) {
54
            $uri = new Uri($path);
55
        } else {
56
            if (null === $baseApiUri) {
57
                throw new Exception(
58
                    'An absolute URI must be passed to ServiceInterface::request as no baseApiUri is set.'
59
                );
60
            }
61
62
            $uri = clone $baseApiUri;
63
            if (false !== strpos($path, '?')) {
64
                $parts = explode('?', $path, 2);
65
                $path = $parts[0];
66
                $query = $parts[1];
67
                $uri->setQuery($query);
68
            }
69
70
            if ($path[0] === '/') {
71
                $path = substr($path, 1);
72
            }
73
74
            $uri->setPath($uri->getPath() . $path);
75
        }
76
77
        return $uri;
78
    }
79
80
    /**
81
     * Accessor to the storage adapter to be able to retrieve tokens
82
     *
83
     * @return TokenStorageInterface
84
     */
85
    public function getStorage()
86
    {
87
        return $this->storage;
88
    }
89
90
    /**
91
     * @return string
92
     */
93
    public function service()
94
    {
95
        // get class name without backslashes
96
        $classname = get_class($this);
97
98
        return preg_replace('/^.*\\\\/', '', $classname);
99
    }
100
}
101