From d8cede5045ec8ba05117308e4a44369f6b7304d7 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Mon, 23 Sep 2024 22:02:55 +0100 Subject: [PATCH] Drop Utils\Routine class Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 45 ------ psalm-baseline.xml | 69 --------- src/Utils/Routine.php | 137 ---------------- tests/Utils/RoutineTest.php | 301 ------------------------------------ 4 files changed, 552 deletions(-) delete mode 100644 src/Utils/Routine.php delete mode 100644 tests/Utils/RoutineTest.php diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 52a50605..d499e247 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -875,51 +875,6 @@ parameters: count: 1 path: src/Utils/Query.php - - - message: "#^Cannot access offset 'value' on mixed\\.$#" - count: 3 - path: src/Utils/Routine.php - - - - message: "#^Cannot access property \\$name on PhpMyAdmin\\\\SqlParser\\\\Components\\\\DataType\\|null\\.$#" - count: 2 - path: src/Utils/Routine.php - - - - message: "#^Cannot access property \\$options on PhpMyAdmin\\\\SqlParser\\\\Components\\\\DataType\\|null\\.$#" - count: 2 - path: src/Utils/Routine.php - - - - message: "#^Cannot access property \\$options on PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#" - count: 3 - path: src/Utils/Routine.php - - - - message: "#^Cannot access property \\$parameters on PhpMyAdmin\\\\SqlParser\\\\Components\\\\DataType\\|null\\.$#" - count: 3 - path: src/Utils/Routine.php - - - - message: "#^Cannot assign new offset to array\\, mixed\\>\\|string\\.$#" - count: 1 - path: src/Utils/Routine.php - - - - message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Utils\\\\Routine\\:\\:getParameter\\(\\) should return array\\ but returns array\\\\.$#" - count: 1 - path: src/Utils/Routine.php - - - - message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Utils\\\\Routine\\:\\:getReturnType\\(\\) should return array\\ but returns array\\\\.$#" - count: 1 - path: src/Utils/Routine.php - - - - message: "#^Parameter \\#2 \\$array of function implode expects array\\|null, array\\, mixed\\>\\|string given\\.$#" - count: 1 - path: src/Utils/Routine.php - - message: "#^Cannot access property \\$database on PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|null\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 03f00f68..fc825eff 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1161,68 +1161,6 @@ order)]]> - - - name, - implode(',', $type->parameters), - implode(' ', $options), - ]]]> - inOut) ? '' : $param->inOut, - $param->name, - $param->type->name, - implode(',', $param->type->parameters), - implode(' ', $options), - ]]]> - - - - - - - - - - - - - - - - - - - - - - - - - type->parameters]]> - type->parameters]]> - - - type->options->options]]> - type->options->options]]> - options->options]]> - - - type->name]]> - type->name]]> - type->options]]> - type->options]]> - type->options->options]]> - type->options->options]]> - type->parameters]]> - type->parameters]]> - options->options]]> - - - inOut)]]> - parameters)]]> - - @@ -1500,13 +1438,6 @@ - - - - - - - diff --git a/src/Utils/Routine.php b/src/Utils/Routine.php deleted file mode 100644 index bb569c78..00000000 --- a/src/Utils/Routine.php +++ /dev/null @@ -1,137 +0,0 @@ -list); - - if ($type === null) { - return [ - '', - '', - '', - ]; - } - - $options = []; - foreach ($type->options->options as $opt) { - $options[] = is_string($opt) ? $opt : $opt['value']; - } - - return [ - $type->name, - implode(',', $type->parameters), - implode(' ', $options), - ]; - } - - /** - * Parses a parameter of a routine. - * - * @param string $param parameter's definition - * - * @return string[] - */ - public static function getParameter(string $param): array - { - $lexer = new Lexer('(' . $param . ')'); - - // A dummy parser is used for error reporting. - $param = ParameterDefinitions::parse(new Parser(), $lexer->list); - - if ($param === []) { - return [ - '', - '', - '', - '', - '', - ]; - } - - $param = $param[0]; - - $options = []; - foreach ($param->type->options->options as $opt) { - $options[] = is_string($opt) ? $opt : $opt['value']; - } - - return [ - empty($param->inOut) ? '' : $param->inOut, - $param->name, - $param->type->name, - implode(',', $param->type->parameters), - implode(' ', $options), - ]; - } - - /** - * Gets the parameters of a routine from the parse tree. - * - * @param CreateStatement $statement the statement to be processed - * - * @return array> - */ - public static function getParameters(CreateStatement $statement): array - { - $retval = [ - 'num' => 0, - 'dir' => [], - 'name' => [], - 'type' => [], - 'length' => [], - 'length_arr' => [], - 'opts' => [], - ]; - - if (! empty($statement->parameters)) { - $idx = 0; - foreach ($statement->parameters as $param) { - $retval['dir'][$idx] = $param->inOut; - $retval['name'][$idx] = $param->name; - $retval['type'][$idx] = $param->type->name; - $retval['length'][$idx] = implode(',', $param->type->parameters); - $retval['length_arr'][$idx] = $param->type->parameters; - $retval['opts'][$idx] = []; - foreach ($param->type->options->options as $opt) { - $retval['opts'][$idx][] = is_string($opt) ? - $opt : $opt['value']; - } - - $retval['opts'][$idx] = implode(' ', $retval['opts'][$idx]); - ++$idx; - } - - $retval['num'] = $idx; - } - - return $retval; - } -} diff --git a/tests/Utils/RoutineTest.php b/tests/Utils/RoutineTest.php deleted file mode 100644 index f7f59ae7..00000000 --- a/tests/Utils/RoutineTest.php +++ /dev/null @@ -1,301 +0,0 @@ -assertEquals($expected, Routine::getReturnType($def)); - } - - /** - * @return array>> - * @psalm-return list - */ - public static function getReturnTypeProvider(): array - { - return [ - [ - '', - [ - '', - '', - '', - ], - ], - [ - 'TEXT', - [ - 'TEXT', - '', - '', - ], - ], - [ - 'INT(20)', - [ - 'INT', - '20', - '', - ], - ], - [ - 'INT UNSIGNED', - [ - 'INT', - '', - 'UNSIGNED', - ], - ], - [ - 'VARCHAR(1) CHARSET utf8', - [ - 'VARCHAR', - '1', - 'utf8', - ], - ], - [ - 'ENUM(\'a\', \'b\') CHARSET latin1', - [ - 'ENUM', - '\'a\',\'b\'', - 'latin1', - ], - ], - [ - 'DECIMAL(5,2) UNSIGNED ZEROFILL', - [ - 'DECIMAL', - '5,2', - 'UNSIGNED ZEROFILL', - ], - ], - [ - 'SET(\'test\'\'esc"\', \'more\\\'esc\')', - [ - 'SET', - '\'test\'\'esc"\',\'more\\\'esc\'', - '', - ], - ], - ]; - } - - /** @param string[] $expected */ - #[DataProvider('getParameterProvider')] - public function testGetParameter(string $def, array $expected): void - { - $this->assertEquals($expected, Routine::getParameter($def)); - } - - /** - * @return array>> - * @psalm-return list - */ - public static function getParameterProvider(): array - { - return [ - [ - '', - [ - '', - '', - '', - '', - '', - ], - ], - [ - '`foo` TEXT', - [ - '', - 'foo', - 'TEXT', - '', - '', - ], - ], - [ - '`foo` INT(20)', - [ - '', - 'foo', - 'INT', - '20', - '', - ], - ], - [ - 'IN `fo``fo` INT UNSIGNED', - [ - 'IN', - 'fo`fo', - 'INT', - '', - 'UNSIGNED', - ], - ], - [ - 'OUT bar VARCHAR(1) CHARSET utf8', - [ - 'OUT', - 'bar', - 'VARCHAR', - '1', - 'utf8', - ], - ], - [ - '`"baz\'\'` ENUM(\'a\', \'b\') CHARSET latin1', - [ - '', - '"baz\'\'', - 'ENUM', - '\'a\',\'b\'', - 'latin1', - ], - ], - [ - 'INOUT `foo` DECIMAL(5,2) UNSIGNED ZEROFILL', - [ - 'INOUT', - 'foo', - 'DECIMAL', - '5,2', - 'UNSIGNED ZEROFILL', - ], - ], - [ - '`foo``s func` SET(\'test\'\'esc"\', \'more\\\'esc\')', - [ - '', - 'foo`s func', - 'SET', - '\'test\'\'esc"\',\'more\\\'esc\'', - '', - ], - ], - ]; - } - - /** - * @param array $expected - * @psalm-param array{ - * num: int, - * dir: string[], - * name: string[], - * type: string[], - * length: string[], - * length_arr: string[][], - * opts: string[] - * } $expected - */ - #[DataProvider('getParametersProvider')] - public function testGetParameters(string $query, array $expected): void - { - $parser = new Parser($query); - $this->assertInstanceOf(CreateStatement::class, $parser->statements[0]); - $this->assertEquals($expected, Routine::getParameters($parser->statements[0])); - } - - /** - * @return array>> - * @psalm-return list - */ - public static function getParametersProvider(): array - { - return [ - [ - 'CREATE PROCEDURE `foo`() SET @A=0', - [ - 'num' => 0, - 'dir' => [], - 'name' => [], - 'type' => [], - 'length' => [], - 'length_arr' => [], - 'opts' => [], - ], - ], - [ - 'CREATE DEFINER=`user\\`@`somehost``(` FUNCTION `foo```(`baz` INT) BEGIN SELECT NULL; END', - [ - 'num' => 1, - 'dir' => [0 => ''], - 'name' => [0 => 'baz'], - 'type' => [0 => 'INT'], - 'length' => [0 => ''], - 'length_arr' => [ - 0 => [], - ], - 'opts' => [0 => ''], - ], - ], - [ - 'CREATE PROCEDURE `foo`(IN `baz\\)` INT(25) zerofill unsigned) BEGIN SELECT NULL; END', - [ - 'num' => 1, - 'dir' => [0 => 'IN'], - 'name' => [0 => 'baz\\)'], - 'type' => [0 => 'INT'], - 'length' => [0 => '25'], - 'length_arr' => [ - 0 => ['25'], - ], - 'opts' => [0 => 'UNSIGNED ZEROFILL'], - ], - ], - [ - 'CREATE PROCEDURE `foo`(IN `baz\\` INT(001) zerofill, out bazz varchar(15) charset utf8) ' . - 'BEGIN SELECT NULL; END', - [ - 'num' => 2, - 'dir' => [ - 0 => 'IN', - 1 => 'OUT', - ], - 'name' => [ - 0 => 'baz\\', - 1 => 'bazz', - ], - 'type' => [ - 0 => 'INT', - 1 => 'VARCHAR', - ], - 'length' => [ - 0 => '1', - 1 => '15', - ], - 'length_arr' => [ - 0 => ['1'], - 1 => ['15'], - ], - 'opts' => [ - 0 => 'ZEROFILL', - 1 => 'utf8', - ], - ], - ], - ]; - } -}