Passed
Push — v3 ( 432ffb...f9ff88 )
by Andrew
40:19 queued 27:54
created

m230601_184311_announcement_google_ua_deprecated   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 23
c 1
b 0
f 0
dl 0
loc 45
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A safeDown() 0 4 1
B safeUp() 0 25 6
1
<?php
2
3
namespace nystudio107\seomatic\migrations;
4
5
use Craft;
6
use craft\db\Migration;
7
use craft\db\Query;
8
use craft\helpers\Json;
9
use nystudio107\seomatic\models\MetaScriptContainer;
10
use nystudio107\seomatic\services\MetaBundles;
11
12
/**
13
 * m230601_184311_announcement_google_ua_deprecated migration.
14
 */
15
class m230601_184311_announcement_google_ua_deprecated extends Migration
16
{
17
    /**
18
     * @inheritdoc
19
     */
20
    public function safeUp()
21
    {
22
        if (version_compare(Craft::$app->getVersion(), '3.7', '>=')) {
23
            $globalBundles = (new Query())
24
                ->from(['{{%seomatic_metabundles}}'])
25
                ->where([
26
                    'sourceBundleType' => MetaBundles::GLOBAL_META_BUNDLE,
27
                ])
28
                ->all();
29
            foreach ($globalBundles as $globalBundle) {
30
                $metaContainers = Json::decodeIfJson($globalBundle['metaContainers']);
31
                foreach ($metaContainers as $metaContainer) {
32
                    if ($metaContainer['class'] === MetaScriptContainer::class) {
33
                        $enabled = $metaContainer['data']['googleAnalytics']['include'] ?? null;
34
                        if ($enabled) {
35
                            Craft::$app->announcements->push(
0 ignored issues
show
Bug introduced by
The method push() does not exist on null. ( Ignorable by Annotation )

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

35
                            Craft::$app->announcements->/** @scrutinizer ignore-call */ 
36
                                                        push(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
36
                                function ($language) {
37
                                    return Craft::t('seomatic', 'Google Universal Analytics deprecated', [], $language);
38
                                },
39
                                function ($language) {
40
                                    return Craft::t('seomatic', 'Universal Analytics (which is used on this site via the SEOmatic plugin) is being [discontinued on July 1st, 2023]({url}). You should use Google gtag.js or Google Tag Manager instead and transition to a new GA4 property.', [
41
                                        'url' => 'https://support.google.com/analytics/answer/11583528',
42
                                    ], $language);
43
                                },
44
                                'seomatic'
45
                            );
46
                        }
47
                    }
48
                }
49
            }
50
        }
51
    }
52
53
    /**
54
     * @inheritdoc
55
     */
56
    public function safeDown()
57
    {
58
        echo "m230601_184311_announcement_google_ua_deprecated cannot be reverted.\n";
59
        return false;
60
    }
61
}
62