HttpBasicExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 6
c 1
b 0
f 0
dl 0
loc 17
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A secureClient() 0 2 1
A secureRequest() 0 11 3
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
/**
10
 * @deprecated use HttpExtension. Will be removed in v1.0.0
11
 */
12
class HttpBasicExtension implements SecurityExtensionInterface
13
{
14
   public function secureClient(Client $client, RequestBuilder $builder)
15
   {
16
   }
17
18
    public function secureRequest(Request $request, RequestBuilder $builder)
19
    {
20
        $credentials = $builder->getCredentials();
21
22
        if (!isset($credentials['username']) || !isset($credentials['password'])) {
23
            throw new \RuntimeException(
24
                'You must specified a "username" and a "password" for the http basic authentication.'
25
            );
26
        }
27
28
        $request->setAuth($credentials['username'], $credentials['password']);
29
    }
30
}
31