HttpExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 33
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A secureClient() 0 2 1
A secureRequest() 0 11 3
A __construct() 0 3 1
1
<?php
2
3
namespace Knp\FriendlyContexts\Http\Security;
4
5
use Guzzle\Http\Client;
6
use Guzzle\Http\Message\Request;
7
use Knp\FriendlyContexts\Builder\RequestBuilder;
8
9
class HttpExtension extends HttpBasicExtension implements SecurityExtensionInterface
0 ignored issues
show
Deprecated Code introduced by
The class Knp\FriendlyContexts\Htt...rity\HttpBasicExtension has been deprecated: use HttpExtension. Will be removed in v1.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

9
class HttpExtension extends /** @scrutinizer ignore-deprecated */ HttpBasicExtension implements SecurityExtensionInterface
Loading history...
10
{
11
    protected $schema;
12
13
    /**
14
     * @param string $scheme (allowed values: basic, digest, ntlm, any)
15
     */
16
    public function __construct($scheme = 'basic')
17
    {
18
        $this->scheme = $scheme;
0 ignored issues
show
Bug Best Practice introduced by
The property scheme does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function secureClient(Client $client, RequestBuilder $builder)
25
    {
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function secureRequest(Request $request, RequestBuilder $builder)
32
    {
33
        $credentials = $builder->getCredentials();
34
35
        if (!isset($credentials['username']) || !isset($credentials['password'])) {
36
            throw new \RuntimeException(
37
                'You must specified a "username" and a "password" for the http basic authentication.'
38
            );
39
        }
40
41
        $request->setAuth($credentials['username'], $credentials['password'], $this->scheme);
42
    }
43
}
44