for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @author Roman Varkuta <[email protected]>
* @license MIT
* @see https://github.com/myclabs/php-enum PHP enum implementation
* @version 1.0
*/
declare(strict_types=1);
namespace Kartavik\Yii2\Database\Pgsql;
use MyCLabs\Enum\Enum;
use yii\db;
* Trait MigrationTrait
* @package Kartavik\Yii2\Database\Pgsql
trait MigrationTrait
{
use SchemaBuilderTrait;
* @param string $name
* @param array|Enum|string $enums
*
* @throws db\Exception
public function addEnum(string $name, $enums): void
$transaction = $this->getDb()->beginTransaction();
$command = $transaction->db->createCommand(
"CREATE TYPE $name AS {$this->formatEnumValues($this->fetchEnums($enums))}"
$this->fetchEnums($enums)
array
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);
);
try {
echo " > create type $name ... ";
$command->execute();
echo 'done';
} catch (\Exception $exception) {
echo "already exist, skipping";
$transaction->rollBack();
}
echo PHP_EOL;
public function dropEnum(string $name): void
$this->getDb()->createCommand("DROP TYPE IF EXISTS $name")->execute();
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: