DigestAuthenticationAdapterFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %
Metric Value
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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