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

Oauth2BaseMigration::getColumnSchemaBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 16
ccs 15
cts 15
cp 1
rs 9.9666
cc 1
nc 1
nop 1
crap 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