Skip to content

Fix some coding standard issues #523

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 1 commit into from
Jan 15, 2024
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
34 changes: 0 additions & 34 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -28,48 +28,14 @@
<exclude-pattern>tests/Tools/templates/*</exclude-pattern>
</rule>

<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
<exclude-pattern>src/Context.php</exclude-pattern>
</rule>

<!-- Rules that should be followed, but are not required -->
<rule ref="SlevomatCodingStandard.Classes.ParentCallSpacing.IncorrectLinesCountAfterControlStructure">
<severity>4</severity>
</rule>
<rule ref="SlevomatCodingStandard.Classes.ParentCallSpacing.IncorrectLinesCountBeforeControlStructure">
<severity>4</severity>
</rule>
<rule ref="SlevomatCodingStandard.Classes.PropertySpacing.IncorrectCountOfBlankLinesAfterProperty">
<severity>4</severity>
</rule>
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.InvalidFormat">
<severity>4</severity>
</rule>
<rule ref="SlevomatCodingStandard.Commenting.RequireOneLineDocComment.MultiLineDocComment">
<severity>4</severity>
</rule>
<rule ref="SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch.NonCapturingCatchRequired">
<severity>4</severity>
</rule>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall.MissingTrailingComma">
<severity>4</severity>
</rule>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration.MissingTrailingComma">
<severity>4</severity>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName">
<severity>4</severity>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint">
<severity>4</severity>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint">
<severity>4</severity>
</rule>
<rule ref="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps">
<severity>4</severity>
</rule>
<rule ref="Squiz.PHP.GlobalKeyword.NotAllowed">
<severity>4</severity>
</rule>
</ruleset>
18 changes: 9 additions & 9 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.18.0@b113f3ed0259fd6e212d87c3df80eec95a6abf19">
<files psalm-version="5.19.0@06b71be009a6bd6d81b9811855d6629b9fe90e1b">
<file src="src/Components/AlterOperation.php">
<PossiblyNullPropertyAssignmentValue>
<code>$options</code>
Expand All @@ -8,7 +8,7 @@
<code><![CDATA[ArrayObj::parse(
$parser,
$list,
['type' => PartitionDefinition::class]
['type' => PartitionDefinition::class],
)]]></code>
</PropertyTypeCoercion>
</file>
Expand All @@ -20,7 +20,7 @@
<code><![CDATA[$options['type']::parse(
$parser,
$list,
empty($options['typeOptions']) ? [] : $options['typeOptions']
empty($options['typeOptions']) ? [] : $options['typeOptions'],
)]]></code>
</MixedMethodCall>
<MixedOperand>
Expand Down Expand Up @@ -374,14 +374,14 @@
[
'parenthesesDelimited' => true,
'breakOnAlias' => true,
]
],
)]]></code>
</PossiblyNullPropertyAssignmentValue>
<PropertyTypeCoercion>
<code><![CDATA[ArrayObj::parse(
$parser,
$list,
['type' => self::class]
['type' => self::class],
)]]></code>
</PropertyTypeCoercion>
<UnusedVariable>
Expand All @@ -401,7 +401,7 @@
[
'parseField' => 'table',
'breakOnAlias' => true,
]
],
)]]></code>
</PossiblyNullPropertyAssignmentValue>
</file>
Expand All @@ -415,15 +415,15 @@
[
'breakOnAlias' => true,
'parseField' => 'table',
]
],
)]]></code>
<code><![CDATA[Expression::parse(
$parser,
$list,
[
'breakOnAlias' => true,
'parseField' => 'table',
]
],
)]]></code>
</PossiblyNullPropertyAssignmentValue>
</file>
Expand Down Expand Up @@ -780,7 +780,7 @@
<code><![CDATA[ArrayObj::parse(
$parser,
$list,
['type' => PartitionDefinition::class]
['type' => PartitionDefinition::class],
)]]></code>
<code>ArrayObj::parse($parser, $list)</code>
</PropertyTypeCoercion>
Expand Down
8 changes: 4 additions & 4 deletions src/Components/AlterOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public function __construct(
OptionsArray|null $options = null,
Expression|string|null $field = null,
array|null $partitions = null,
public array $unknown = []
public array $unknown = [],
) {
$this->partitions = $partitions;
$this->options = $options;
Expand Down Expand Up @@ -370,7 +370,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
[
'breakOnAlias' => true,
'parseField' => 'column',
]
],
);
if ($ret->field === null) {
// No field was read. We go back one token so the next
Expand Down Expand Up @@ -417,7 +417,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
// a start to new statement, but have not found a delimiter between them
$parser->error(
'A new statement was found, but no delimiter between it and the previous one.',
$token
$token,
);
break;
}
Expand Down Expand Up @@ -481,7 +481,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$ret->partitions = ArrayObj::parse(
$parser,
$list,
['type' => PartitionDefinition::class]
['type' => PartitionDefinition::class],
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Array2d.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
sprintf(
Translator::gettext('%1$d values were expected, but found %2$d.'),
$count,
$arrCount
$arrCount,
),
$token
$token,
);
}

Expand Down
6 changes: 2 additions & 4 deletions src/Components/ArrayObj.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$ret[] = $options['type']::parse(
$parser,
$list,
empty($options['typeOptions']) ? [] : $options['typeOptions']
empty($options['typeOptions']) ? [] : $options['typeOptions'],
);
}
}
Expand Down Expand Up @@ -170,9 +170,7 @@ public function build(): string
return '(' . implode(', ', $this->values) . ')';
}

/**
* @param ArrayObj[] $component the component to be built
*/
/** @param ArrayObj[] $component the component to be built */
public static function buildAll(array $component): string
{
return implode(', ', $component);
Expand Down
8 changes: 2 additions & 6 deletions src/Components/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ final class Condition implements Component
*/
public $expr;

/**
* @param string $expr the condition or the operator
*/
/** @param string $expr the condition or the operator */
public function __construct(string|null $expr = null)
{
$this->expr = trim((string) $expr);
Expand Down Expand Up @@ -222,9 +220,7 @@ public function build(): string
return $this->expr;
}

/**
* @param Condition[] $component the component to be built
*/
/** @param Condition[] $component the component to be built */
public static function buildAll(array $component): string
{
return implode(' ', $component);
Expand Down
8 changes: 3 additions & 5 deletions src/Components/CreateDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function __construct(
OptionsArray|null $options = null,
DataType|Key|null $type = null,
bool $isConstraint = false,
Reference|null $references = null
Reference|null $references = null,
) {
$this->name = $name;
$this->options = $options;
Expand Down Expand Up @@ -247,7 +247,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
'A symbol name was expected! '
. 'A reserved keyword can not be used '
. 'as a column name without backquotes.',
$token
$token,
);

return $ret;
Expand Down Expand Up @@ -340,9 +340,7 @@ public function build(): string
return trim($tmp);
}

/**
* @param CreateDefinition[] $component the component to be built
*/
/** @param CreateDefinition[] $component the component to be built */
public static function buildAll(array $component): string
{
return "(\n " . implode(",\n ", $component) . "\n)";
Expand Down
2 changes: 1 addition & 1 deletion src/Components/DataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ final class DataType implements Component
public function __construct(
string|null $name = null,
array $parameters = [],
OptionsArray|null $options = null
OptionsArray|null $options = null,
) {
$this->name = $name;
$this->parameters = $parameters;
Expand Down
9 changes: 4 additions & 5 deletions src/Components/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PhpMyAdmin\SqlParser\Components;

use AllowDynamicProperties;
use PhpMyAdmin\SqlParser\Component;
use PhpMyAdmin\SqlParser\Context;
use PhpMyAdmin\SqlParser\Exceptions\ParserException;
Expand All @@ -21,7 +22,7 @@
* Parses a reference to an expression (column, table or database name, function
* call, mathematical expression, etc.).
*/
#[\AllowDynamicProperties]
#[AllowDynamicProperties]
final class Expression implements Component
{
/**
Expand Down Expand Up @@ -114,7 +115,7 @@ public function __construct(
string|null $database = null,
string|null $table = null,
string|null $column = null,
string|null $alias = null
string|null $alias = null,
) {
if (($column === null) && ($alias === null)) {
$this->expr = $database; // case 1
Expand Down Expand Up @@ -476,9 +477,7 @@ public function build(): string
return $ret;
}

/**
* @param Expression[] $component the component to be built
*/
/** @param Expression[] $component the component to be built */
public static function buildAll(array $component): string
{
return implode(', ', $component);
Expand Down
4 changes: 1 addition & 3 deletions src/Components/ExpressionArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ public function build(): string
throw new RuntimeException(Translator::gettext('Not implemented yet.'));
}

/**
* @param Expression[] $component the component to be built
*/
/** @param Expression[] $component the component to be built */
public static function buildAll(array $component): string
{
return implode(', ', $component);
Expand Down
8 changes: 2 additions & 6 deletions src/Components/GroupKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ final class GroupKeyword implements Component
*/
public $expr;

/**
* @param Expression $expr the expression that we are sorting by
*/
/** @param Expression $expr the expression that we are sorting by */
public function __construct(Expression|null $expr = null)
{
$this->expr = $expr;
Expand Down Expand Up @@ -115,9 +113,7 @@ public function build(): string
return trim((string) $this->expr);
}

/**
* @param GroupKeyword[] $component the component to be built
*/
/** @param GroupKeyword[] $component the component to be built */
public static function buildAll(array $component): string
{
return implode(', ', $component);
Expand Down
6 changes: 2 additions & 4 deletions src/Components/IndexHint.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(
string|null $type = null,
string|null $indexOrKey = null,
string|null $for = null,
array $indexes = []
array $indexes = [],
) {
$this->type = $type;
$this->indexOrKey = $indexOrKey;
Expand Down Expand Up @@ -186,9 +186,7 @@ public function build(): string
return $ret . Expression::buildAll($this->indexes);
}

/**
* @param IndexHint[] $component the component to be built
*/
/** @param IndexHint[] $component the component to be built */
public static function buildAll(array $component): string
{
return implode(' ', $component);
Expand Down
4 changes: 2 additions & 2 deletions src/Components/IntoKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function __construct(
array|null $columns = null,
array|null $values = null,
OptionsArray|null $fieldsOptions = null,
bool|null $fieldsKeyword = null
bool|null $fieldsKeyword = null,
) {
$this->type = $type;
$this->dest = $dest;
Expand Down Expand Up @@ -195,7 +195,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
[
'parseField' => 'table',
'breakOnAlias' => true,
]
],
);
} else {
$ret->values = ExpressionArray::parse($parser, $list);
Expand Down
6 changes: 2 additions & 4 deletions src/Components/JoinKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct(
string|null $type = null,
Expression|null $expr = null,
array|null $on = null,
ArrayObj|null $using = null
ArrayObj|null $using = null,
) {
$this->type = $type;
$this->expr = $expr;
Expand Down Expand Up @@ -206,9 +206,7 @@ public function build(): string
throw new RuntimeException(Translator::gettext('Not implemented yet.'));
}

/**
* @param JoinKeyword[] $component the component to be built
*/
/** @param JoinKeyword[] $component the component to be built */
public static function buildAll(array $component): string
{
$ret = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function __construct(
string|null $name = null,
array $columns = [],
string|null $type = null,
OptionsArray|null $options = null
OptionsArray|null $options = null,
) {
$this->name = $name;
$this->columns = $columns;
Expand Down
Loading