DisqusFactory::createDisqusHelper()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 17
c 0
b 0
f 0
ccs 9
cts 9
cp 1
rs 9.4285
cc 3
eloc 9
nc 3
nop 1
crap 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