Passed
Push — develop-v4 ( 477347...f45251 )
by Andrew
19:02 queued 09:04
created

m230601_184259_announcement_google_ua_deprecated   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 20
c 1
b 0
f 0
dl 0
loc 41
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A safeDown() 0 4 1
A safeUp() 0 27 5
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 craft\i18n\Translation;
10
use nystudio107\seomatic\models\MetaScriptContainer;
11
use nystudio107\seomatic\services\MetaBundles;
12
13
/**
14
 * m230601_184259_announcement_google_ua_deprecated migration.
15
 */
16
class m230601_184259_announcement_google_ua_deprecated extends Migration
17
{
18
    /**
19
     * @inheritdoc
20
     */
21
    public function safeUp(): bool
22
    {
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
                            Translation::prep('seomatic', 'Google Universal Analytics deprecated', []),
37
                            Translation::prep('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..', [
38
                                'url' => 'https://support.google.com/analytics/answer/11583528',
39
                            ]),
40
                            'seomatic'
41
                        );
42
                    }
43
                }
44
            }
45
        }
46
47
        return true;
48
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53
    public function safeDown(): bool
54
    {
55
        echo "m230601_184259_announcement_google_ua_deprecated cannot be reverted.\n";
56
        return false;
57
    }
58
}
59