Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHP 8.1 deprecation notice #371

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,9 @@ protected function processPackage($errorPos) {
$newContent = preg_replace('/[^A-Za-z_]/', '', $newContent);
$nameBits = explode('_', $newContent);
$firstBit = array_shift($nameBits);
$newName = strtoupper($firstBit{0}) . substr($firstBit, 1) . '_';
$newName = strtoupper($firstBit[0]) . substr($firstBit, 1) . '_';
foreach ($nameBits as $bit) {
$newName .= strtoupper($bit{0}) . substr($bit, 1) . '_';
$newName .= strtoupper($bit[0]) . substr($bit, 1) . '_';
}

$error = 'Package name "%s" is not valid; consider "%s" instead';
Expand All @@ -504,9 +504,9 @@ protected function processSubpackage($errorPos) {
$newContent = str_replace(' ', '_', $content);
$nameBits = explode('_', $newContent);
$firstBit = array_shift($nameBits);
$newName = strtoupper($firstBit{0}) . substr($firstBit, 1) . '_';
$newName = strtoupper($firstBit[0]) . substr($firstBit, 1) . '_';
foreach ($nameBits as $bit) {
$newName .= strtoupper($bit{0}) . substr($bit, 1) . '_';
$newName .= strtoupper($bit[0]) . substr($bit, 1) . '_';
}

$error = 'Subpackage name "%s" is not valid; consider "%s" instead';
Expand Down
10 changes: 6 additions & 4 deletions src/PHPSQLParser/PHPSQLCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
*/

namespace PHPSQLParser;
use PHPSQLParser\builders\Builder;
use PHPSQLParser\exceptions\UnsupportedFeatureException;
use PHPSQLParser\builders\SelectStatementBuilder;
use PHPSQLParser\builders\DeleteStatementBuilder;
Expand All @@ -64,7 +65,8 @@
*
*/
class PHPSQLCreator {

public $created;

public function __construct($parsed = false) {
if ($parsed) {
$this->create($parsed);
Expand All @@ -76,9 +78,9 @@ public function create($parsed) {
switch ($k) {

case 'UNION':
$builder = new UnionStatementBuilder();
$this->created = $builder->build($parsed);
break;
$builder = new UnionStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'UNION ALL':
$builder = new UnionAllStatementBuilder();
$this->created = $builder->build($parsed);
Expand Down
4 changes: 3 additions & 1 deletion src/PHPSQLParser/processors/SelectExpressionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public function process($expression) {
// but also a comment!
if ($capture) {
if (!$this->isWhitespaceToken($upper) && !$this->isCommentToken($upper)) {
$alias['name'] .= $token;
if ($alias) {
$alias['name'] .= $token;
}
array_pop($stripped);
}
$alias['base_expr'] .= $token;
Expand Down
2 changes: 1 addition & 1 deletion src/PHPSQLParser/utils/PHPSQLParserConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class PHPSQLParserConstants {
'BITLENGTH', 'CAST', 'CEILING', 'CHAR', 'CHAR_LENGTH', 'CHARACTER_LENGTH', 'CHARSET',
'COALESCE', 'COERCIBILITY', 'COLLATION', 'COMPRESS', 'CONCAT', 'CONCAT_WS',
'CONNECTION_ID', 'CONV', 'CONVERT', 'CONVERT_TZ', 'COS', 'COT', 'COUNT', 'CRC32',
'CURDATE', 'CURRENT_USER', 'CURRVAL', 'CURTIME', 'DATABASE', 'SCHEMA', 'DATE_ADD', 'DATE_DIFF',
'CURDATE', 'CURRENT_TIMESTAMP', 'CURRENT_USER', 'CURRVAL', 'CURTIME', 'DATABASE', 'SCHEMA', 'DATE_ADD', 'DATE_DIFF',
'DATE_FORMAT', 'DATE_SUB', 'DAY', 'DAYNAME', 'DAYOFMONTH', 'DAYOFWEEK', 'DAYOFYEAR',
'DECODE', 'DEFAULT', 'DEGREES', 'DES_DECRYPT', 'DES_ENCRYPT', 'ELT', 'ENCODE',
'ENCRYPT', 'EXP', 'EXPORT_SET', 'EXTRACT', 'FIELD', 'FIND_IN_SET', 'FLOOR', 'FORMAT',
Expand Down
30 changes: 30 additions & 0 deletions tests/cases/creator/issue368Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* issue368.php
*
* Test case for PHPSQLCreator.
*/

namespace PHPSQLParser\Test\Creator;

use PHPSQLParser\PHPSQLParser;
use PHPSQLParser\PHPSQLCreator;

class Issue368Test extends \PHPUnit\Framework\TestCase
{
/*
* https://github.com/greenlion/PHP-SQL-Parser/issues/368
* CURRENT_TIMESTAMP is detected as a reserved word an generate errors when used in JOIN clause
*/
public function testIssue368()
{
$sql = "SELECT foo FROM barTable LEFT JOIN bazTable ON barTable.a = bazTable.a AND bazTable.d <= CURRENT_TIMESTAMP"; // KO

$parser = new PHPSQLParser();
$creator = new PHPSQLCreator();

$parser->parse($sql);

$this->assertEquals($sql, $creator->create($parser->parsed));
}
}
3 changes: 1 addition & 2 deletions tests/cases/parser/issue320Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@
*/
namespace PHPSQLParser\Test\Parser;
use PHPSQLParser\PHPSQLParser;
use PHPSQLParser\PHPSQLCreator;

class issue320Test extends \PHPUnit_Framework_TestCase
class issue320Test extends \PHPUnit\Framework\TestCase
{
public function test_no_warning_is_issued_when_help_table_is_used()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/parser/issue335Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

use PHPSQLParser\PHPSQLParser;

class issue335Test extends \PHPUnit_Framework_TestCase
class issue335Test extends \PHPUnit\Framework\TestCase
{
/**
* @test
Expand Down