From 0e23a9fdcb0bdb9535b3e7300d2437864325057b Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Sun, 15 Oct 2023 14:02:51 +0700 Subject: [PATCH] Remove `yiisoft/strings` dependency (#210) * Remove `yiisoft/strings` dependency * Apply @vjik suggestion Co-authored-by: Sergei Predvoditelev * Update test according changes --------- Co-authored-by: Sergei Predvoditelev --- composer.json | 3 +-- src/Command/CreateCommand.php | 3 +-- src/MigrationBuilder.php | 10 +++++++--- src/Service/MigrationService.php | 9 +++++++-- tests/Common/AbstractMigrationBuilderTest.php | 4 +--- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 5d27197e..b6d42196 100644 --- a/composer.json +++ b/composer.json @@ -28,8 +28,7 @@ "yiisoft/db": "^1.1", "yiisoft/di": "^1.0", "yiisoft/definitions": "^3.0", - "yiisoft/injector": "^1.0", - "yiisoft/strings": "^2.0" + "yiisoft/injector": "^1.0" }, "require-dev": { "maglnet/composer-require-checker": "^4.4", diff --git a/src/Command/CreateCommand.php b/src/Command/CreateCommand.php index b10f6ea1..499b50cf 100644 --- a/src/Command/CreateCommand.php +++ b/src/Command/CreateCommand.php @@ -13,7 +13,6 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Style\SymfonyStyle; -use Yiisoft\Strings\Inflector; use Yiisoft\Db\Migration\Migrator; use Yiisoft\Db\Migration\Service\Generate\CreateService; use Yiisoft\Db\Migration\Service\MigrationService; @@ -137,7 +136,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int return Command::INVALID; } - $name = $this->generateName($command, (new Inflector())->toPascalCase($table), $and); + $name = $this->generateName($command, $table, $and); /** * @var string $namespace diff --git a/src/MigrationBuilder.php b/src/MigrationBuilder.php index 01acf788..e574f167 100644 --- a/src/MigrationBuilder.php +++ b/src/MigrationBuilder.php @@ -12,9 +12,13 @@ use Yiisoft\Db\Query\Query; use Yiisoft\Db\Query\QueryInterface; use Yiisoft\Db\Schema\Builder\ColumnInterface; -use Yiisoft\Strings\StringHelper; use Yiisoft\Db\Migration\Informer\MigrationInformerInterface; +use function implode; +use function microtime; +use function sprintf; +use function substr; + final class MigrationBuilder extends AbstractMigrationBuilder { public function __construct( @@ -47,8 +51,8 @@ public function getDb(): ConnectionInterface public function execute(string $sql, array $params = []): void { $sqlOutput = $sql; - if ($this->maxSqlOutputLength > 0) { - $sqlOutput = StringHelper::truncateEnd($sql, $this->maxSqlOutputLength, '[... hidden]'); + if (0 < $this->maxSqlOutputLength && $this->maxSqlOutputLength < strlen($sql)) { + $sqlOutput = substr($sql, 0, $this->maxSqlOutputLength) . ' [... hidden]'; } $time = $this->beginCommand("Execute SQL: $sqlOutput"); diff --git a/src/Service/MigrationService.php b/src/Service/MigrationService.php index 80b21555..cc7d681f 100644 --- a/src/Service/MigrationService.php +++ b/src/Service/MigrationService.php @@ -12,12 +12,16 @@ use Yiisoft\Aliases\Aliases; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Injector\Injector; -use Yiisoft\Strings\Inflector; use Yiisoft\Db\Migration\MigrationInterface; use Yiisoft\Db\Migration\Migrator; use Yiisoft\Db\Migration\RevertibleMigrationInterface; use function dirname; +use function gmdate; +use function preg_replace; +use function str_replace; +use function trim; +use function ucwords; final class MigrationService { @@ -310,7 +314,8 @@ public function generateClassName(?string $namespace, string $name): array $namespace = $this->createNamespace; } - $class = 'M' . gmdate('ymdHis') . (new Inflector())->toPascalCase($name); + $class = 'M' . gmdate('ymdHis') + . str_replace(' ', '', ucwords(preg_replace('/[^a-z0-9]+/i', ' ', $name))); return [$namespace, $class]; } diff --git a/tests/Common/AbstractMigrationBuilderTest.php b/tests/Common/AbstractMigrationBuilderTest.php index a5b7c08f..2c6b65a8 100644 --- a/tests/Common/AbstractMigrationBuilderTest.php +++ b/tests/Common/AbstractMigrationBuilderTest.php @@ -575,17 +575,15 @@ public function testMaxSqlOutputLength(): void SELECT 1+2+3+4+5+6+7+8+9+10+11 AS resultado FROM dual SQL, ); - $expected = 'Execute SQL: SELECT 1+2+3+4+5+6+7+8+9+10+11 AS resultado F[... hidden] ... Done'; } else { $this->builder->execute( <<assertStringContainsString($expected, $this->informer->getOutput()); + $this->assertStringContainsString('Execute SQL: SELE [... hidden] ... Done', $this->informer->getOutput()); } public function testBigInteger(): void