Completed
Push — Feature-GoogleAnalyticsOptout ( 12176c...39c6dd )
by
unknown
01:53
created

functions.php ➔ init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Flynt\Features\GoogleAnalytics;
4
5
require_once __DIR__ . '/GoogleAnalytics.php';
6
7
use Flynt\Features\GoogleAnalytics\GoogleAnalytics;
8
use Flynt\Utils\Feature;
9
use Flynt\Utils\Asset;
10
use Flynt\Features\Acf\OptionPages;
11
12
add_action('init', 'Flynt\Features\GoogleAnalytics\init', 100);
13
14
function init()
15
{
16
    $googleAnalyticsOptions = OptionPages::get('globalOptions', 'feature', 'GoogleAnalytics');
17
    $googleAnalyticsOptionsTranslatable = OptionPages::get('translatableOptions', 'feature', 'GoogleAnalytics');
0 ignored issues
show
Unused Code introduced by
$googleAnalyticsOptionsTranslatable is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
18
19
    if ($googleAnalyticsOptions) {
20
        new GoogleAnalytics($googleAnalyticsOptions);
21
    }
22
}
23
24
add_action('wp_enqueue_scripts', function () {
25
    $gaOptions = OptionPages::get('globalOptions', 'feature', 'GoogleAnalytics');
26
    $gaOptionsTranslatable = OptionPages::get('translatableOptions', 'feature', 'GoogleAnalytics');
27
28
    Asset::enqueue([
29
        'type' => 'script',
30
        'name' => 'js-cookie',
31
        'path' => 'vendor/js-cookie.js'
32
    ]);
33
34
    Asset::enqueue([
35
        'type' => 'script',
36
        'name' => 'Flynt/Features/GoogleAnalytics',
37
        'path' => 'Features/GoogleAnalytics/script.js',
38
        'dependencies' => ['jquery', 'js-cookie']
39
    ]);
40
41
    $data = [
42
        'gaId' => $gaOptions['gaId'],
43
        'confirm' => $gaOptionsTranslatable['optOutConfirm'],
44
        'success' => $gaOptionsTranslatable['optOutSuccess']
45
    ];
46
    wp_localize_script('Flynt/Features/GoogleAnalytics', 'dataFlyntFeatureGoogleAnalytics', $data);
47
}, 100);
48