Skip to content

Commit e2a84a8

Browse files
Merge pull request #364 from mauriciofauth/php80-polyfill
Add PHP 8.0 polyfill
2 parents 6043d96 + 77523c6 commit e2a84a8

File tree

9 files changed

+22
-14
lines changed

9 files changed

+22
-14
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
},
1818
"require": {
1919
"php": "^7.1 || ^8.0",
20-
"symfony/polyfill-mbstring": "^1.3"
20+
"symfony/polyfill-mbstring": "^1.3",
21+
"symfony/polyfill-php80": "^1.16"
2122
},
2223
"require-dev": {
2324
"phpmyadmin/coding-standard": "^3.0",

src/Component.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
namespace PhpMyAdmin\SqlParser;
1414

1515
use Exception;
16+
use Stringable;
1617

1718
/**
1819
* A component (of a statement) is a part of a statement that is common to
1920
* multiple query types.
2021
*/
21-
abstract class Component
22+
abstract class Component implements Stringable
2223
{
2324
/**
2425
* Parses the tokens contained in the given list in the context of the given

src/Context.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
use function is_array;
2020
use function is_numeric;
2121
use function str_replace;
22+
use function str_starts_with;
2223
use function strlen;
23-
use function strncmp;
2424
use function strtoupper;
2525
use function substr;
2626

@@ -553,11 +553,11 @@ public static function loadClosest($context = '')
553553
}
554554

555555
/* Fallback to loading at least matching engine */
556-
if (strncmp($context, 'MariaDb', 7) === 0) {
556+
if (str_starts_with($context, 'MariaDb')) {
557557
return static::loadClosest('MariaDb100300');
558558
}
559559

560-
if (strncmp($context, 'MySql', 5) === 0) {
560+
if (str_starts_with($context, 'MySql')) {
561561
return static::loadClosest('MySql50700');
562562
}
563563

src/Lexer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use function in_array;
1919
use function mb_strlen;
2020
use function sprintf;
21+
use function str_ends_with;
2122
use function strlen;
2223
use function substr;
2324

@@ -1014,7 +1015,7 @@ public function parseUnknown()
10141015
$token .= $this->str[$this->last];
10151016

10161017
// Test if end of token equals the current delimiter. If so, remove it from the token.
1017-
if (substr($token, -$this->delimiterLen) === $this->delimiter) {
1018+
if (str_ends_with($token, $this->delimiter)) {
10181019
$token = substr($token, 0, -$this->delimiterLen);
10191020
$this->last -= $this->delimiterLen - 1;
10201021
break;

src/Statement.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use PhpMyAdmin\SqlParser\Components\FunctionCall;
1414
use PhpMyAdmin\SqlParser\Components\OptionsArray;
15+
use Stringable;
1516

1617
use function array_flip;
1718
use function array_keys;
@@ -23,7 +24,7 @@
2324
/**
2425
* Abstract statement definition.
2526
*/
26-
abstract class Statement
27+
abstract class Statement implements Stringable
2728
{
2829
/**
2930
* Options for this statement.

src/Tools/TestGenerator.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
use function print_r;
2424
use function scandir;
2525
use function sprintf;
26+
use function str_contains;
27+
use function str_ends_with;
2628
use function strpos;
2729
use function substr;
2830

@@ -219,7 +221,7 @@ public static function buildAll($input, $output, $debug = null)
219221

220222
// Generating tests recursively.
221223
static::buildAll($inputFile, $outputFile, $debugFile);
222-
} elseif (substr($inputFile, -3) === '.in') {
224+
} elseif (str_ends_with($inputFile, '.in')) {
223225
// Generating file names by replacing `.in` with `.out` and
224226
// `.debug`.
225227
$outputFile = substr($outputFile, 0, -3) . '.out';
@@ -231,11 +233,11 @@ public static function buildAll($input, $output, $debug = null)
231233
if (! file_exists($outputFile)) {
232234
sprintf("Building test for %s...\n", $inputFile);
233235
static::build(
234-
strpos($inputFile, 'lex') !== false ? 'lexer' : 'parser',
236+
str_contains($inputFile, 'lex') ? 'lexer' : 'parser',
235237
$inputFile,
236238
$outputFile,
237239
$debugFile,
238-
strpos($inputFile, 'ansi') !== false
240+
str_contains($inputFile, 'ansi')
239241
);
240242
} else {
241243
sprintf("Test for %s already built!\n", $inputFile);

src/UtfString.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
use ArrayAccess;
1818
use Exception;
19+
use Stringable;
1920

2021
use function mb_check_encoding;
2122
use function mb_strlen;
@@ -28,7 +29,7 @@
2829
*
2930
* @implements ArrayAccess<int, string>
3031
*/
31-
class UtfString implements ArrayAccess
32+
class UtfString implements ArrayAccess, Stringable
3233
{
3334
/**
3435
* The raw, multi-byte string.

src/Utils/Formatter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
use function htmlspecialchars;
2020
use function in_array;
2121
use function mb_strlen;
22+
use function str_contains;
2223
use function str_repeat;
2324
use function str_replace;
24-
use function strpos;
2525
use function strtoupper;
2626

2727
use const ENT_NOQUOTES;
@@ -399,7 +399,7 @@ public function formatList($list)
399399
if ($curr->type === Token::TYPE_WHITESPACE) {
400400
// Keep linebreaks before and after comments
401401
if (
402-
strpos($curr->token, "\n") !== false && (
402+
str_contains($curr->token, "\n") && (
403403
($prev !== null && $prev->type === Token::TYPE_COMMENT) ||
404404
($next !== null && $next->type === Token::TYPE_COMMENT)
405405
)

tests/TestCase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Zumba\JsonSerializer\JsonSerializer;
1818

1919
use function file_get_contents;
20+
use function str_contains;
2021
use function strpos;
2122
use function substr;
2223

@@ -107,7 +108,7 @@ public function runParserTest($name): void
107108
*/
108109
$data = $this->getData($name);
109110

110-
if (strpos($name, '/ansi/') !== false) {
111+
if (str_contains($name, '/ansi/')) {
111112
// set mode if appropriate
112113
Context::setMode('ANSI_QUOTES');
113114
}

0 commit comments

Comments
 (0)