HttpBasicExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 63.16 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 12
loc 19
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A secureClient() 0 3 1
A secureRequest() 12 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
    public function secureRequest(Request $request, RequestBuilder $builder)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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