Passed
Push — master ( c8e076...fbaea5 )
by Rutger
02:57
created

Oauth2BaseMigration   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 14
c 1
b 0
f 0
dl 0
loc 57
ccs 19
cts 19
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTableSchema() 0 3 1
A getTableName() 0 3 1
A getColumnSchemaBuilder() 0 16 1
1
<?php
2
3
namespace rhertogh\Yii2Oauth2Server\migrations\base;
4
5
use rhertogh\Yii2Oauth2Server\helpers\DiHelper;
6
use rhertogh\Yii2Oauth2Server\Oauth2Module;
7
use yii\base\InvalidConfigException;
8
use yii\db\ColumnSchema;
9
use yii\db\ColumnSchemaBuilder;
10
use yii\db\Migration;
11
use yii\db\Schema;
12
use yii\db\TableSchema;
13
14
abstract class Oauth2BaseMigration extends Migration
15
{
16
    public const RESTRICT = 'RESTRICT';
17
    public const CASCADE = 'CASCADE';
18
19
    /**
20
     * Determines if the migration should be generated for the current module configuration.
21
     * @param Oauth2Module $module
22
     * @return bool
23
     * @since 1.0.0
24
     */
25
    abstract public static function generationIsActive($module);
26
27
    /**
28
     * Get the table name for a model.
29
     * @param string $tableClass
30
     * @return string
31
     * @throws InvalidConfigException
32
     * @since 1.0.0
33
     */
34 1
    protected function getTableName($tableClass)
35
    {
36 1
        return call_user_func([DiHelper::getValidatedClassName($tableClass), 'tableName']);
37
    }
38
39
    /**
40
     * Get the table schema for a model.
41
     * @param string $tableClass
42
     * @return TableSchema
43
     * @throws InvalidConfigException
44
     * @since 1.0.0
45
     */
46 1
    protected function getTableSchema($tableClass)
47
    {
48 1
        return call_user_func([DiHelper::getValidatedClassName($tableClass), 'getTableSchema']);
49
    }
50
51
    /**
52
     * @param ColumnSchema $columnSchema
53
     * @return ColumnSchemaBuilder
54
     */
55 9
    protected function getColumnSchemaBuilder($columnSchema): ColumnSchemaBuilder
56
    {
57 9
        $typeFunction = str_replace(
58 9
            [
59 9
                Schema::TYPE_TINYINT,
60 9
                Schema::TYPE_SMALLINT,
61 9
                Schema::TYPE_BIGINT,
62 9
            ],
63 9
            [
64 9
                'tinyInteger',
65 9
                'smallInteger',
66 9
                'bigInteger',
67 9
            ],
68 9
            $columnSchema->type
69 9
        );
70 9
        return $this->{$typeFunction}();
71
    }
72
}
73