Passed
Push — master ( 11b010...ea8435 )
by Evgenii
01:20
created

AdminBar::extendMenu()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 33
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 21
nc 3
nop 1
dl 0
loc 33
rs 9.584
c 0
b 0
f 0
1
<?php
2
3
namespace Helick\GTM;
4
5
use Helick\GTM\Contracts\Bootable;
6
use RecursiveArrayIterator;
7
use RecursiveIteratorIterator;
8
use WP_Admin_Bar;
0 ignored issues
show
Bug introduced by
The type WP_Admin_Bar was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
final class AdminBar implements Bootable
11
{
12
    /**
13
     * Boot the service.
14
     *
15
     * @return void
16
     */
17
    public static function boot(): void
18
    {
19
        $self = new static;
20
21
        add_action('admin_bar_menu', [$self, 'extendMenu']);
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

21
        /** @scrutinizer ignore-call */ 
22
        add_action('admin_bar_menu', [$self, 'extendMenu']);
Loading history...
22
    }
23
24
    /**
25
     * Extend the admin bar menu.
26
     *
27
     * @param WP_Admin_Bar $adminBar
28
     *
29
     * @return void
30
     */
31
    public function extendMenu(WP_Admin_Bar $adminBar): void
32
    {
33
        $isUserAllowed = current_user_can('manage_options');
0 ignored issues
show
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        $isUserAllowed = /** @scrutinizer ignore-call */ current_user_can('manage_options');
Loading history...
34
        $isBackend     = is_admin();
0 ignored issues
show
Bug introduced by
The function is_admin was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        $isBackend     = /** @scrutinizer ignore-call */ is_admin();
Loading history...
35
36
        if (!$isUserAllowed || $isBackend) {
37
            return;
38
        }
39
40
        $adminBar->add_menu([
41
            'id'    => 'helick-gtm',
42
            'title' => sprintf(
43
                '<span class="ab-icon dashicons-filter"></span> <span class="ab-label">%s</span>',
44
                __('Data Layer', DOMAIN)
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
                /** @scrutinizer ignore-call */ 
45
                __('Data Layer', DOMAIN)
Loading history...
45
            ),
46
        ]);
47
48
        $dataLayer = dataLayer();
49
50
        // Flatten data layer
51
        $iterator = new RecursiveArrayIterator($dataLayer);
52
        $iterator = new RecursiveIteratorIterator($iterator);
53
54
        $dataLayer = iterator_to_array($iterator);
55
56
        foreach ($dataLayer as $key => $value) {
57
            $adminBar->add_node([
58
                'id'     => sanitize_key('helick-gtm-' . $key),
0 ignored issues
show
Bug introduced by
The function sanitize_key was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
                'id'     => /** @scrutinizer ignore-call */ sanitize_key('helick-gtm-' . $key),
Loading history...
59
                'parent' => 'helick-gtm',
60
                'title'  => sprintf(
61
                    '<span style="font-weight: bold">%s:</span> %s',
62
                    $key,
63
                    esc_html($value)
0 ignored issues
show
Bug introduced by
The function esc_html was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
                    /** @scrutinizer ignore-call */ 
64
                    esc_html($value)
Loading history...
64
                ),
65
            ]);
66
        }
67
    }
68
}
69