DigestAuthenticationAdapterFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A createService() 16 16 2

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 LearnZF2Authentication\Factory;
4
5
use Zend\Authentication\Adapter\Http as HttpAdapter;
6
use Zend\Authentication\Adapter\Http\FileResolver;
7
use Zend\ServiceManager\FactoryInterface;
8
use Zend\ServiceManager\ServiceLocatorInterface;
9
10 View Code Duplication
class DigestAuthenticationAdapterFactory implements FactoryInterface
0 ignored issues
show
Duplication introduced by
This class 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...
11
{
12
    /** @var array|object|string $digestConfig */
13
    private $digestConfig = [];
14
15
    /**
16
     * @param array|object|string $digestConfig
17
     */
18
    public function __construct(array $digestConfig = [])
19
    {
20
        $this->digestConfig = $digestConfig;
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function createService(ServiceLocatorInterface $digestServiceLocator)
27
    {
28
        if (empty($this->digestConfig)) {
29
            $this->digestConfig = $digestServiceLocator->get('Config');
30
        }
31
32
        $authDigestConfig = $this->digestConfig['authentication_digest']['adapter'];
33
        $authDigestAdapter = new HttpAdapter($authDigestConfig['config']);
34
35
        $digest = new FileResolver();
36
        $digest->setFile($authDigestConfig['digest']);
37
38
        $authDigestAdapter->setDigestResolver($digest);
39
40
        return $authDigestAdapter;
41
    }
42
}
43