Skip to content

Commit

Permalink
Merge pull request #520 from kamil-tekiela/Minor-fixes
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
MauricioFauth authored Jan 12, 2024
2 parents 30452c0 + a40efe4 commit 25a0713
Showing 16 changed files with 97 additions and 261 deletions.
23 changes: 9 additions & 14 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -370,11 +370,6 @@ parameters:
count: 1
path: src/Context.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: src/Core.php

-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Exceptions\\\\ParserException\\:\\:\\$token \\(PhpMyAdmin\\\\SqlParser\\\\Token\\) does not accept PhpMyAdmin\\\\SqlParser\\\\Token\\|null\\.$#"
count: 1
@@ -391,22 +386,22 @@ parameters:
path: src/Lexer.php

-
message: "#^Parameter \\#1 \\$msg \\(string\\) of method PhpMyAdmin\\\\SqlParser\\\\Lexer\\:\\:error\\(\\) should be compatible with parameter \\$error \\(Exception\\) of method PhpMyAdmin\\\\SqlParser\\\\Core\\:\\:error\\(\\)$#"
message: "#^Parameter \\#1 \\$token of class PhpMyAdmin\\\\SqlParser\\\\Token constructor expects string, null given\\.$#"
count: 1
path: src/Lexer.php

-
message: "#^Parameter \\#1 \\$token of class PhpMyAdmin\\\\SqlParser\\\\Token constructor expects string, null given\\.$#"
message: "#^Parameter \\#3 \\$flags of class PhpMyAdmin\\\\SqlParser\\\\Token constructor expects int, int\\|null given\\.$#"
count: 1
path: src/Lexer.php

-
message: "#^Parameter \\#3 \\$flags of class PhpMyAdmin\\\\SqlParser\\\\Token constructor expects int, int\\|null given\\.$#"
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Lexer\\:\\:\\$delimiter \\(string\\) does not accept null\\.$#"
count: 1
path: src/Lexer.php

-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Lexer\\:\\:\\$delimiter \\(string\\) does not accept null\\.$#"
message: "#^Strict comparison using \\=\\=\\= between non\\-empty\\-array\\<non\\-empty\\-string, int\\> and array\\{\\} will always evaluate to false\\.$#"
count: 1
path: src/Lexer.php

@@ -430,11 +425,6 @@ parameters:
count: 4
path: src/Parser.php

-
message: "#^Parameter \\#1 \\$msg \\(string\\) of method PhpMyAdmin\\\\SqlParser\\\\Parser\\:\\:error\\(\\) should be compatible with parameter \\$error \\(Exception\\) of method PhpMyAdmin\\\\SqlParser\\\\Core\\:\\:error\\(\\)$#"
count: 1
path: src/Parser.php

-
message: "#^Parameter \\#2 \\$list of method PhpMyAdmin\\\\SqlParser\\\\Statement\\:\\:validateClauseOrder\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\TokensList, PhpMyAdmin\\\\SqlParser\\\\TokensList\\|null given\\.$#"
count: 3
@@ -445,6 +435,11 @@ parameters:
count: 1
path: src/Parser.php

-
message: "#^Strict comparison using \\=\\=\\= between non\\-empty\\-array\\<non\\-empty\\-string, int\\> and array\\{\\} will always evaluate to false\\.$#"
count: 1
path: src/Parser.php

