diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 7c723ba1..c65d1c14 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -70,6 +70,6 @@ jobs: - name: Run infection. run: | - vendor/bin/roave-infection-static-analysis-plugin --threads=2 --ignore-msi-with-no-mutations --only-covered + vendor/bin/roave-infection-static-analysis-plugin --threads=2 --ignore-msi-with-no-mutations env: STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} diff --git a/CHANGELOG.md b/CHANGELOG.md index f8da79f5..2805e75b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ - Chg #428: Update expression namespaces according to changes in `yiisoft/db` package (@Tigrov) - Enh #432, #433: Update `DMLQueryBuilder::update()` method to adapt changes in `yiisoft/db` (@rustamwin, @Tigrov) - Enh #439: Move "Packets out of order" warning suppression from Yii DB (@vjik) +- Chg #447: Refactor `ColumnDefinitionParser` (@vjik) ## 1.2.0 March 21, 2024 diff --git a/src/Column/ColumnDefinitionParser.php b/src/Column/ColumnDefinitionParser.php index 53206921..24d4a712 100644 --- a/src/Column/ColumnDefinitionParser.php +++ b/src/Column/ColumnDefinitionParser.php @@ -4,6 +4,8 @@ namespace Yiisoft\Db\Mysql\Column; +use Yiisoft\Db\Syntax\AbstractColumnDefinitionParser; + /** * Parses column definition string. For example, `string(255)` or `int unsigned`. * @@ -19,11 +21,11 @@ * unsigned?: bool * } */ -final class ColumnDefinitionParser extends \Yiisoft\Db\Syntax\ColumnDefinitionParser +final class ColumnDefinitionParser extends AbstractColumnDefinitionParser { /** - * @psalm-return ExtraInfo - * @psalm-suppress ImplementedReturnTypeMismatch, InvalidReturnType, InvalidReturnStatement + * @inheritDoc + * @psalm-suppress InvalidReturnType, InvalidReturnStatement */ protected function extraInfo(string $extra): array { @@ -44,4 +46,40 @@ protected function extraInfo(string $extra): array return $info; } + + protected function parseTypeParams(string $type, string $params): array + { + return match ($type) { + 'bit', + 'bigint', + 'binary', + 'char', + 'decimal', + 'double', + 'float', + 'int', + 'integer', + 'mediumint', + 'numeric', + 'real', + 'smallint', + 'string', + 'tinyint', + 'varbinary', + 'varchar', + 'year' => $this->parseSizeInfo($params), + 'enum' => $this->parseEnumValues($params), + default => [], + }; + } + + /** + * @psalm-return array{enumValues: list} + */ + protected function parseEnumValues(string $params): array + { + preg_match_all("/'([^']*)'/", $params, $matches); + + return ['enumValues' => $matches[1]]; + } } diff --git a/tests/ColumnDefinitionParserTest.php b/tests/ColumnDefinitionParserTest.php new file mode 100644 index 00000000..4b4f0076 --- /dev/null +++ b/tests/ColumnDefinitionParserTest.php @@ -0,0 +1,28 @@ + 'enum', 'enumValues' => ['a', 'b', 'c']]], + ["enum('a','b','c') NOT NULL", ['type' => 'enum', 'enumValues' => ['a', 'b', 'c'], 'notNull' => true]], + ]; + } +}