Skip to content

Commit

Permalink
Remove yiisoft/strings dependency (#210)
Browse files Browse the repository at this point in the history
* Remove `yiisoft/strings` dependency

* Apply @vjik suggestion

Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>

* Update test according changes

---------

Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
  • Loading branch information
Tigrov and vjik committed Oct 15, 2023
1 parent e8427c7 commit 0e23a9f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
3 changes: 1 addition & 2 deletions composer.json
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions src/Command/CreateCommand.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions src/MigrationBuilder.php
Expand Up @@ -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(
Expand Down Expand Up @@ -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)) {

Check warning on line 54 in src/MigrationBuilder.php

View workflow job for this annotation

GitHub Actions / PHP 8-ubuntu-latest

Escaped Mutant for Mutator "LessThan": --- Original +++ New @@ @@ public function execute(string $sql, array $params = []) : void { $sqlOutput = $sql; - if (0 < $this->maxSqlOutputLength && $this->maxSqlOutputLength < strlen($sql)) { + if (0 < $this->maxSqlOutputLength && $this->maxSqlOutputLength <= strlen($sql)) { $sqlOutput = substr($sql, 0, $this->maxSqlOutputLength) . ' [... hidden]'; } $time = $this->beginCommand("Execute SQL: {$sqlOutput}");
$sqlOutput = substr($sql, 0, $this->maxSqlOutputLength) . ' [... hidden]';
}

$time = $this->beginCommand("Execute SQL: $sqlOutput");
Expand Down
9 changes: 7 additions & 2 deletions src/Service/MigrationService.php
Expand Up @@ -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
{
Expand Down Expand Up @@ -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];
}
Expand Down
4 changes: 1 addition & 3 deletions tests/Common/AbstractMigrationBuilderTest.php
Expand Up @@ -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(
<<<SQL
SELECT 1+2+3+4+5+6+7+8+9+10+11
SQL,
);
$expected = 'Execute SQL: SELECT 1+2+3+4+5+6+7+8[... hidden] ... Done';
}

$this->assertStringContainsString($expected, $this->informer->getOutput());
$this->assertStringContainsString('Execute SQL: SELE [... hidden] ... Done', $this->informer->getOutput());
}

public function testBigInteger(): void
Expand Down

0 comments on commit 0e23a9f

Please sign in to comment.