Running drupal-check on simpleSAMLphp Authentication returns 11 errors:

  1. 7 calls to deprecated function drupal_set_message()
  2. 2 calls to deprecated method url() of class Drupal
  3. 2 uses of Class Drupal\Tests\UnitTestCase not found (not actually deprecated code)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

safetypin created an issue. See original summary.

safetypin’s picture

Assigned: Unassigned » safetypin
safetypin’s picture

I've completed an initial pass at replacing deprecated function calls for drupal_set_message() and \Drupal::url(). It looks to me like the "...\UnitTestCase not found" errors are false positives; I think you specify the location of this class when you run unit tests. But I'm not familiar with running Unit Tests on a Drupal module.

Berdir’s picture

Status: Active » Needs review

Changes so far look good, would need to check the unit test stuff, could be bugs in phpstan or maybe those tests really are broken.

TR’s picture

Status: Needs review » Needs work

Rather than using the static \Drupal::messenger() call, the messenger service should be injected into SimplesamlphpDrupalAuth.php. It already has a number of other services injected, so this should be an easy fix.

I triggered testing of the patch in #3, and you can see from the output https://www.drupal.org/project/simplesamlphp_auth/issues/3047241 that you introduced one new coding standard violation, which should be fixed. The test failures seem to be branch failures unrelated to this patch.

safetypin’s picture

Here's a new patch with the the coding standard violation fixed you mentioned (line 161 of SimplesamlphpDrupalAuth.php) - at least I'm pretty sure that's the one that I introduced. I've also added use MessengerTrait to the Class, which allows us to call $this->addMessage() directly. I think this isn't exactly what you had in mind, but it seems like a very elegant solution to me. I believe I'm using this correctly, but I'm not certain.

TR’s picture

Status: Needs work » Needs review

If you set the issue to needs review the test will be triggered automatically.

safetypin’s picture

I looked at some other classes using the MessengerTrait, and applied that formatting to SimplesamlphpDrupalAuth.php.

oknate’s picture

This update removes MessengerTrait and injects messenger service and module handler.

Status: Needs review » Needs work

The last submitted patch, 9: simplesamlphp_auth-drupal-9-fixes-3047241-9.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

oknate’s picture

oknate’s picture

Status: Needs work » Needs review
TR’s picture

Status: Needs review » Needs work
-function simplesamlphp_auth_user_form_includes(&$form) {
+function simplesamlphp_auth_user_form_includes(array &$form) {

This is an API change. It doesn't belong in this issue. I'm not sure why this change was included in this patch, because it has nothing to do with deprecated code.

   /**
-   * Redirect anonymous users from the Drupal login page directly to the external IdP.
+   * Redirect anonymous users from the Drupal login page directly to the
+   * external IdP.

This fixes one coding standards issue - line > 80 characters, but causes a new coding standards issue - function short description should be one line. Again, this is not a deprecated code problem so it should not be addressed here.

My comment in #5 did NOT mean that you should try to fix all the coding standards problems in the existing code - those should be handled in a separate issue. Instead, I simply meant that the patch should not introduce NEW coding standards issues.

What happened to the changes to SimplesamlphpDrupalAuthTest.php? They don't show up in your patch, but DO show up in your interdiff ...

What happened to the url() fixes?

What I was expecting was a patch similar to #8 but using injection instead of MessengerTrait.

oknate’s picture

The patch above was for #3052166: Coding style fixes. I was uploading a patch for this issue and one that issue, and I must have accidentally uploaded the wrong patch. The filename even references that issue.

That being said, that's some good feedback and I'll take that into account on the other issue.

Adding array type hint to simplesamlphp_auth_user_form_includes() isn't really an api change, because it's a helper function, you can't override it, and when you call it, you don't add a type hint, you'd use it like this:
simplesamlphp_auth_user_form_includes($form);
So the type hint wouldn't change the usage.

This is good feedback:

This fixes one coding standards issue - line > 80 characters, but causes a new coding standards issue - function short description should be one line. Again, this is not a deprecated code problem so it should not be addressed here

I'll fix that on issue 3052166.

oknate’s picture

The patch above was still wrong (same as 9, from wrong branch). Here's an update.

oknate’s picture

oknate’s picture

FileSize
880 bytes
Berdir’s picture

Status: Needs review » Needs work
+++ b/src/Service/SimplesamlphpDrupalAuth.php
@@ -127,7 +149,8 @@ class SimplesamlphpDrupalAuth {
       // We let the user know about this and redirect to the user/login page.
-      drupal_set_message(t("We are sorry. While you have successfully authenticated, you are not yet entitled to access this site. Please ask the site administrator to provision access for you."));
+      $this->messenger
+        ->addMessage(t('We are sorry. While you have successfully authenticated, you are not yet entitled to access this site. Please ask the site administrator to provision access for you.'), 'status');
       $this->simplesamlAuth->logout(base_path());

Lets also switch this to $this->() while touching these lines? Might have committed it, but it needs reroll anyway.

oknate’s picture

  • Rerolling
  • Adding MessengerTrait
  • Converting calls to t() to $this->t().

  • Berdir committed 3e8335b on 8.x-3.x authored by oknate
    Issue #3047241 by oknate, safetypin: Remove deprecated code for Drupal 9
    
Berdir’s picture

Status: Needs review » Fixed

Thanks, committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.