Skip to content

Commit

Permalink
Load column properties via constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Oct 18, 2024
1 parent 5171ad7 commit c03e064
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/Column/ColumnBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ final class ColumnBuilder extends \Yiisoft\Db\Schema\Column\ColumnBuilder
{
public static function binary(int|null $size = null): ColumnSchemaInterface
{
return (new BinaryColumnSchema(ColumnType::BINARY))
->size($size);
return new BinaryColumnSchema(ColumnType::BINARY, size: $size);
}
}
11 changes: 7 additions & 4 deletions src/Column/ColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Schema\Column\AbstractColumnFactory;
use Yiisoft\Db\Schema\Column\ColumnSchemaInterface;
use Yiisoft\Db\Schema\Column\StringColumnSchema;

final class ColumnFactory extends AbstractColumnFactory
{
Expand Down Expand Up @@ -76,9 +77,11 @@ protected function getType(string $dbType, array $info = []): string
public function fromPseudoType(string $pseudoType, array $info = []): ColumnSchemaInterface
{
if ($pseudoType === PseudoType::UUID_PK_SEQ) {
return ColumnBuilder::uuidPrimaryKey()
->defaultValue(new Expression('newsequentialid()'))
->load($info);
$info['primaryKey'] = true;
$info['autoIncrement'] = true;
$info['defaultValue'] = new Expression('newsequentialid()');

return new StringColumnSchema(ColumnType::UUID, ...$info);

Check failure on line 84 in src/Column/ColumnFactory.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

InvalidNamedArgument

src/Column/ColumnFactory.php:84:61: InvalidNamedArgument: Parameter $type has already been used in Yiisoft\Db\Schema\Column\StringColumnSchema::__construct (see https://psalm.dev/238)

Check failure on line 84 in src/Column/ColumnFactory.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

InvalidNamedArgument

src/Column/ColumnFactory.php:84:61: InvalidNamedArgument: Parameter $type has already been used in Yiisoft\Db\Schema\Column\StringColumnSchema::__construct (see https://psalm.dev/238)
}

return parent::fromPseudoType($pseudoType, $info);
Expand All @@ -87,7 +90,7 @@ public function fromPseudoType(string $pseudoType, array $info = []): ColumnSche
public function fromType(string $type, array $info = []): ColumnSchemaInterface
{
if ($type === ColumnType::BINARY) {
return (new BinaryColumnSchema($type))->load($info);
return new BinaryColumnSchema($type, ...$info);

Check failure on line 93 in src/Column/ColumnFactory.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

InvalidNamedArgument

src/Column/ColumnFactory.php:93:50: InvalidNamedArgument: Parameter $type has already been used in Yiisoft\Db\Mssql\Column\BinaryColumnSchema::__construct (see https://psalm.dev/238)

Check failure on line 93 in src/Column/ColumnFactory.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

InvalidNamedArgument

src/Column/ColumnFactory.php:93:50: InvalidNamedArgument: Parameter $type has already been used in Yiisoft\Db\Mssql\Column\BinaryColumnSchema::__construct (see https://psalm.dev/238)
}

return parent::fromType($type, $info);
Expand Down
2 changes: 1 addition & 1 deletion src/Dsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class Dsn extends AbstractDsn
*/
public function __construct(
string $driver = 'sqlsrv',
string $host = 'localhost',
string $host = '127.0.0.1',
string|null $databaseName = null,
string|null $port = '1433',
array $options = []
Expand Down

0 comments on commit c03e064

Please sign in to comment.