SchemaBuilderTrait::enum()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\Mariadb;
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\Mariadb
21
 *
22
 * @mixin \yii\db\Migration
23
 */
24
trait SchemaBuilderTrait
25
{
26
    use EnumTrait;
27
28
    /**
29
     * @param array|string|Enum $values
30
     *
31
     * @return db\ColumnSchemaBuilder
32
     * @throws \yii\base\NotSupportedException
33
     */
34
    public function enum($values): db\ColumnSchemaBuilder
35
    {
36
        return $this->getDb()
37
            ->getSchema()
38
            ->createColumnSchemaBuilder(
39
                $this->formatEnumValues(
40
                    $this->fetchEnums($values)
0 ignored issues
show
Documentation introduced by
$this->fetchEnums($values) is of type array, but the function expects a object<Kartavik\Yii2\Database\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
41
                )
42
            );
43
    }
44
}
45