Skip to content

Commit 86c5bae

Browse files
committed
Apply phpmyadmin/coding-standard
Signed-off-by: Maurício Meneghini Fauth <[email protected]>
1 parent 2842754 commit 86c5bae

132 files changed

Lines changed: 2958 additions & 2094 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ coverage.xml
88
.php_cs.cache
99
*sw[op]
1010
phpunit.xml
11+
phpcs.xml

.php_cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"require-dev": {
2323
"sami/sami": "^4.0",
2424
"phpunit/php-code-coverage": "*",
25-
"phpunit/phpunit": "^7.4"
25+
"phpunit/phpunit": "^7.4",
26+
"phpmyadmin/coding-standard": "^1.0"
2627
},
2728
"conflict": {
2829
"phpmyadmin/motranslator": "<3.0"

phpcs.xml.dist

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0"?>
2+
<ruleset
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
name="phpMyAdmin"
5+
xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd"
6+
>
7+
<rule ref="./vendor/phpmyadmin/coding-standard/PhpMyAdmin/ruleset.xml">
8+
<exclude name="PEAR.Commenting.FileComment"/>
9+
<exclude name="PEAR.Commenting.ClassComment"/>
10+
<exclude name="PEAR.Commenting.FunctionComment"/>
11+
</rule>
12+
13+
<rule ref="Squiz.Arrays.ArrayDeclaration.IndexNoNewline">
14+
<exclude-pattern>*/src/Contexts/*</exclude-pattern>
15+
</rule>
16+
17+
<rule ref="Generic.Files.LineLength.TooLong">
18+
<severity>4</severity>
19+
</rule>
20+
<rule ref="Generic.Metrics.NestingLevel.TooHigh">
21+
<severity>4</severity>
22+
</rule>
23+
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
24+
<severity>4</severity>
25+
</rule>
26+
<rule ref="Squiz.NamingConventions.ValidVariableName">
27+
<severity>4</severity>
28+
</rule>
29+
30+
<arg value="sp"/>
31+
<arg name="colors"/>
32+
<arg name="extensions" value="php"/>
33+
34+
<exclude-pattern>*/tools/sami-config.php</exclude-pattern>
35+
36+
<file>src</file>
37+
<file>tests</file>
38+
<file>tools</file>
39+
</ruleset>

src/Component.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ abstract class Component
3636
public static function parse(
3737
Parser $parser,
3838
TokensList $list,
39-
array $options = array()
39+
array $options = []
4040
) {
4141
// This method should be abstract, but it can't be both static and
4242
// abstract.
@@ -56,7 +56,7 @@ public static function parse(
5656
*
5757
* @return string
5858
*/
59-
public static function build($component, array $options = array())
59+
public static function build($component, array $options = [])
6060
{
6161
// This method should be abstract, but it can't be both static and
6262
// abstract.

src/Components/AlterOperation.php

Lines changed: 74 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,67 @@ class AlterOperation extends Component
2525
*
2626
* @var array
2727
*/
28-
public static $DB_OPTIONS = array(
29-
'CHARACTER SET' => array(1, 'var'),
30-
'CHARSET' => array(1, 'var'),
31-
'DEFAULT CHARACTER SET' => array(1, 'var'),
32-
'DEFAULT CHARSET' => array(1, 'var'),
33-
'UPGRADE' => array(1, 'var'),
34-
'COLLATE' => array(2, 'var'),
35-
'DEFAULT COLLATE' => array(2, 'var'),
36-
);
28+
public static $DB_OPTIONS = [
29+
'CHARACTER SET' => [
30+
1,
31+
'var',
32+
],
33+
'CHARSET' => [
34+
1,
35+
'var',
36+
],
37+
'DEFAULT CHARACTER SET' => [
38+
1,
39+
'var',
40+
],
41+
'DEFAULT CHARSET' => [
42+
1,
43+
'var',
44+
],
45+
'UPGRADE' => [
46+
1,
47+
'var',
48+
],
49+
'COLLATE' => [
50+
2,
51+
'var',
52+
],
53+
'DEFAULT COLLATE' => [
54+
2,
55+
'var',
56+
],
57+
];
3758

3859
/**
3960
* All table options.
4061
*
4162
* @var array
4263
*/
43-
public static $TABLE_OPTIONS = array(
44-
'ENGINE' => array(1, 'var='),
45-
'AUTO_INCREMENT' => array(1, 'var='),
46-
'AVG_ROW_LENGTH' => array(1, 'var'),
47-
'MAX_ROWS' => array(1, 'var'),
48-
'ROW_FORMAT' => array(1, 'var'),
49-
'COMMENT' => array(1, 'var'),
64+
public static $TABLE_OPTIONS = [
65+
'ENGINE' => [
66+
1,
67+
'var=',
68+
],
69+
'AUTO_INCREMENT' => [
70+
1,
71+
'var=',
72+
],
73+
'AVG_ROW_LENGTH' => [
74+
1,
75+
'var',
76+
],
77+
'MAX_ROWS' => [
78+
1,
79+
'var',
80+
],
81+
'ROW_FORMAT' => [
82+
1,
83+
'var',
84+
],
85+
'COMMENT' => [
86+
1,
87+
'var',
88+
],
5089
'ADD' => 1,
5190
'ALTER' => 1,
5291
'ANALYZE' => 1,
@@ -84,16 +123,16 @@ class AlterOperation extends Component
84123
'SPATIAL' => 2,
85124
'TABLESPACE' => 2,
86125
'INDEX' => 2,
87-
);
126+
];
88127

89128
/**
90129
* All view options.
91130
*
92131
* @var array
93132
*/
94-
public static $VIEW_OPTIONS = array(
133+
public static $VIEW_OPTIONS = [
95134
'AS' => 1,
96-
);
135+
];
97136

98137
/**
99138
* Options of this operation.
@@ -114,7 +153,7 @@ class AlterOperation extends Component
114153
*
115154
* @var Token[]|string
116155
*/
117-
public $unknown = array();
156+
public $unknown = [];
118157

119158
/**
120159
* Constructor.
@@ -126,7 +165,7 @@ class AlterOperation extends Component
126165
public function __construct(
127166
$options = null,
128167
$field = null,
129-
$unknown = array()
168+
$unknown = []
130169
) {
131170
$this->options = $options;
132171
$this->field = $field;
@@ -140,7 +179,7 @@ public function __construct(
140179
*
141180
* @return AlterOperation
142181
*/
143-
public static function parse(Parser $parser, TokensList $list, array $options = array())
182+
public static function parse(Parser $parser, TokensList $list, array $options = [])
144183
{
145184
$ret = new self();
146185

@@ -212,10 +251,10 @@ public static function parse(Parser $parser, TokensList $list, array $options =
212251
$ret->field = Expression::parse(
213252
$parser,
214253
$list,
215-
array(
254+
[
216255
'breakOnAlias' => true,
217256
'parseField' => 'column',
218-
)
257+
]
219258
);
220259
if ($ret->field === null) {
221260
// No field was read. We go back one token so the next
@@ -232,11 +271,11 @@ public static function parse(Parser $parser, TokensList $list, array $options =
232271
} elseif (($token->value === ',') && ($brackets === 0)) {
233272
break;
234273
}
235-
} elseif (!empty(Parser::$STATEMENT_PARSERS[$token->value])) {
274+
} elseif (! empty(Parser::$STATEMENT_PARSERS[$token->value])) {
236275
// We have reached the end of ALTER operation and suddenly found
237276
// a start to new statement, but have not find a delimiter between them
238277

239-
if (!($token->value === 'SET' && $list->tokens[$list->idx - 1]->value === 'CHARACTER')) {
278+
if (! ($token->value === 'SET' && $list->tokens[$list->idx - 1]->value === 'CHARACTER')) {
240279
$parser->error(
241280
'A new statement was found, but no delimiter between it and the previous one.',
242281
$token
@@ -245,7 +284,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
245284
}
246285
} elseif (array_key_exists($token->value, self::$DB_OPTIONS)
247286
|| (array_key_exists($token->value, self::$TABLE_OPTIONS)
248-
&& !self::checkIfColumnDefinitionKeyword($token->value))
287+
&& ! self::checkIfColumnDefinitionKeyword($token->value))
249288
) {
250289
// This alter operation has finished, which means a comma was missing before start of new alter operation
251290
$parser->error(
@@ -276,7 +315,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
276315
*
277316
* @return string
278317
*/
279-
public static function build($component, array $options = array())
318+
public static function build($component, array $options = [])
280319
{
281320
$ret = $component->options . ' ';
282321
if ((isset($component->field)) && ($component->field !== '')) {
@@ -293,8 +332,13 @@ public static function build($component, array $options = array())
293332
*
294333
* @param string $tokenValue Value of current token
295334
*/
296-
private static function checkIfColumnDefinitionKeyword($tokenValue) {
297-
$common_options = array('AUTO_INCREMENT', 'COMMENT', 'DEFAULT');
335+
private static function checkIfColumnDefinitionKeyword($tokenValue)
336+
{
337+
$common_options = [
338+
'AUTO_INCREMENT',
339+
'COMMENT',
340+
'DEFAULT',
341+
];
298342
// Since AUTO_INCREMENT and COMMENT can be used for
299343
// both table as well as a specific column in the table
300344
return in_array($tokenValue, $common_options);

src/Components/Array2d.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class Array2d extends Component
2828
*
2929
* @return ArrayObj[]
3030
*/
31-
public static function parse(Parser $parser, TokensList $list, array $options = array())
31+
public static function parse(Parser $parser, TokensList $list, array $options = [])
3232
{
33-
$ret = array();
33+
$ret = [];
3434

3535
/**
3636
* The number of values in each set.
@@ -124,7 +124,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
124124
*
125125
* @return string
126126
*/
127-
public static function build($component, array $options = array())
127+
public static function build($component, array $options = [])
128128
{
129129
return ArrayObj::build($component);
130130
}

src/Components/ArrayObj.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ class ArrayObj extends Component
2525
*
2626
* @var array
2727
*/
28-
public $raw = array();
28+
public $raw = [];
2929

3030
/**
3131
* The array that contains the processed value of each token.
3232
*
3333
* @var array
3434
*/
35-
public $values = array();
35+
public $values = [];
3636

3737
/**
3838
* Constructor.
3939
*
4040
* @param array $raw the unprocessed values
4141
* @param array $values the processed values
4242
*/
43-
public function __construct(array $raw = array(), array $values = array())
43+
public function __construct(array $raw = [], array $values = [])
4444
{
4545
$this->raw = $raw;
4646
$this->values = $values;
@@ -53,9 +53,9 @@ public function __construct(array $raw = array(), array $values = array())
5353
*
5454
* @return ArrayObj|Component[]
5555
*/
56-
public static function parse(Parser $parser, TokensList $list, array $options = array())
56+
public static function parse(Parser $parser, TokensList $list, array $options = [])
5757
{
58-
$ret = empty($options['type']) ? new self() : array();
58+
$ret = empty($options['type']) ? new self() : [];
5959

6060
/**
6161
* The last raw expression.
@@ -144,7 +144,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
144144
$ret[] = $options['type']::parse(
145145
$parser,
146146
$list,
147-
empty($options['typeOptions']) ? array() : $options['typeOptions']
147+
empty($options['typeOptions']) ? [] : $options['typeOptions']
148148
);
149149
}
150150
}
@@ -176,11 +176,11 @@ public static function parse(Parser $parser, TokensList $list, array $options =
176176
*
177177
* @return string
178178
*/
179-
public static function build($component, array $options = array())
179+
public static function build($component, array $options = [])
180180
{
181181
if (is_array($component)) {
182182
return implode(', ', $component);
183-
} elseif (!empty($component->raw)) {
183+
} elseif (! empty($component->raw)) {
184184
return '(' . implode(', ', $component->raw) . ')';
185185
}
186186

0 commit comments

Comments
 (0)