Skip to content

Commit d0e84f1

Browse files
committed
Rename methods in TokenList - separating getters from questions; removing bunch of (bool) in the process
1 parent db04ea1 commit d0e84f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1909
-1869
lines changed

sources/Parser/Dal/BinlogCommandParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class BinlogCommandParser
2323
*/
2424
public function parseBinlog(TokenList $tokenList): BinlogCommand
2525
{
26-
$tokenList->consumeKeyword(Keyword::BINLOG);
27-
$value = $tokenList->consumeString();
26+
$tokenList->expectKeyword(Keyword::BINLOG);
27+
$value = $tokenList->expectString();
2828
$tokenList->expectEnd();
2929

3030
return new BinlogCommand($value);

sources/Parser/Dal/CacheCommandsParser.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ class CacheCommandsParser
3939
*/
4040
public function parseCacheIndex(TokenList $tokenList): CacheIndexCommand
4141
{
42-
$tokenList->consumeKeywords(Keyword::CACHE, Keyword::INDEX);
42+
$tokenList->expectKeywords(Keyword::CACHE, Keyword::INDEX);
4343

4444
$tableIndexLists = [];
4545
do {
46-
$table = new QualifiedName(...$tokenList->consumeQualifiedName());
46+
$table = new QualifiedName(...$tokenList->expectQualifiedName());
4747
$indexes = $this->parseIndexes($tokenList);
4848

4949
$tableIndexLists[] = new TableIndexList($table, $indexes);
50-
} while ($tokenList->mayConsumeComma());
50+
} while ($tokenList->hasComma());
5151

5252
$partitions = $this->parsePartitions($tokenList);
5353

54-
$tokenList->consumeKeyword(Keyword::IN);
55-
$keyCache = $tokenList->consumeName();
54+
$tokenList->expectKeyword(Keyword::IN);
55+
$keyCache = $tokenList->expectName();
5656
$tokenList->expectEnd();
5757

5858
return new CacheIndexCommand($keyCache, $tableIndexLists, $partitions);
@@ -73,17 +73,17 @@ public function parseCacheIndex(TokenList $tokenList): CacheIndexCommand
7373
*/
7474
public function parseLoadIndexIntoCache(TokenList $tokenList): LoadIndexIntoCacheCommand
7575
{
76-
$tokenList->consumeKeywords(Keyword::LOAD, Keyword::INDEX, Keyword::INTO, Keyword::CACHE);
76+
$tokenList->expectKeywords(Keyword::LOAD, Keyword::INDEX, Keyword::INTO, Keyword::CACHE);
7777

7878
$tableIndexLists = [];
7979
do {
80-
$table = new QualifiedName(...$tokenList->consumeQualifiedName());
80+
$table = new QualifiedName(...$tokenList->expectQualifiedName());
8181
$partitions = $this->parsePartitions($tokenList);
8282
$indexes = $this->parseIndexes($tokenList);
83-
$ignoreLeaves = (bool) $tokenList->mayConsumeKeywords(Keyword::IGNORE, Keyword::LEAVES);
83+
$ignoreLeaves = $tokenList->hasKeywords(Keyword::IGNORE, Keyword::LEAVES);
8484

8585
$tableIndexLists[] = new TableIndexList($table, $indexes, $partitions, $ignoreLeaves);
86-
} while ($tokenList->mayConsumeComma());
86+
} while ($tokenList->hasComma());
8787

8888
return new LoadIndexIntoCacheCommand($tableIndexLists);
8989
}
@@ -94,13 +94,13 @@ public function parseLoadIndexIntoCache(TokenList $tokenList): LoadIndexIntoCach
9494
private function parseIndexes(TokenList $tokenList): ?array
9595
{
9696
$indexes = null;
97-
if ($tokenList->mayConsumeAnyKeyword(Keyword::INDEX, Keyword::KEY)) {
98-
$tokenList->consume(TokenType::LEFT_PARENTHESIS);
97+
if ($tokenList->hasAnyKeyword(Keyword::INDEX, Keyword::KEY)) {
98+
$tokenList->expect(TokenType::LEFT_PARENTHESIS);
9999
$indexes = [];
100100
do {
101-
$indexes[] = $tokenList->consumeName();
102-
} while ($tokenList->mayConsumeComma());
103-
$tokenList->consume(TokenType::RIGHT_PARENTHESIS);
101+
$indexes[] = $tokenList->expectName();
102+
} while ($tokenList->hasComma());
103+
$tokenList->expect(TokenType::RIGHT_PARENTHESIS);
104104
}
105105

106106
return $indexes;
@@ -111,20 +111,20 @@ private function parseIndexes(TokenList $tokenList): ?array
111111
*/
112112
private function parsePartitions(TokenList $tokenList)
113113
{
114-
if (!$tokenList->mayConsumeKeyword(Keyword::PARTITION)) {
114+
if (!$tokenList->hasKeyword(Keyword::PARTITION)) {
115115
return null;
116116
}
117117

118-
$tokenList->consume(TokenType::LEFT_PARENTHESIS);
119-
if ($tokenList->mayConsumeKeyword(Keyword::ALL)) {
118+
$tokenList->expect(TokenType::LEFT_PARENTHESIS);
119+
if ($tokenList->hasKeyword(Keyword::ALL)) {
120120
$partitions = true;
121121
} else {
122122
$partitions = [];
123123
do {
124-
$partitions[] = $tokenList->consumeName();
125-
} while ($tokenList->mayConsumeComma());
124+
$partitions[] = $tokenList->expectName();
125+
} while ($tokenList->hasComma());
126126
}
127-
$tokenList->consume(TokenType::RIGHT_PARENTHESIS);
127+
$tokenList->expect(TokenType::RIGHT_PARENTHESIS);
128128

129129
return $partitions;
130130
}

sources/Parser/Dal/CharsetCommandsParser.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ class CharsetCommandsParser
2727
*/
2828
public function parseSetCharacterSet(TokenList $tokenList): SetCharacterSetCommand
2929
{
30-
$tokenList->consumeKeyword(Keyword::SET);
31-
$keyword = $tokenList->consumeAnyKeyword(Keyword::CHARACTER, Keyword::CHARSET);
30+
$tokenList->expectKeyword(Keyword::SET);
31+
$keyword = $tokenList->expectAnyKeyword(Keyword::CHARACTER, Keyword::CHARSET);
3232
if ($keyword === Keyword::CHARACTER) {
33-
$tokenList->consumeKeyword(Keyword::SET);
33+
$tokenList->expectKeyword(Keyword::SET);
3434
}
35-
if ($tokenList->mayConsumeKeyword(Keyword::DEFAULT)) {
35+
if ($tokenList->hasKeyword(Keyword::DEFAULT)) {
3636
$charset = null;
3737
} else {
38-
$charset = Charset::get($tokenList->consumeNameOrString());
38+
$charset = Charset::get($tokenList->expectNameOrString());
3939
}
4040
$tokenList->expectEnd();
4141

@@ -48,12 +48,12 @@ public function parseSetCharacterSet(TokenList $tokenList): SetCharacterSetComma
4848
*/
4949
public function parseSetNames(TokenList $tokenList): SetNamesCommand
5050
{
51-
$tokenList->consumeKeywords(Keyword::SET, Keyword::NAMES);
51+
$tokenList->expectKeywords(Keyword::SET, Keyword::NAMES);
5252
$charset = $collation = null;
53-
if ($tokenList->mayConsumeKeyword(Keyword::DEFAULT) === null) {
54-
$charset = Charset::get($tokenList->consumeNameOrString());
55-
if ($tokenList->mayConsumeKeyword(Keyword::COLLATE) !== null) {
56-
$collation = Collation::get($tokenList->consumeNameOrString());
53+
if ($tokenList->hasKeyword(Keyword::DEFAULT) === null) {
54+
$charset = Charset::get($tokenList->expectNameOrString());
55+
if ($tokenList->hasKeyword(Keyword::COLLATE) !== null) {
56+
$collation = Collation::get($tokenList->expectNameOrString());
5757
}
5858
}
5959
$tokenList->expectEnd();

sources/Parser/Dal/ComponentCommandsParser.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ class ComponentCommandsParser
2424
*/
2525
public function parseInstallComponent(TokenList $tokenList): InstallComponentCommand
2626
{
27-
$tokenList->consumeKeywords(Keyword::INSTALL, Keyword::COMPONENT);
27+
$tokenList->expectKeywords(Keyword::INSTALL, Keyword::COMPONENT);
2828
$components = [];
2929
do {
30-
$components[] = $tokenList->consumeNameOrString();
31-
} while ($tokenList->mayConsumeComma());
30+
$components[] = $tokenList->expectNameOrString();
31+
} while ($tokenList->hasComma());
3232
$tokenList->expectEnd();
3333

3434
return new InstallComponentCommand($components);
@@ -39,11 +39,11 @@ public function parseInstallComponent(TokenList $tokenList): InstallComponentCom
3939
*/
4040
public function parseUninstallComponent(TokenList $tokenList): UninstallComponentCommand
4141
{
42-
$tokenList->consumeKeywords(Keyword::UNINSTALL, Keyword::COMPONENT);
42+
$tokenList->expectKeywords(Keyword::UNINSTALL, Keyword::COMPONENT);
4343
$components = [];
4444
do {
45-
$components[] = $tokenList->consumeNameOrString();
46-
} while ($tokenList->mayConsumeComma());
45+
$components[] = $tokenList->expectNameOrString();
46+
} while ($tokenList->hasComma());
4747
$tokenList->expectEnd();
4848

4949
return new UninstallComponentCommand($components);

sources/Parser/Dal/CreateFunctionCommandParser.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ class CreateFunctionCommandParser
2626
*/
2727
public function parseCreateFunction(TokenList $tokenList): CreateFunctionSonameCommand
2828
{
29-
$tokenList->consumeKeyword(Keyword::CREATE);
30-
$aggregate = (bool) $tokenList->mayConsumeKeyword(Keyword::AGGREGATE);
31-
$tokenList->consumeKeyword(Keyword::FUNCTION);
32-
$name = new QualifiedName(...$tokenList->consumeQualifiedName());
33-
$tokenList->consumeKeyword(Keyword::RETURNS);
29+
$tokenList->expectKeyword(Keyword::CREATE);
30+
$aggregate = $tokenList->hasKeyword(Keyword::AGGREGATE);
31+
$tokenList->expectKeyword(Keyword::FUNCTION);
32+
$name = new QualifiedName(...$tokenList->expectQualifiedName());
33+
$tokenList->expectKeyword(Keyword::RETURNS);
3434
/** @var UdfReturnDataType $type */
35-
$type = $tokenList->consumeKeywordEnum(UdfReturnDataType::class);
36-
$tokenList->consumeKeyword(Keyword::SONAME);
37-
$libName = $tokenList->consumeNameOrString();
35+
$type = $tokenList->expectKeywordEnum(UdfReturnDataType::class);
36+
$tokenList->expectKeyword(Keyword::SONAME);
37+
$libName = $tokenList->expectNameOrString();
3838
$tokenList->expectEnd();
3939

4040
return new CreateFunctionSonameCommand($name, $libName, $type, $aggregate);

sources/Parser/Dal/FlushCommandParser.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,27 @@ class FlushCommandParser
5151
*/
5252
public function parseFlush(TokenList $tokenList): FlushCommand
5353
{
54-
$tokenList->consumeKeyword(Keyword::FLUSH);
55-
$local = (bool) $tokenList->mayConsumeAnyKeyword(Keyword::NO_WRITE_TO_BINLOG, Keyword::LOCAL);
54+
$tokenList->expectKeyword(Keyword::FLUSH);
55+
$local = $tokenList->hasAnyKeyword(Keyword::NO_WRITE_TO_BINLOG, Keyword::LOCAL);
5656
$options = [];
5757
$channel = null;
5858
$logs = [Keyword::BINARY, Keyword::ENGINE, Keyword::ERROR, Keyword::GENERAL, Keyword::RELAY, Keyword::SLOW];
5959
$other = [Keyword::DES_KEY_FILE, Keyword::HOSTS, Keyword::OPTIMIZER_COSTS, Keyword::PRIVILEGES, Keyword::QUERY, Keyword::STATUS, Keyword::USER_RESOURCES];
6060
do {
61-
$keyword = $tokenList->consumeAnyKeyword(...array_merge($logs, $other));
61+
$keyword = $tokenList->expectAnyKeyword(...array_merge($logs, $other));
6262
if (Arr::contains($logs, $keyword)) {
63-
$tokenList->consumeKeyword(Keyword::LOGS);
64-
if ($keyword === Keyword::RELAY && $tokenList->mayConsumeKeywords(Keyword::FOR, Keyword::CHANNEL)) {
65-
$channel = $tokenList->consumeName();
63+
$tokenList->expectKeyword(Keyword::LOGS);
64+
if ($keyword === Keyword::RELAY && $tokenList->hasKeywords(Keyword::FOR, Keyword::CHANNEL)) {
65+
$channel = $tokenList->expectName();
6666
}
6767
$options[] = FlushOption::get($keyword . ' ' . Keyword::LOGS);
6868
} elseif ($keyword === Keyword::QUERY) {
69-
$tokenList->consumeKeyword(Keyword::CACHE);
69+
$tokenList->expectKeyword(Keyword::CACHE);
7070
$options[] = FlushOption::get($keyword . ' ' . Keyword::CACHE);
7171
} else {
7272
$options[] = FlushOption::get($keyword);
7373
}
74-
} while ($tokenList->mayConsumeComma());
74+
} while ($tokenList->hasComma());
7575
$tokenList->expectEnd();
7676

7777
return new FlushCommand($options, $channel, $local);
@@ -82,22 +82,22 @@ public function parseFlush(TokenList $tokenList): FlushCommand
8282
*/
8383
public function parseFlushTables(TokenList $tokenList): FlushTablesCommand
8484
{
85-
$tokenList->consumeKeywords(Keyword::FLUSH, Keyword::TABLES);
85+
$tokenList->expectKeywords(Keyword::FLUSH, Keyword::TABLES);
8686
$tables = [];
87-
$table = $tokenList->mayConsumeQualifiedName();
87+
$table = $tokenList->getQualifiedName();
8888
if ($table !== null) {
8989
$tables[] = new QualifiedName(...$table);
90-
while ($tokenList->mayConsumeComma()) {
91-
$tables[] = new QualifiedName(...$tokenList->consumeQualifiedName());
90+
while ($tokenList->hasComma()) {
91+
$tables[] = new QualifiedName(...$tokenList->expectQualifiedName());
9292
}
9393
}
94-
$keyword = $tokenList->mayConsumeAnyKeyword(Keyword::WITH, Keyword::FOR);
94+
$keyword = $tokenList->getAnyKeyword(Keyword::WITH, Keyword::FOR);
9595
$withReadLock = $forExport = false;
9696
if ($keyword === Keyword::WITH) {
97-
$tokenList->consumeKeywords(Keyword::READ, Keyword::LOCK);
97+
$tokenList->expectKeywords(Keyword::READ, Keyword::LOCK);
9898
$withReadLock = true;
9999
} else {
100-
$tokenList->consumeKeyword(Keyword::EXPORT);
100+
$tokenList->expectKeyword(Keyword::EXPORT);
101101
$forExport = true;
102102
}
103103
$tokenList->expectEnd();

sources/Parser/Dal/KillCommandParser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class KillCommandParser
2323
*/
2424
public function parseKill(TokenList $tokenList): KillCommand
2525
{
26-
$tokenList->consumeKeyword(Keyword::KILL);
27-
$tokenList->mayConsumeAnyKeyword(Keyword::CONNECTION, Keyword::QUERY);
28-
$id = $tokenList->consumeInt();
26+
$tokenList->expectKeyword(Keyword::KILL);
27+
$tokenList->getAnyKeyword(Keyword::CONNECTION, Keyword::QUERY);
28+
$id = $tokenList->expectInt();
2929
$tokenList->expectEnd();
3030

3131
return new KillCommand($id);

sources/Parser/Dal/PluginCommandsParser.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class PluginCommandsParser
2424
*/
2525
public function parseInstallPlugin(TokenList $tokenList): InstallPluginCommand
2626
{
27-
$tokenList->consumeKeywords(Keyword::INSTALL, Keyword::PLUGIN);
28-
$pluginName = $tokenList->consumeName();
29-
$tokenList->consumeKeyword(Keyword::SONAME);
30-
$libName = $tokenList->consumeString();
27+
$tokenList->expectKeywords(Keyword::INSTALL, Keyword::PLUGIN);
28+
$pluginName = $tokenList->expectName();
29+
$tokenList->expectKeyword(Keyword::SONAME);
30+
$libName = $tokenList->expectString();
3131
$tokenList->expectEnd();
3232

3333
return new InstallPluginCommand($pluginName, $libName);
@@ -38,8 +38,8 @@ public function parseInstallPlugin(TokenList $tokenList): InstallPluginCommand
3838
*/
3939
public function parseUninstallPlugin(TokenList $tokenList): UninstallPluginCommand
4040
{
41-
$tokenList->consumeKeywords(Keyword::UNINSTALL, Keyword::PLUGIN);
42-
$pluginName = $tokenList->consumeName();
41+
$tokenList->expectKeywords(Keyword::UNINSTALL, Keyword::PLUGIN);
42+
$pluginName = $tokenList->expectName();
4343
$tokenList->expectEnd();
4444

4545
return new UninstallPluginCommand($pluginName);

0 commit comments

Comments
 (0)