StatcounterModule::bodyContent()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * webtrees: online genealogy
5
 * Copyright (C) 2025 webtrees development team
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
 */
17
18
declare(strict_types=1);
19
20
namespace Fisharebest\Webtrees\Module;
21
22
use Fisharebest\Webtrees\I18N;
0 ignored issues
show
Bug introduced by
The type Fisharebest\Webtrees\I18N 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...
23
24
/**
25
 * Class StatcounterModule - add support for statcounter.
26
 */
27
class StatcounterModule extends AbstractModule implements ModuleAnalyticsInterface, ModuleConfigInterface, ModuleExternalUrlInterface, ModuleGlobalInterface
28
{
29
    use ModuleAnalyticsTrait;
30
    use ModuleConfigTrait;
31
    use ModuleExternalUrlTrait;
32
    use ModuleGlobalTrait;
33
34
    public function title(): string
35
    {
36
        return I18N::translate('Statcounter™');
37
    }
38
39
    public function isEnabledByDefault(): bool
40
    {
41
        return false;
42
    }
43
44
    /**
45
     * Form fields to edit the parameters.
46
     *
47
     * @return string
48
     */
49
    public function analyticsFormFields(): string
50
    {
51
        return view('modules/statcounter/form', $this->analyticsParameters());
52
    }
53
54
    /**
55
     * Home page for the service.
56
     *
57
     * @return string
58
     */
59
    public function externalUrl(): string
60
    {
61
        return 'https://statcounter.com';
62
    }
63
64
    /**
65
     * The parameters that need to be embedded in the snippet.
66
     *
67
     * @return array<string>
68
     */
69
    public function analyticsParameters(): array
70
    {
71
        return [
72
            'STATCOUNTER_PROJECT_ID' => $this->getPreference('STATCOUNTER_PROJECT_ID'),
73
            'STATCOUNTER_SECURITY_ID' => $this->getPreference('STATCOUNTER_SECURITY_ID'),
74
        ];
75
    }
76
77
    /**
78
     * Embed placeholders in the snippet.
79
     *
80
     * @param array<string> $parameters
81
     *
82
     * @return string
83
     */
84
    public function analyticsSnippet(array $parameters): string
85
    {
86
        return view('modules/statcounter/snippet', $parameters);
87
    }
88
89
    /**
90
     * Raw content, to be added at the end of the <body> element.
91
     * Typically, this will be <script> elements.
92
     *
93
     * @return string
94
     */
95
    public function bodyContent(): string
96
    {
97
        if ($this->analyticsCanShow()) {
98
            return $this->analyticsSnippet($this->analyticsParameters());
99
        }
100
101
        return '';
102
    }
103
}
104