-
message: "#^Call to an undefined static method PhpMyAdmin\\\\SqlParser\\\\Component\\:\\:buildAll\\(\\)\\.$#"
count: 1
121 changes: 0 additions & 121 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -450,9 +450,6 @@
<MixedAssignment>
<code>self::$keywords</code>
</MixedAssignment>
<PossiblyUnusedMethod>
<code>getIdentifierQuote</code>
</PossiblyUnusedMethod>
</file>
<file src="src/Contexts/ContextMariaDb100000.php">
<UnusedClass>
@@ -564,12 +561,6 @@
<code>ContextMySql80100</code>
</UnusedClass>
</file>
<file src="src/Core.php">
<RedundantConditionGivenDocblockType>
<code>Context::$keywords !== []</code>
<code>Context::$keywords !== []</code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Exceptions/ParserException.php">
<PossiblyNullPropertyAssignmentValue>
<code>$token</code>
@@ -589,9 +580,6 @@
<NullArgument>
<code>null</code>
</NullArgument>
<ParamNameMismatch>
<code>$msg</code>
</ParamNameMismatch>
<PossiblyNullArgument>
<code>$flags</code>
<code><![CDATA[$this->str[$this->last + 1]]]></code>
@@ -658,9 +646,6 @@
<code><![CDATA[self::STATEMENT_PARSERS[$statementName ?? $token->keyword]]]></code>
<code><![CDATA[self::STATEMENT_PARSERS[$token->keyword]]]></code>
</MixedArrayOffset>
<ParamNameMismatch>
<code>$msg</code>
</ParamNameMismatch>
<PossiblyNullArgument>
<code>$list</code>
<code>$list</code>
@@ -1014,9 +999,6 @@
<code>++$i !== $count</code>
<code>++$i !== $count</code>
</RedundantCondition>
<UnnecessaryVarAnnotation>
<code>string</code>
</UnnecessaryVarAnnotation>
</file>
<file src="src/Tools/CustomJsonSerializer.php">
<MixedAssignment>
@@ -1256,7 +1238,6 @@
<code>$ret</code>
<code>$ret</code>
<code>$ret</code>
<code>$ret</code>
</PossiblyNullArrayOffset>
<PossiblyNullReference>
<code>has</code>
@@ -1594,108 +1575,6 @@
<code><![CDATA[$parser->statements[0]]]></code>
<code><![CDATA[$parser->statements[0]]]></code>
</ArgumentTypeCoercion>
<InvalidReturnStatement>
<code><![CDATA[[
[
'CREATE USER test',
[],
],
[
'CREATE TABLE `address` (
`address_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`address` varchar(50) NOT NULL,
`address2` varchar(50) DEFAULT NULL,
`district` varchar(20) NOT NULL,
`city_id` smallint(5) unsigned NOT NULL,
`postal_code` varchar(10) DEFAULT NULL,
`phone` varchar(20) NOT NULL,
`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`address_id`),
KEY `idx_fk_city_id` (`city_id`),
CONSTRAINT `fk_address_city` FOREIGN KEY (`city_id`) REFERENCES `city` (`city_id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=606 DEFAULT CHARSET=utf8',
[
'address_id' => [
'type' => 'SMALLINT',
'timestamp_not_null' => false,
],
'address' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
],
'address2' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
'default_value' => 'NULL',
],
'district' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
],
'city_id' => [
'type' => 'SMALLINT',
'timestamp_not_null' => false,
],
'postal_code' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
'default_value' => 'NULL',
],
'phone' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
],
'last_update' => [
'type' => 'TIMESTAMP',
'timestamp_not_null' => true,
'default_value' => 'CURRENT_TIMESTAMP',
'default_current_timestamp' => true,
'on_update_current_timestamp' => true,
],
],
],
[
'CREATE TABLE table1 (
a INT NOT NULL,
b VARCHAR(32),
c INT AS (a mod 10) VIRTUAL,
d VARCHAR(5) AS (left(b,5)) PERSISTENT
)',
[
'a' => [
'type' => 'INT',
'timestamp_not_null' => false,
],
'b' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
],
'c' => [
'type' => 'INT',
'timestamp_not_null' => false,
'generated' => true,
'expr' => '(a mod 10)',
],
'd' => [
'type' => 'VARCHAR',
'timestamp_not_null' => false,
'generated' => true,
'expr' => '(left(b,5))',
],
],
],
]]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code><![CDATA[list<array{string, array<string, array{
* type: string,
* timestamp_not_null: bool,
* default_value?: string,
* default_current_timestamp?: bool,
* on_update_current_timestamp?: bool,
* expr?: string
* }>}>]]></code>
</InvalidReturnType>
<PossiblyUnusedMethod>
<code>getFieldsProvider</code>
<code>getForeignKeysProvider</code>
4 changes: 2 additions & 2 deletions src/Components/GroupKeyword.php
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@
*/
final class GroupKeyword implements Component
{
/** @var mixed */
public $type;
/** @var 'ASC'|'DESC'|null */
public string|null $type = null;

Check failure on line 21 in src/Components/GroupKeyword.php

GitHub Actions / lint-docs

The hint on "type" at @var is invalid: "'ASC'|'DESC'|null" on "PhpMyAdmin\SqlParser\Components\GroupKeyword::$type"

/**
* The expression that is used for grouping.
10 changes: 0 additions & 10 deletions src/Context.php
Original file line number Diff line number Diff line change
@@ -705,16 +705,6 @@ public static function escapeAll(array $strings): array
return $strings;
}

/**
* Returns char used to quote identifiers based on currently set SQL Mode (ie. standard or ANSI_QUOTES)
*
* @return string either " (double quote, ansi_quotes mode) or ` (backtick, standard mode)
*/
public static function getIdentifierQuote(): string
{
return self::hasMode(self::SQL_MODE_ANSI_QUOTES) ? '"' : '`';
}

/**
* Function verifies that given SQL Mode constant is currently set
*
60 changes: 0 additions & 60 deletions src/Core.php

This file was deleted.

30 changes: 27 additions & 3 deletions src/Lexer.php
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@

namespace PhpMyAdmin\SqlParser;

use Exception;
use PhpMyAdmin\SqlParser\Exceptions\LexerException;

use function in_array;
@@ -26,8 +27,24 @@
*
* @see Context
*/
class Lexer extends Core
class Lexer
{
/**
* Whether errors should throw exceptions or just be stored.
*/
private bool $strict = false;

/**
* List of errors that occurred during lexing.
*
* Usually, the lexing does not stop once an error occurred because that
* error might be false positive or a partial result (even a bad one)
* might be needed.
*
* @var Exception[]
*/
public array $errors = [];

/**
* A list of keywords that indicate that the function keyword
* is not used as a function
@@ -112,7 +129,9 @@ class Lexer extends Core
*/
public function __construct($str, $strict = false, $delimiter = null)
{
parent::__construct();
if (Context::$keywords === []) {
Context::load();
}

// `strlen` is used instead of `mb_strlen` because the lexer needs to
// parse each byte of the input.
@@ -372,7 +391,12 @@ public function error($msg, $str = '', $pos = 0, $code = 0): void
$pos,
$code
);
parent::error($error);

if ($this->strict) {
throw $error;
}

$this->errors[] = $error;
}

/**
Loading

0 comments on commit 25a0713

Please sign in to comment.