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

Add variable analysis phpcs sniffs #8556

Merged
merged 12 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"spatie/phpunit-watcher": "1.23",
"woocommerce/qit-cli": "0.4.0",
"slevomat/coding-standard": "8.15.0",
"dg/bypass-finals": "1.5.1"
"dg/bypass-finals": "1.5.1",
"sirbrillig/phpcs-variable-analysis": "^2.11"
},
"scripts": {
"test": [
Expand Down
60 changes: 59 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<!-- FIXME: Remove these ignores once https://github.com/Automattic/woocommerce-payments/issues/8436 is closed. -->
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.Found" />
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed" />
<exclude name="VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable" />

<!-- FIXME: Remove these ignores once https://github.com/Automattic/woocommerce-payments/issues/8437 is clsoed. -->
<exclude name="WooCommerce.Commenting.CommentHooks.MissingHookComment" />
Expand All @@ -62,6 +63,17 @@
<exclude name="Universal.NamingConventions.NoReservedKeywordParameterNames.functionFound" />
</rule>

<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis">
<properties>
<property name="ignoreUnusedRegexp" value="/^unused_/"/>
reykjalin marked this conversation as resolved.
Show resolved Hide resolved
</properties>
</rule>

<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable">
<exclude-pattern>templates/emails/</exclude-pattern>
<exclude-pattern>includes/in-person-payments/templates/</exclude-pattern>
</rule>

<!-- Disallow long array syntax -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/helpers/class-wc-mock-wc-data-store.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function update( &$object ) {
if ( 'user' === $this->meta_type ) {
wp_update_user(
[
'ID' => $customer_id,
'ID' => $customer_id, // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
shendy-a8c marked this conversation as resolved.
Show resolved Hide resolved
reykjalin marked this conversation as resolved.
Show resolved Hide resolved
'user_email' => $object->get_content(),
]
);
Expand Down
1 change: 1 addition & 0 deletions tests/unit/multi-currency/test-class-multi-currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public function test_get_enabled_currencies_returns_correctly() {
'BIF' => 1974,
];

$expected = [];
foreach ( $mock_currencies as $code => $rate ) {
$currency = new WCPay\MultiCurrency\Currency( $code, $rate );
$currency->set_charm( 0.00 );
Expand Down
1 change: 1 addition & 0 deletions tests/unit/src/Internal/Service/Level3ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ protected function mock_level_3_order(
$product_id = 30,
$variable = false
) {
$mock_items = [];
$mock_items[] = $this->create_mock_item( 'Beanie with Logo', $quantity, 18, 2.7, $product_id, $variable );

if ( $with_fee ) {
Expand Down
Loading