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

GoogleAnalyticsFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 6 1
A getTrackingId() 0 11 4
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