Passed
Push — master ( f4d59e...ca3fd6 )
by Chris
03:34
created

GoogleAnalyticsFactory::getTrackingId()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 3
nop 1
dl 0
loc 11
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace OpenTickets\GoogleAnalytics\View\Helper;
6
7
use Zend\ServiceManager\AbstractPluginManager;
8
use Zend\ServiceManager\ServiceLocatorInterface;
9
10
final class GoogleAnalyticsFactory
11
{
12
    public function __invoke(AbstractPluginManager $pluginManager)
13
    {
14
        $trackingId = $this->getTrackingId($pluginManager->getServiceLocator());
15
16
        return new GoogleAnalytics($trackingId);
17
    }
18
19
    private function getTrackingId(ServiceLocatorInterface $serviceLocator): string
20
    {
21
        if (!$serviceLocator->has('config')) {
22
            return '';
23
        }
24
        $config = $serviceLocator->get('Config');
25
        if (!isset($config['google_analytics']['tracking_id']) || !is_string($config['google_analytics']['tracking_id'])) {
26
            return '';
27
        }
28
        return $config['google_analytics']['tracking_id'];
29
    }
30
}
31