SchemaBuilderTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A enum() 0 18 3
1
<?php
2
3
/**
4
 * @author Roman Varkuta <[email protected]>
5
 * @license MIT
6
 * @see https://github.com/myclabs/php-enum PHP enum implementation
7
 * @version 1.0
8
 */
9
10
declare(strict_types=1);
11
12
namespace Kartavik\Yii2\Database\Pgsql;
13
14
use Kartavik\Yii2\Database\EnumTrait;
15
use MyCLabs\Enum\Enum;
16
use yii\db;
17
18
/**
19
 * Trait SchemaBuilderTrait
20
 * @package Kartavik\Yii2\Database\Pgsql
21
 *
22
 * @mixin \yii\db\Migration
23
 */
24
trait SchemaBuilderTrait
25
{
26
    use EnumTrait;
27
28
    /**
29
     * @param string $name
30
     * @param array|Enum|string|null $values
31
     *
32
     * @return db\ColumnSchemaBuilder
33
     * @throws \yii\base\NotSupportedException
34
     */
35
    public function enum(string $name, $values = null): db\ColumnSchemaBuilder
36
    {
37
        $values = $this->fetchEnums($values);
38
39
        if (!empty($values)) {
40
            $this->addEnum($name, $values);
0 ignored issues
show
Bug introduced by
It seems like addEnum() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
41
        }
42
43
        $column = $this->getDb()->getSchema()->createColumnSchemaBuilder($name);
44
45
        if (\in_array(null, $values, true)) {
46
            $column->null();
47
        } else {
48
            $column->notNull();
49
        }
50
51
        return $column;
52
    }
53
}
54