Skip to content

Apply php-cs-fixer #114

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

Merged
merged 2 commits into from
Jan 6, 2017
Merged
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
20 changes: 20 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

// @see https://github.com/FriendsOfPHP/PHP-CS-Fixer

$finder = PhpCsFixer\Finder::create()
->in(array(__DIR__.'/bin', __DIR__.'/src', __DIR__.'/tests', __DIR__.'/tools'))
;

return PhpCsFixer\Config::create()
->setRules(array(
'@PSR1' => true,
'@PSR2' => true,
'@Symfony' => true,
'array_syntax' => array('syntax' => 'long'),
'concat_space' => array('spacing' => true),
'no_trailing_whitespace' => true,
'phpdoc_order' => true,
))
->setFinder($finder)
;
20 changes: 9 additions & 11 deletions src/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
* There is a small difference between *Component and *Keyword classes: usually,
* *Component parsers can be reused in multiple situations and *Keyword parsers
* count on the *Component classes to do their job.
*
* @package SqlParser
*/

namespace SqlParser;

require_once 'common.php';
Expand All @@ -19,21 +18,20 @@
* multiple query types.
*
* @category Components
* @package SqlParser
*
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
abstract class Component
{

/**
* Parses the tokens contained in the given list in the context of the given
* parser.
*
* @param Parser $parser The parser that serves as context.
* @param TokensList $list The list of tokens that are being parsed.
* @param array $options Parameters for parsing.
* @param Parser $parser the parser that serves as context
* @param TokensList $list the list of tokens that are being parsed
* @param array $options parameters for parsing
*
* @throws \Exception Not implemented yet.
* @throws \Exception not implemented yet
*
* @return mixed
*/
Expand All @@ -53,10 +51,10 @@ public static function parse(
* In other words, this function represents the inverse function of
* `static::parse`.
*
* @param mixed $component The component to be built.
* @param array $options Parameters for building.
* @param mixed $component the component to be built
* @param array $options parameters for building
*
* @throws \Exception Not implemented yet.
* @throws \Exception not implemented yet
*
* @return string
*/
Expand Down
135 changes: 66 additions & 69 deletions src/Components/AlterOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

/**
* Parses an alter operation.
*
* @package SqlParser
* @subpackage Components
*/

namespace SqlParser\Components;

use SqlParser\Component;
Expand All @@ -17,86 +15,84 @@
* Parses an alter operation.
*
* @category Components
* @package SqlParser
* @subpackage Components
*
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class AlterOperation extends Component
{

/**
* All database options
* All database options.
*
* @var array
*/
public static $DB_OPTIONS = array(
'CHARACTER SET' => array(1, 'var'),
'CHARSET' => array(1, 'var'),
'DEFAULT CHARACTER SET' => array(1, 'var'),
'DEFAULT CHARSET' => array(1, 'var'),
'UPGRADE' => array(1, 'var'),
'COLLATE' => array(2, 'var'),
'DEFAULT COLLATE' => array(2, 'var'),
'CHARACTER SET' => array(1, 'var'),
'CHARSET' => array(1, 'var'),
'DEFAULT CHARACTER SET' => array(1, 'var'),
'DEFAULT CHARSET' => array(1, 'var'),
'UPGRADE' => array(1, 'var'),
'COLLATE' => array(2, 'var'),
'DEFAULT COLLATE' => array(2, 'var'),
);

/**
* All table options
* All table options.
*
* @var array
*/
public static $TABLE_OPTIONS = array(
'ENGINE' => array(1, 'var='),
'AUTO_INCREMENT' => array(1, 'var='),
'AVG_ROW_LENGTH' => array(1, 'var'),
'MAX_ROWS' => array(1, 'var'),
'ROW_FORMAT' => array(1, 'var'),
'COMMENT' => array(1, 'var'),
'ADD' => 1,
'ALTER' => 1,
'ANALYZE' => 1,
'CHANGE' => 1,
'CHECK' => 1,
'COALESCE' => 1,
'CONVERT' => 1,
'DISABLE' => 1,
'DISCARD' => 1,
'DROP' => 1,
'ENABLE' => 1,
'IMPORT' => 1,
'MODIFY' => 1,
'OPTIMIZE' => 1,
'ORDER' => 1,
'PARTITION' => 1,
'REBUILD' => 1,
'REMOVE' => 1,
'RENAME' => 1,
'REORGANIZE' => 1,
'REPAIR' => 1,
'UPGRADE' => 1,
'ENGINE' => array(1, 'var='),
'AUTO_INCREMENT' => array(1, 'var='),
'AVG_ROW_LENGTH' => array(1, 'var'),
'MAX_ROWS' => array(1, 'var'),
'ROW_FORMAT' => array(1, 'var'),
'COMMENT' => array(1, 'var'),
'ADD' => 1,
'ALTER' => 1,
'ANALYZE' => 1,
'CHANGE' => 1,
'CHECK' => 1,
'COALESCE' => 1,
'CONVERT' => 1,
'DISABLE' => 1,
'DISCARD' => 1,
'DROP' => 1,
'ENABLE' => 1,
'IMPORT' => 1,
'MODIFY' => 1,
'OPTIMIZE' => 1,
'ORDER' => 1,
'PARTITION' => 1,
'REBUILD' => 1,
'REMOVE' => 1,
'RENAME' => 1,
'REORGANIZE' => 1,
'REPAIR' => 1,
'UPGRADE' => 1,

'COLUMN' => 2,
'CONSTRAINT' => 2,
'DEFAULT' => 2,
'TO' => 2,
'BY' => 2,
'FOREIGN' => 2,
'FULLTEXT' => 2,
'KEY' => 2,
'KEYS' => 2,
'PARTITIONING' => 2,
'PRIMARY KEY' => 2,
'SPATIAL' => 2,
'TABLESPACE' => 2,
'INDEX' => 2,
'COLUMN' => 2,
'CONSTRAINT' => 2,
'DEFAULT' => 2,
'TO' => 2,
'BY' => 2,
'FOREIGN' => 2,
'FULLTEXT' => 2,
'KEY' => 2,
'KEYS' => 2,
'PARTITIONING' => 2,
'PRIMARY KEY' => 2,
'SPATIAL' => 2,
'TABLESPACE' => 2,
'INDEX' => 2,
);

/**
* All view options
* All view options.
*
* @var array
*/
public static $VIEW_OPTIONS = array(
'AS' => 1,
'AS' => 1,
);

/**
Expand All @@ -121,20 +117,20 @@ class AlterOperation extends Component
public $unknown = array();

/**
* @param Parser $parser The parser that serves as context.
* @param TokensList $list The list of tokens that are being parsed.
* @param array $options Parameters for parsing.
* @param Parser $parser the parser that serves as context
* @param TokensList $list the list of tokens that are being parsed
* @param array $options parameters for parsing
*
* @return AlterOperation
*/
public static function parse(Parser $parser, TokensList $list, array $options = array())
{
$ret = new AlterOperation();
$ret = new self();

/**
* Counts brackets.
*
* @var int $brackets
* @var int
*/
$brackets = 0;

Expand All @@ -149,15 +145,15 @@ public static function parse(Parser $parser, TokensList $list, array $options =
*
* 2 -------------------------[ , ]-----------------------> 0
*
* @var int $state
* @var int
*/
$state = 0;

for (; $list->idx < $list->count; ++$list->idx) {
/**
* Token parsed at this moment.
*
* @var Token $token
* @var Token
*/
$token = $list->tokens[$list->idx];

Expand Down Expand Up @@ -223,7 +219,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
// We have reached the end of ALTER operation and suddenly found
// a start to new statement, but have not find a delimiter between them

if (! ($token->value == 'SET' && $list->tokens[$list->idx - 1]->value == 'CHARACTER')) {
if (!($token->value == 'SET' && $list->tokens[$list->idx - 1]->value == 'CHARACTER')) {
$parser->error(
__('A new statement was found, but no delimiter between it and the previous one.'),
$token
Expand All @@ -248,8 +244,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

/**
* @param AlterOperation $component The component to be built.
* @param array $options Parameters for building.
* @param AlterOperation $component the component to be built
* @param array $options parameters for building
*
* @return string
*/
Expand All @@ -260,6 +256,7 @@ public static function build($component, array $options = array())
$ret .= $component->field . ' ';
}
$ret .= TokensList::build($component->unknown);

return $ret;
}
}
25 changes: 11 additions & 14 deletions src/Components/Array2d.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

/**
* `VALUES` keyword parser.
*
* @package SqlParser
* @subpackage Components
*/

namespace SqlParser\Components;

use SqlParser\Component;
Expand All @@ -17,17 +15,15 @@
* `VALUES` keyword parser.
*
* @category Keywords
* @package SqlParser
* @subpackage Components
*
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class Array2d extends Component
{

/**
* @param Parser $parser The parser that serves as context.
* @param TokensList $list The list of tokens that are being parsed.
* @param array $options Parameters for parsing.
* @param Parser $parser the parser that serves as context
* @param TokensList $list the list of tokens that are being parsed
* @param array $options parameters for parsing
*
* @return ArrayObj[]
*/
Expand All @@ -38,7 +34,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
/**
* The number of values in each set.
*
* @var int $count
* @var int
*/
$count = -1;

Expand All @@ -52,15 +48,15 @@ public static function parse(Parser $parser, TokensList $list, array $options =
* 1 ------------------------[ , ]------------------------> 0
* 1 -----------------------[ else ]----------------------> (END)
*
* @var int $state
* @var int
*/
$state = 0;

for (; $list->idx < $list->count; ++$list->idx) {
/**
* Token parsed at this moment.
*
* @var Token $token
* @var Token
*/
$token = $list->tokens[$list->idx];

Expand Down Expand Up @@ -117,12 +113,13 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

--$list->idx;

return $ret;
}

/**
* @param ArrayObj[] $component The component to be built.
* @param array $options Parameters for building.
* @param ArrayObj[] $component the component to be built
* @param array $options parameters for building
*
* @return string
*/
Expand Down
Loading