ServicesTrait::getGa4()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * Instant Analytics plugin for Craft CMS
4
 *
5
 * Instant Analytics brings full Google Analytics support to your Twig templates
6
 *
7
 * @link      https://nystudio107.com
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) 2022 nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
10
11
namespace nystudio107\instantanalyticsGa4\services;
12
13
use nystudio107\instantanalyticsGa4\assetbundles\instantanalytics\InstantAnalyticsAsset;
14
use nystudio107\instantanalyticsGa4\services\Commerce as CommerceService;
15
use nystudio107\pluginvite\services\VitePluginService;
16
use yii\base\InvalidConfigException;
17
18
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
19
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
20
 * @package   InstantAnalytics
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
21
 * @since     4.0.0
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
22
 *
23
 * @property Ga4 $ga4
24
 * @property CommerceService $commerce
25
 * @property VitePluginService $vite
26
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
27
trait ServicesTrait
28
{
29
    // Public Static Methods
30
    // =========================================================================
31
32
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
33
     * @inheritdoc
34
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
35
    public static function config(): array
36
    {
37
        // Constants aren't allowed in traits until PHP >= 8.2, and config() is called before __construct(),
38
        // so we can't extract it from the passed in $config
39
        $majorVersion = '4';
40
        // Dev server container name & port are based on the major version of this plugin
41
        $devPort = 3000 + (int)$majorVersion;
42
        $versionName = 'v' . $majorVersion;
43
        return [
44
            'components' => [
45
                'ga4' => Ga4::class,
46
                'commerce' => CommerceService::class,
47
                // Register the vite service
48
                'vite' => [
49
                    'assetClass' => InstantAnalyticsAsset::class,
50
                    'checkDevServer' => true,
51
                    'class' => VitePluginService::class,
52
                    'devServerInternal' => 'http://craft-instantanalytics-ga4-' . $versionName . '-buildchain-dev:' . $devPort,
53
                    'devServerPublic' => 'http://localhost:' . $devPort,
54
                    'errorEntry' => 'src/js/app.ts',
55
                    'useDevServer' => true,
56
                ],
57
            ],
58
        ];
59
    }
60
61
    // Public Methods
62
    // =========================================================================
63
64
    /**
65
     * Returns the GA4 service
66
     *
67
     * @return Ga4 The GA4 service
68
     * @throws InvalidConfigException
69
     */
70
    public function getGa4(): Ga4
71
    {
72
        return $this->get('ga4');
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

72
        return $this->/** @scrutinizer ignore-call */ get('ga4');
Loading history...
73
    }
74
75
    /**
76
     * Returns the commerce service
77
     *
78
     * @return CommerceService The commerce service
79
     * @throws InvalidConfigException
80
     */
81
    public function getCommerce(): CommerceService
82
    {
83
        return $this->get('commerce');
84
    }
85
86
    /**
87
     * Returns the vite service
88
     *
89
     * @return VitePluginService The vite service
90
     * @throws InvalidConfigException
91
     */
92
    public function getVite(): VitePluginService
93
    {
94
        return $this->get('vite');
95
    }
96
}
97