HttpExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 34.29 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 12
loc 35
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
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
class HttpExtension extends HttpBasicExtension implements SecurityExtensionInterface
0 ignored issues
show
Deprecated Code introduced by
The class Knp\FriendlyContexts\Htt...rity\HttpBasicExtension has been deprecated with message: use HttpExtension. Will be removed in v1.0.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

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 introduced by
The property scheme does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function secureClient(Client $client, RequestBuilder $builder)
25
    {
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 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...
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