DisqusFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 27
c 0
b 0
f 0
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 6 1
A createDisqusHelper() 0 17 3
1
<?php
2
/**
3
 * This file is part of the ZfDisqus Module package.
4
 *
5
 * Copyright (c) Nikola Posa <[email protected]>
6
 *
7
 * For full copyright and license information, please refer to the LICENSE file,
8
 * located at the package root folder.
9
 */
10
11
declare(strict_types=1);
12
13
namespace ZfDisqus\View\Helper;
14
15
use DisqusHelper\Disqus as DisqusHelper;
16
use Interop\Container\ContainerInterface;
17
use ZfDisqus\Exception\DisqusConfigurationNotProvidedException;
18
19
final class DisqusFactory
20
{
21 3
    public function __invoke(ContainerInterface $container) : Disqus
22
    {
23 3
        $config = $container->get('config');
24
25 3
        return new Disqus($this->createDisqusHelper($config['disqus'] ?? []));
26
    }
27
28 3
    private function createDisqusHelper(array $config) : DisqusHelper
29
    {
30 3
        if (!isset($config['shortname'])) {
31 1
            throw new DisqusConfigurationNotProvidedException('Disqus shortname must be provided through the `disqus` -> `shortname` configuration option');
32
        }
33
34 2
        $shortName = $config['shortname'];
35 2
        unset($config['shortname']);
36
37 2
        $disqusHelper = DisqusHelper::create($shortName);
38
39 2
        if (!empty($config)) {
40 1
            $disqusHelper->configure($config);
41
        }
42
43 2
        return $disqusHelper;
44
    }
45
}
46