m210603_221000_add_gql_schema_components   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 12
c 0
b 0
f 0
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A safeDown() 0 5 1
A safeUp() 0 18 4
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace nystudio107\retour\migrations;
4
5
use Craft;
6
use craft\db\Migration;
7
8
/**
9
 * m210603_221000_add_gql_schema_components migration.
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
10
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @category tag in class comment
Loading history...
11
class m210603_221000_add_gql_schema_components extends Migration
0 ignored issues
show
Coding Style introduced by
Class name is not valid; consider M210603_221000_Add_Gql_Schema_Components instead
Loading history...
Coding Style introduced by
Class name must begin with a capital letter
Loading history...
12
{
13
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
14
     * @inheritdoc
15
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
16
    public function safeUp(): bool
17
    {
18
        // Don't make the same config changes twice
19
        $projectConfig = Craft::$app->getProjectConfig();
20
        $schemaVersion = $projectConfig->get('plugins.retour.schemaVersion', true);
21
22
        if (version_compare($schemaVersion, '3.0.10', '<')) {
23
            foreach ($projectConfig->get('graphql.schemas') ?? [] as $schemaUid => $schemaComponents) {
24
                if (isset($schemaComponents['scope'])) {
25
                    $scope = $schemaComponents['scope'];
26
                    $scope[] = 'retour.all:read';
27
28
                    $projectConfig->set("graphql.schemas.$schemaUid.scope", $scope);
29
                }
30
            }
31
        }
32
33
        return true;
34
    }
35
36
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
37
     * @inheritdoc
38
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
39
    public function safeDown(): bool
40
    {
41
        echo "m210603_221000_add_gql_schema_components cannot be reverted.\n";
42
        
43
        return false;
44
    }
45
}
46