m200925_135118_refactor_oauth_provider_options   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 39
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A safeDown() 0 4 1
A safeUp() 0 23 4
1
<?php
2
3
namespace dukt\videos\migrations;
4
5
use Craft;
6
use craft\db\Migration;
7
use craft\helpers\ProjectConfig;
8
9
/**
10
 * m200925_135118_refactor_oauth_provider_options migration.
11
 */
12
class m200925_135118_refactor_oauth_provider_options extends Migration
13
{
14
    /**
15
     * @inheritdoc
16
     */
17
    public function safeUp()
18
    {
19
        $projectConfig = Craft::$app->projectConfig;
20
21
        // Don't make the same config changes twice
22
        $schemaVersion = $projectConfig->get('plugins.videos.schemaVersion', true);
0 ignored issues
show
Bug introduced by
The method get() 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

22
        /** @scrutinizer ignore-call */ 
23
        $schemaVersion = $projectConfig->get('plugins.videos.schemaVersion', true);

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...
23
24
        if (version_compare($schemaVersion, '1.0.3', '<')) {
25
            // Get OAuth provider options
26
            $oauthProviderOptions = $projectConfig->get('plugins.videos.settings.oauthProviderOptions', true);
27
28
            if (!is_array($oauthProviderOptions)) {
29
                return true;
30
            }
31
32
            $oauthProviderOptions = ProjectConfig::unpackAssociativeArray($oauthProviderOptions);
33
34
            // Reset OAuth provider options
35
            $projectConfig->set('plugins.videos.settings.oauthProviderOptions', [], "Reset the oauth provider options");
36
37
            // Rebuild OAuth provider options
38
            foreach ($oauthProviderOptions as $providerHandle => $provider) {
39
                $projectConfig->set('plugins.videos.settings.oauthProviderOptions.' . $providerHandle, $provider, sprintf('Save the ā€œ%sā€ provider', $providerHandle));
40
            }
41
        }
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function safeDown(): bool
48
    {
49
        echo "m200925_135118_refactor_oauth_provider_options cannot be reverted.\n";
50
        return false;
51
    }
52
}
53