diff --git a/README.md b/README.md index efad64b..43023b9 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,21 @@ ### Static analysis To run static analysis: -- psalm -- phpstan +- [psalm](https://psalm.dev/) +- [phpstan](https://phpstan.org/) ```shell make check ``` +To fix code style: +- [phpcs](https://github.com/squizlabs/PHP_CodeSniffer) +- [rector](https://getrector.com/) + +```shell +make fix +``` + ### Testing The package is tested with diff --git a/rector.php b/rector.php index 63ba589..6e66834 100644 --- a/rector.php +++ b/rector.php @@ -6,21 +6,29 @@ declare(strict_types=1); -use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; +use Rector\DeadCode\Rector\Node\RemoveNonExistingVarAnnotationRector; +use Rector\Set\ValueObject\SetList; return Rector\Config\RectorConfig::configure() ->withPaths( [ __DIR__ . '/src', __DIR__ . '/tests', - __DIR__ . '/example', ] ) ->withParallel() ->withCache('/tmp/var/rector') - ->withPhpSets() - ->withRules( + ->withPhpSets(php83: true) + ->withSets( [ - InlineConstructorDefaultToPropertyRector::class, + SetList::CODE_QUALITY, + SetList::DEAD_CODE, + SetList::PRIVATIZATION, + SetList::TYPE_DECLARATION_DOCBLOCKS, + ] + ) + ->withSkip( + [ + RemoveNonExistingVarAnnotationRector::class, ] ); diff --git a/src/Driver.php b/src/Driver.php index 5415c7c..d058c57 100644 --- a/src/Driver.php +++ b/src/Driver.php @@ -101,7 +101,7 @@ private function makeConnection(): ConnectionInterface * @note если вдруг экземпляр класса Migrator будет использоваться как сервис, то переиспользуем коннект. * Но с ограничением по времени, долго держать в памяти не будем. */ - if ($this->connectionInstance === null || $this->connectionTimer < time()) { + if (!$this->connectionInstance instanceof Connection || $this->connectionTimer < time()) { $this->connectionTimer = time() + $timeout; try { return $this->connectionInstance = new Connection( diff --git a/src/internal/ErrorInfo.php b/src/internal/ErrorInfo.php index 0145423..243f24e 100644 --- a/src/internal/ErrorInfo.php +++ b/src/internal/ErrorInfo.php @@ -36,6 +36,6 @@ public function getMessage(): string #[\Override] public function __toString(): string { - return $this->getMessage(); + return $this->message; } } diff --git a/tests/workflow/StatementMysqlTest.php b/tests/workflow/StatementMysqlTest.php index 03b2a0c..76add99 100644 --- a/tests/workflow/StatementMysqlTest.php +++ b/tests/workflow/StatementMysqlTest.php @@ -7,6 +7,7 @@ use Override; use Throwable; use PDO; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use dbschemix\core\connection\TransactionInterface; use dbschemix\pdo\internal\Connection; @@ -55,16 +56,28 @@ public function testExecActiveTransaction(): void } /** + * @return iterable + */ + public static function additionSchemaQuery(): iterable + { + yield ['CREATE TABLE IF NOT EXISTS test (name TEXT PRIMARY KEY, version INTEGER DEFAULT 0, atime TEXT)']; + yield ['ALTER TABLE migration ADD COLUMN test TEXT DEFAULT NULL']; + yield ['CREATE UNIQUE INDEX IF NOT EXISTS `UI_migration_name` ON migration (name)']; + yield ['DROP INDEX IF EXISTS `UI_migration_name`']; + yield ['DROP TABLE IF EXISTS test']; + } + + /** + * @param non-empty-string $query * @throws Throwable */ - public function testExecNotActiveTransaction(): void + #[DataProvider('additionSchemaQuery')] + public function testExecNotActiveTransaction(string $query): void { // default: false self::assertFalse($this->transaction->isActive()); - $this->transaction->exec( - "CREATE TABLE test (name TEXT PRIMARY KEY, version INTEGER DEFAULT 0, atime TEXT)" - ); + $this->transaction->exec($query); // statement CREATE TABLE: false self::assertFalse($this->transaction->isActive());