Notification Setup Error

We have detected an error in your notification set-up (Event-ID dab39dc24f564ec7bd4628d1305fd03c). Currently, we cannot inform you about inspection progress. Please check that the user 557058:bca11929-8c2d-43f2-8a82-c5416880d395 still has access to your repository or update the API account.

Completed
Pull Request — develop ( #41 )
by
unknown
27:26 queued 12:27
created

ApiVersionPlugin   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handleRequest() 0 9 2
1
<?php
2
3
namespace Bitbucket\API\Http\Plugin;
4
5
use Http\Client\Common\Plugin;
6
use Http\Promise\Promise;
7
use Psr\Http\Message\RequestInterface;
8
9
class ApiVersionPlugin implements Plugin
10
{
11
    /** @var string */
12
    private $version;
13
    /**
14
     * @param string $version
15
     */
16
    public function __construct($version)
17
    {
18
        $this->version = $version;
19
    }
20
21
    /**
22
     * @param RequestInterface $request
23
     * @param callable $next Next middleware in the chain, the request is passed as the first argument
24
     * @param callable $first First middleware in the chain, used to to restart a request
25
     *
26
     * @return Promise Resolves a PSR-7 Response or fails with an Http\Client\Exception (The same as HttpAsyncClient).
27
     */
28
    public function handleRequest(RequestInterface $request, callable $next, callable $first)
29
    {
30
        $uri = $request->getUri();
31
        if (strpos($uri->getPath(), '/' . $this->version) !== 0) {
32
            $request = $request->withUri($uri->withPath('/' . $this->version . $uri->getPath()));
33
        }
34
35
        return $next($request);
36
    }
37
}
38