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: PHPCS Errors for PHP files #143

Merged
merged 10 commits into from
Feb 8, 2023
Merged

Conversation

hbhalodia
Copy link

@hbhalodia hbhalodia commented Feb 8, 2023

  • This PR fixes PHPCS and coding standard issues.
  • For Hooks Naming convention we have ignored the error using comment because hooks can be used by other who have downloaded this plugin, so to add backward compatible we have untouched hooks.
  • Also we assume that this plugin should only use for PHP version 7.1 as plugin uses object type in param and return type.

Issue - #142

1. Blank line after function.
2. Ignore WordPress.NamingConventions.ValidHookName.UseUnderscores because of backward compatibility
1. Spacing and equal line alignement issue.
2. Ignore object param and return type because assuming php greater than 7.1 also requrires php 7.4 as plugin description.
3. Change CamelCase to snake_case variables.
1. Spacing and alignment issue.
2. Naming convention
3. Multiline array comma issue
Copy link
Contributor

@rtBot rtBot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phpcs scanning turned up:

⚠️ 1 warning


hashes-api-scanning skipped

src/Utils/GoogleClient.php Outdated Show resolved Hide resolved
@hbhalodia hbhalodia marked this pull request as ready for review February 8, 2023 10:05
@hbhalodia hbhalodia requested a review from thelovekesh February 8, 2023 10:11
@@ -196,6 +196,6 @@ public function define_services(): void {
*
* @since 1.0.0
*/
do_action( 'rtcamp.google_login_services', $this );
do_action( 'rtcamp.google_login_services', $this ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- Ignore as currently cannot change because of backward compatibility.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about disabling this rule in phpcs config?

<rule ref="WordPress-Core">
	<exclude name="Generic.Arrays.DisallowShortArraySyntax" />
	<exclude name="Generic.Commenting.DocComment.MissingShort" />
	<exclude name="WordPress.PHP.DisallowShortTernary" />
+	<exclude name="WordPress.NamingConventions.ValidHookName.UseUnderscores" />
</rule>

Probably include a todo comment as well?

<!-- @todo: Remove this once we rename the hooks with underscores and deprecate the old ones. -->

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, We can do exclude it from there with a todo for future, works well. 👍

@thelovekesh
Copy link
Member

@hbhalodia PHPUnit tests seem to be failing as there is test scripts specified in the composer scripts[].

Below diff should fix the issue.

diff --git a/.github/workflows/phpunit_on_pull_request.yml b/.github/workflows/phpunit_on_pull_request.yml
index fcca561..e2670d3 100644
--- a/.github/workflows/phpunit_on_pull_request.yml
+++ b/.github/workflows/phpunit_on_pull_request.yml
@@ -48,9 +48,13 @@ jobs:
         if: steps.check_files.outputs.files_exists == 'true'
         run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
 
+      - name: Update composer packages
+        if: steps.check_files.outputs.files_exists == 'true'
+        run: composer update
+
       - name: Run PHPUnit
         if: steps.check_files.outputs.files_exists == 'true'
-        run: composer update && composer tests:unit
+        run: vendor/bin/phpunit tests/php/Unit/ --verbose
 
       - name: Archive code coverage results
         uses: actions/upload-artifact@v2

@hbhalodia
Copy link
Author

Hi @thelovekesh, Seems like some of the tests aer giving errors due to changes in path for the assets.

1) RtCamp\GoogleLogin\Tests\Unit\Modules\AssetsTest::testRegisterLoginStyles
2) RtCamp\GoogleLogin\Tests\Unit\Modules\AssetsTest::testEnqueueLoginStyleWithStyleNotRegistered,

as we have not added build files folder and seems like in enquing this scripts and styles we need to change a code bit there to achieve what we need and then have to check the test.

Other error is use of wp_json_encode, not able to identify that function and adding as undefined because wp_json_encode is a WordPress function and we are calling in PHP environment. Should I update the rule to exclude this phpcs error or should we create some wrapper function to the main testee class and should call wp_json_encode function there? Let me know your thoughts on this.

Thanks.

@thelovekesh
Copy link
Member

@hbhalodia I think we can ignore the tests here for now since changes are going to be merged on a develop(refactor/v2) branch.

Copy link
Member

@thelovekesh thelovekesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @hbhalodia!

Note: Ignore failing tests as they will be fixed and reviewed before getting merged into the main branch.

@thelovekesh thelovekesh merged commit ceb8772 into refactor/v2 Feb 8, 2023
@thelovekesh thelovekesh deleted the fix/GH-142-phpcs-issues branch February 8, 2023 16:13
hbhalodia added a commit that referenced this pull request Feb 14, 2023
* Fix: phpcs errors

1. Blank line after function.
2. Ignore WordPress.NamingConventions.ValidHookName.UseUnderscores because of backward compatibility

* Fix: phpcs error for equal sign alignment

* Fix: phpcs errors

1. Spacing and equal line alignement issue.
2. Ignore object param and return type because assuming php greater than 7.1 also requrires php 7.4 as plugin description.
3. Change CamelCase to snake_case variables.

* Fix: phpcs error for file /tests/bootstrap.php for spacing issue

* Fix: phpcs errors

1. Spacing and alignment issue.
2. Naming convention
3. Multiline array comma issue

* Fix issue added by bot for undefined variable

* Exclude hook name validation rule instead ignoring

* Update unit tests workflow

* Add slah before wp_json_encode function

* Revert json encode change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants