BasicAuthenticationAdapterFactory::createService()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 16
Ratio 100 %
Metric Value
dl 16
loc 16
rs 9.4285
cc 2
eloc 9
nc 2
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
/**
11
 * @author Stanimir Dimitrov Dimitrov <[email protected]>
12
 */
13 View Code Duplication
class BasicAuthenticationAdapterFactory 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...
14
{
15
    /** @var array|object|string $basicConfig */
16
    private $basicConfig = [];
17
18
    /**
19
     * @param array|object|string $basicConfig
20
     */
21
    public function __construct(array $basicConfig = [])
22
    {
23
        $this->basicConfig = $basicConfig;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function createService(ServiceLocatorInterface $basicServiceLocator)
30
    {
31
        if (empty($this->basicConfig)) {
32
            $this->basicConfig = $basicServiceLocator->get('Config');
33
        }
34
35
        $authBasicConfig = $this->basicConfig['authentication_basic']['adapter'];
36
        $authBasicAdapter = new HttpAdapter($authBasicConfig['config']);
37
38
        $basic = new FileResolver();
39
        $basic->setFile($authBasicConfig['basic']);
40
41
        $authBasicAdapter->setBasicResolver($basic);
42
43
        return $authBasicAdapter;
44
    }
45
}
46