Passed
Push — master ( a9546d...6aabd8 )
by Paul
05:58
created

Migrate_4_5_0::migrateOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules\Migrations;
4
5
use GeminiLabs\SiteReviews\Controllers\NoticeController;
6
use GeminiLabs\SiteReviews\Database\OptionManager;
7
use GeminiLabs\SiteReviews\Helpers\Arr;
8
9
class Migrate_4_5_0
10
{
11
    /**
12
     * @return void
13
     */
14 1
    public function migrateOptions()
15
    {
16 1
        $isAccountVerified = glsr(OptionManager::class)->getWP('_glsr_rebusify', false);
17 1
        update_option('_glsr_trustalyze', $isAccountVerified);
18 1
        delete_option('_glsr_rebusify');
19 1
    }
20
21
    /**
22
     * @return void
23
     */
24 1
    public function migrateSettings()
25
    {
26 1
        if ($settings = get_option(OptionManager::databaseKey(4))) {
27 1
            $settings = Arr::set($settings, 'settings.general.trustalyze',
28 1
                Arr::get($settings, 'settings.general.rebusify')
29
            );
30 1
            $settings = Arr::set($settings, 'settings.general.trustalyze_email',
31 1
                Arr::get($settings, 'settings.general.rebusify_email')
32
            );
33 1
            $settings = Arr::set($settings, 'settings.general.trustalyze_serial',
34 1
                Arr::get($settings, 'settings.general.rebusify_serial')
35
            );
36 1
            unset($settings['settings']['general']['rebusify']);
37 1
            unset($settings['settings']['general']['rebusify_email']);
38 1
            unset($settings['settings']['general']['rebusify_serial']);
39 1
            update_option(OptionManager::databaseKey(4), $settings);
40
        }
41 1
    }
42
43
    /**
44
     * @return void
45
     */
46 1
    public function migrateUserMeta()
47
    {
48 1
        $metaKey = NoticeController::USER_META_KEY;
49 1
        $userIds = get_users([
50 1
            'fields' => 'ID',
51 1
            'meta_compare' => 'EXISTS',
52 1
            'meta_key' => $metaKey,
53
        ]);
54 1
        foreach ($userIds as $userId) {
55
            $meta = get_user_meta($userId, $metaKey, true);
56
            if (array_key_exists('rebusify', $meta)) {
0 ignored issues
show
Bug introduced by
It seems like $meta can also be of type false and string; however, parameter $search of array_key_exists() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

56
            if (array_key_exists('rebusify', /** @scrutinizer ignore-type */ $meta)) {
Loading history...
57
                $meta['trustalyze'] = $meta['rebusify'];
58
                unset($meta['rebusify']);
59
                update_user_meta($userId, $metaKey, $meta);
60
            }
61
        }
62 1
    }
63
64
    /**
65
     * @return void
66
     */
67 1
    public function run()
68
    {
69 1
        $this->migrateOptions();
70 1
        $this->migrateSettings();
71 1
        $this->migrateUserMeta();
72 1
    }
73
}
74