Skip to content

Commit

Permalink
Remove ColumnFactory from ColumnBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Sep 16, 2024
1 parent c3a584d commit 70fee23
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Enh #315: Raise minimum PHP version to `^8.1` with minor refactoring (@Tigrov)
- Enh #314: Implement `ColumnFactory` class (@Tigrov)
- Enh #317: Separate column type constants (@Tigrov)
- Enh #318: Realize `ColumnBuilder` class (@Tigrov)

## 1.2.0 March 21, 2024

Expand Down
6 changes: 0 additions & 6 deletions src/Column/ColumnBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@

namespace Yiisoft\Db\Sqlite\Column;

use Yiisoft\Db\Schema\Column\ColumnFactoryInterface;

final class ColumnBuilder extends \Yiisoft\Db\Schema\Column\ColumnBuilder
{
public static function columnFactory(): ColumnFactoryInterface
{
return new ColumnFactory();
}
}
7 changes: 4 additions & 3 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
use Yiisoft\Db\Driver\Pdo\AbstractPdoConnection;
use Yiisoft\Db\Driver\Pdo\PdoCommandInterface;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
use Yiisoft\Db\Schema\Column\ColumnFactoryInterface;
use Yiisoft\Db\Schema\Quoter;
use Yiisoft\Db\Schema\QuoterInterface;
use Yiisoft\Db\Schema\SchemaInterface;
use Yiisoft\Db\Sqlite\Column\ColumnBuilder;
use Yiisoft\Db\Sqlite\Column\ColumnFactory;
use Yiisoft\Db\Transaction\TransactionInterface;

use function str_starts_with;
Expand Down Expand Up @@ -71,9 +72,9 @@ public function getQueryBuilder(): QueryBuilderInterface
return $this->queryBuilder;
}

public function getColumnBuilderClass(): string
public function getColumnFactory(): ColumnFactoryInterface
{
return ColumnBuilder::class;
return new ColumnFactory();
}

public function getQuoter(): QuoterInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ public function getSchemaDefaultValues(string $schema = '', bool $refresh = fals
*/
private function loadColumnSchema(array $info): ColumnSchemaInterface
{
$columnFactory = $this->db->getColumnBuilderClass()::columnFactory();
$columnFactory = $this->db->getColumnFactory();

$dbType = strtolower($info['type']);
$column = $columnFactory->fromDefinition($dbType, ['name' => $info['name']]);
Expand Down
11 changes: 5 additions & 6 deletions tests/ColumnBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

declare(strict_types=1);

use Yiisoft\Db\Sqlite\Column\ColumnFactory;
namespace Yiisoft\Db\Sqlite\Tests;

use Yiisoft\Db\Sqlite\Column\ColumnBuilder;
use Yiisoft\Db\Sqlite\Tests\Support\TestTrait;
use Yiisoft\Db\Tests\AbstractColumnBuilderTest;

Expand All @@ -13,11 +15,8 @@ class ColumnBuilderTest extends AbstractColumnBuilderTest
{
use TestTrait;

public function testColumnFactory(): void
public function getColumnBuilderClass(): string
{
$db = $this->getConnection();
$columnBuilderClass = $db->getColumnBuilderClass();

$this->assertInstanceOf(ColumnFactory::class, $columnBuilderClass::columnFactory());
return ColumnBuilder::class;
}
}
6 changes: 3 additions & 3 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Profiler\ProfilerInterface;
use Yiisoft\Db\Sqlite\Column\ColumnBuilder;
use Yiisoft\Db\Sqlite\Column\ColumnFactory;
use Yiisoft\Db\Sqlite\Tests\Support\TestTrait;
use Yiisoft\Db\Tests\Common\CommonConnectionTest;
use Yiisoft\Db\Transaction\TransactionInterface;
Expand Down Expand Up @@ -182,11 +182,11 @@ private function runExceptionTest(ConnectionInterface $db): void
$this->assertTrue($thrown, 'An exception should have been thrown by the command.');
}

public function testGetColumnBuilderClass(): void
public function testGetColumnFactory(): void
{
$db = $this->getConnection();

$this->assertSame(ColumnBuilder::class, $db->getColumnBuilderClass());
$this->assertInstanceOf(ColumnFactory::class, $db->getColumnFactory());
}

private function createProfiler(): ProfilerInterface
Expand Down

0 comments on commit 70fee23

Please sign in to comment.